Skip to content

Commit

Permalink
Include indexstores as inputs to indexstore_filelist
Browse files Browse the repository at this point in the history
This ensures they are generated/downloaded when using `--features=swift.split_derived_files_generation`.

Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
brentleyjones committed Oct 10, 2023
1 parent 5e96396 commit 9e34080
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 21 deletions.
27 changes: 25 additions & 2 deletions xcodeproj/internal/indexstore_filelists.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,39 @@ def _directory_and_target_override(directory_and_target_override):
directory, target_override = directory_and_target_override
return [directory.path, target_override]

def _write(*, actions, name, rule_name, indexstore_and_target_overrides):
def _write(
*,
actions,
name,
rule_name,
indexstore_and_target_overrides,
indexstores):
args = actions.args()
args.use_param_file("%s", use_always = True)
args.set_param_file_format("multiline")

args.add_all(
indexstore_and_target_overrides,
map_each = _directory_and_target_override,
)

output = actions.declare_file("{}-{}.filelist".format(rule_name, name))
actions.write(output, args)

# We make an action to copy the params file, because we want to force the
# downloading of `indexstores`. We don't want to directly place the
# `indexstores` in an output group to prevent the explosion of the BEP.
actions.run_shell(
arguments = [args, output.path],
inputs = indexstores,
outputs = [output],
command = """\
if [[ $(stat -f '%d' "$1") == $(stat -f '%d' "${2%/*}") ]]; then
cp -c "$1" "$2"
else
cp "$1" "$2"
fi
""",
)

return output

Expand Down
44 changes: 31 additions & 13 deletions xcodeproj/internal/input_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ def _collect_input_files(

# Collect unfocused target info
indexstores = []
indexstore_overrides = []
bwx_unfocused_libraries = None
if should_include_non_xcode_outputs(ctx = ctx):
if unfocused == None:
Expand Down Expand Up @@ -559,7 +560,8 @@ def _collect_input_files(
)
generated.extend(swiftmodules)
if should_produce_output_groups and indexstore:
indexstores.append((indexstore, EMPTY_STRING))
indexstore_overrides.append((indexstore, EMPTY_STRING))
indexstores.append(indexstore)

if is_swift:
unfocused_swift_info_modules = target[SwiftInfo].transitive_modules
Expand Down Expand Up @@ -613,15 +615,23 @@ def _collect_input_files(
)

if should_produce_output_groups:
indexstores_depset = memory_efficient_depset(
transitive_indexstore_overrides = memory_efficient_depset(
indexstore_overrides,
transitive = [
info.inputs._indexstore_overrides
for info in transitive_infos
],
)
transitive_indexstores = memory_efficient_depset(
indexstores,
transitive = [
info.inputs.indexstores
info.inputs._indexstores
for info in transitive_infos
],
)
else:
indexstores_depset = EMPTY_DEPSET
transitive_indexstore_overrides = EMPTY_DEPSET
transitive_indexstores = EMPTY_DEPSET

# We need to collect transitive modulemaps, because some are private to
# dependent targets, but we still need them for the final output group
Expand Down Expand Up @@ -654,7 +664,8 @@ def _collect_input_files(

indexstores_filelist = indexstore_filelists.write(
actions = ctx.actions,
indexstore_and_target_overrides = indexstores_depset,
indexstore_and_target_overrides = transitive_indexstore_overrides,
indexstores = transitive_indexstores,
name = "xi",
rule_name = ctx.rule.attr.name,
)
Expand Down Expand Up @@ -728,7 +739,7 @@ def _collect_input_files(
c_sources = c_sources,
cxx_sources = cxx_sources,
hdrs = hdrs,
indexstores = indexstores_depset,
indexstores = transitive_indexstores,
indexstores_output_group_name = indexstores_output_group_name,
linking_output_group_name = linking_output_group_name,
non_arc_srcs = non_arc_srcs,
Expand All @@ -743,6 +754,8 @@ def _collect_input_files(
unfocused_generated_linking = unfocused_generated_linking,
),
struct(
_indexstore_overrides = transitive_indexstore_overrides,
_indexstores = transitive_indexstores,
_modulemaps = modulemaps_depset,
_non_target_swift_info_modules = non_target_swift_info_modules,
_output_group_list = memory_efficient_depset(
Expand Down Expand Up @@ -778,7 +791,6 @@ def _collect_input_files(
],
),
has_generated_files = has_generated_files,
indexstores = indexstores_depset,
extra_files = memory_efficient_depset(
[(label, depset(extra_files))] if extra_files else None,
transitive = [
Expand Down Expand Up @@ -843,6 +855,18 @@ def _merge_input_files(*, transitive_infos, extra_generated = None):
break

return struct(
_indexstore_overrides = memory_efficient_depset(
transitive = [
info.inputs._indexstore_overrides
for info in transitive_infos
],
),
_indexstores = memory_efficient_depset(
transitive = [
info.inputs._indexstores
for info in transitive_infos
],
),
_modulemaps = memory_efficient_depset(
transitive = [
info.inputs._modulemaps
Expand Down Expand Up @@ -905,12 +929,6 @@ def _merge_input_files(*, transitive_infos, extra_generated = None):
],
),
has_generated_files = has_generated_files,
indexstores = memory_efficient_depset(
transitive = [
info.inputs.indexstores
for info in transitive_infos
],
),
extra_files = memory_efficient_depset(
transitive = [
info.inputs.extra_files
Expand Down
23 changes: 17 additions & 6 deletions xcodeproj/internal/output_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,17 @@ def _collect_output_files(
if not indexstore_overrides and indexstore:
indexstore_overrides = [(indexstore, EMPTY_STRING)]

transitive_indexestores = memory_efficient_depset(
transitive_indexstore_overrides = memory_efficient_depset(
indexstore_overrides,
transitive = [
info.outputs._transitive_indexestores
info.outputs._transitive_indexstore_overrides
for info in transitive_infos
],
)
transitive_indexstores = memory_efficient_depset(
[indexstore] if indexstore else None,
transitive = [
info.outputs._transitive_indexstores
for info in transitive_infos
],
)
Expand All @@ -189,7 +196,8 @@ def _collect_output_files(
)
else:
closest_compiled = EMPTY_DEPSET
transitive_indexestores = EMPTY_DEPSET
transitive_indexstore_overrides = EMPTY_DEPSET
transitive_indexstores = EMPTY_DEPSET
transitive_products = EMPTY_DEPSET

transitive_infoplists = memory_efficient_depset(
Expand All @@ -207,7 +215,8 @@ def _collect_output_files(

indexstores_filelist = indexstore_filelists.write(
actions = ctx.actions,
indexstore_and_target_overrides = transitive_indexestores,
indexstore_and_target_overrides = transitive_indexstore_overrides,
indexstores = transitive_indexstores,
name = "bi",
rule_name = ctx.rule.attr.name,
)
Expand Down Expand Up @@ -262,7 +271,8 @@ def _collect_output_files(
_closest_compiled = closest_compiled,
_is_framework = is_framework,
_output_group_list = output_group_list,
_transitive_indexestores = transitive_indexestores,
_transitive_indexstore_overrides = transitive_indexstore_overrides,
_transitive_indexstores = transitive_indexstores,
_transitive_products = transitive_products,
_transitive_infoplists = transitive_infoplists,
),
Expand All @@ -289,7 +299,8 @@ def _merge_output_files(*, transitive_infos):
for info in transitive_infos
],
),
_transitive_indexestores = EMPTY_DEPSET,
_transitive_indexstore_overrides = EMPTY_DEPSET,
_transitive_indexstores = EMPTY_DEPSET,
_transitive_products = EMPTY_DEPSET,
_transitive_infoplists = memory_efficient_depset(
transitive = [
Expand Down

0 comments on commit 9e34080

Please sign in to comment.