Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the paths to module maps generated by the Swift build rules. #560

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ load(
"SWIFT_FEATURE_VFSOVERLAY",
)
load(":features.bzl", "are_all_features_enabled", "is_feature_enabled")
load(":module_maps.bzl", "write_module_map")
load(":providers.bzl", "SwiftInfo", "create_swift_info")
load(":toolchain_config.bzl", "swift_toolchain_config")
load(
Expand Down Expand Up @@ -1774,11 +1775,11 @@ def _declare_compile_outputs(
actions = actions,
target_name = target_name,
)
_write_objc_header_module_map(
write_module_map(
actions = actions,
module_map_file = generated_module_map,
module_name = module_name,
objc_header = generated_header,
output = generated_module_map,
public_headers = [generated_header],
)
else:
generated_module_map = None
Expand Down Expand Up @@ -2243,29 +2244,6 @@ def swift_library_output_map(name, alwayslink):
"archive": "lib{}.{}".format(name, extension),
}

def _write_objc_header_module_map(
actions,
module_name,
objc_header,
output):
"""Writes a module map for a generated Swift header to a file.

Args:
actions: The context's actions object.
module_name: The name of the Swift module.
objc_header: The `File` representing the generated header.
output: The `File` to which the module map should be written.
"""
actions.write(
content = ('module "{module_name}" {{\n' +
' header "../{header_name}"\n' +
"}}\n").format(
header_name = objc_header.basename,
module_name = module_name,
),
output = output,
)

def _index_store_path_overridden(copts):
"""Checks if index_while_building must be disabled.

Expand Down
10 changes: 6 additions & 4 deletions swift/internal/derived_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ def _intermediate_object_file(actions, target_name, src):
)

def _module_map(actions, target_name):
"""Declares the module map for the generated header of a target.
"""Declares the module map for a target.
These module maps are used when generating a Swift-compatible module map for
a C/Objective-C target, and also when generating the module map for the
generated header of a Swift target.
Args:
actions: The context's actions object.
Expand All @@ -117,9 +121,7 @@ def _module_map(actions, target_name):
Returns:
The declared `File`.
"""
return actions.declare_file(
"{}.modulemaps/module.modulemap".format(target_name),
)
return actions.declare_file("{}.swift.modulemap".format(target_name))

def _modulewrap_object(actions, target_name):
"""Declares the object file used to wrap Swift modules for ELF binaries.
Expand Down
7 changes: 7 additions & 0 deletions swift/internal/module_maps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ def _header_path(header_file, module_map_file, workspace_relative):
if workspace_relative:
return header_file.path

# Minor optimization for the generated Objective-C header of a Swift module,
# which will be in the same directory as the module map file -- we can just
# use the header's basename instead of the elaborate relative path
# computation below.
if header_file.dirname == module_map_file.dirname:
return header_file.basename

# Otherwise, since the module map is generated, we need to get the full path
# to it rather than just its short path (that is, the path starting with
# bazel-out/). Then, we can simply walk up the same number of parent
Expand Down
4 changes: 2 additions & 2 deletions test/private_deps_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def private_deps_test_suite(name = "private_deps"):
private_deps_provider_test(
name = "{}_client_cc_deps_modulemaps".format(name),
expected_files = [
"/test/fixtures/private_deps/public_cc.modulemaps/module.modulemap",
"-/test/fixtures/private_deps/private_cc.modulemaps/module.modulemap",
"/test/fixtures/private_deps/public_cc.swift.modulemap",
"-/test/fixtures/private_deps/private_cc.swift.modulemap",
],
field = "transitive_modules.clang!.module_map",
provider = "SwiftInfo",
Expand Down