Skip to content

Commit

Permalink
Remove top level functions for now
Browse files Browse the repository at this point in the history
  • Loading branch information
keith committed May 4, 2021
1 parent 26f81ca commit b1cc212
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
34 changes: 19 additions & 15 deletions swift/internal/module_maps.bzl
Expand Up @@ -14,6 +14,19 @@

"""Logic for generating Clang module map files."""

# TODO: Once bazel supports nested functions unify it with upstream
def _add_headers(*, headers, kind, content, relative_to_dir, back_to_root_path):
# Each header is added to the `Args` object as a tuple along with
# `relative_to_dir` and `back_to_root_path`. This gives the mapping
# function the information it needs to relativize the header paths even
# when they're expanded from a tree artifact (and thus not known at
# analysis time).
content.add_all(
[(file, relative_to_dir, back_to_root_path) for file in headers],
format_each = ' {} "%s"'.format(kind),
map_each = _header_info_mapper,
)

def write_module_map(
actions,
module_map_file,
Expand Down Expand Up @@ -74,24 +87,15 @@ def write_module_map(
content.add_all(exported_module_ids, format_each = " export %s")
content.add("")

def _add_headers(*, headers, kind):
# Each header is added to the `Args` object as a tuple along with
# `relative_to_dir` and `back_to_root_path`. This gives the mapping
# function the information it needs to relativize the header paths even
# when they're expanded from a tree artifact (and thus not known at
# analysis time).
content.add_all(
[(file, relative_to_dir, back_to_root_path) for file in headers],
format_each = ' {} "%s"'.format(kind),
map_each = _header_info_mapper,
)

_add_headers(headers = public_headers, kind = "header")
_add_headers(headers = private_headers, kind = "private header")
_add_headers(headers = public_textual_headers, kind = "textual header")
_add_headers(headers = public_headers, kind = "header", content = content, relative_to_dir = relative_to_dir, back_to_root_path = back_to_root_path)
_add_headers(headers = private_headers, kind = "private header", content = content, relative_to_dir = relative_to_dir, back_to_root_path = back_to_root_path)
_add_headers(headers = public_textual_headers, kind = "textual header", content = content, relative_to_dir = relative_to_dir, back_to_root_path = back_to_root_path)
_add_headers(
headers = private_textual_headers,
kind = "private textual header",
content = content,
relative_to_dir = relative_to_dir,
back_to_root_path = back_to_root_path,
)
content.add("")

Expand Down
13 changes: 7 additions & 6 deletions swift/internal/swift_clang_module_aspect.bzl
Expand Up @@ -205,6 +205,13 @@ def _tagged_target_module_name(label, tags):
_, _, module_name = tag.partition("=")
return module_name

# TODO: Once bazel supports nested functions unify this with upstream
# Sort dependent module names and the headers to ensure a deterministic
# order in the output file, in the event the compilation context would ever
# change this on us. For files, use the execution path as the sorting key.
def _path_sorting_key(file):
return file.path

def _generate_module_map(
actions,
compilation_context,
Expand Down Expand Up @@ -249,12 +256,6 @@ def _generate_module_map(
target_name = target.label.name,
)

# Sort dependent module names and the headers to ensure a deterministic
# order in the output file, in the event the compilation context would ever
# change this on us. For files, use the execution path as the sorting key.
def _path_sorting_key(file):
return file.path

write_module_map(
actions = actions,
dependent_module_names = sorted(dependent_module_names),
Expand Down

0 comments on commit b1cc212

Please sign in to comment.