Skip to content

Commit 5838bef

Browse files
Extract out get_argsfiles_output function
Summary: The existing `_get_argsfile_output` does two things: 1. creates the argsfile subtarget DefaultInfo provider 2. sets the `by_ext` attribute for use in xcode_data Up the stack, #2 is replaced by the `CompileArgsfiles` record which contains a map of extension to `CompileArgsfile`. Extracting out #1 allows us to restructure the code (later on) to 1. define the argsfile subtarget, DefaultInfo and action only for targets that want it 2. extract it out of compilation so that compilation code is simpler Reviewed By: milend Differential Revision: D46743454 fbshipit-source-id: 31a108410e49fb85851d91334ed598a10731e7d9
1 parent 9387a6d commit 5838bef

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

prelude/cxx/argsfiles.bzl

+13
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,16 @@ CompileArgsfiles = record(
2525
# Absolute path argsfiles used for extra outputs, mapped by extension.
2626
absolute = field({str.type: CompileArgsfile.type}, default = {}),
2727
)
28+
29+
def get_argsfiles_output(ctx: "context", argsfile_by_ext: {str.type: CompileArgsfile.type}, summary_name: str.type) -> DefaultInfo.type:
30+
argsfiles = []
31+
argsfile_names = cmd_args()
32+
dependent_outputs = []
33+
for _, argsfile in argsfile_by_ext.items():
34+
argsfiles.append(argsfile.file)
35+
argsfile_names.add(cmd_args(argsfile.file).ignore_artifacts())
36+
dependent_outputs.extend(argsfile.input_args)
37+
38+
argsfiles_summary = ctx.actions.write(summary_name, argsfile_names)
39+
40+
return DefaultInfo(default_outputs = [argsfiles_summary] + argsfiles, other_outputs = dependent_outputs)

prelude/cxx/compile.bzl

+3-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load(
1111
"@prelude//utils:utils.bzl",
1212
"flatten",
1313
)
14-
load(":argsfiles.bzl", "CompileArgsfile", "CompileArgsfiles")
14+
load(":argsfiles.bzl", "CompileArgsfile", "CompileArgsfiles", "get_argsfiles_output")
1515
load(":attr_selection.bzl", "cxx_by_language_ext")
1616
load(
1717
":compiler.bzl",
@@ -268,20 +268,10 @@ def create_compile_cmds(
268268
)
269269

270270
def _get_argsfile_output(ctx: "context", argsfile_by_ext: {str.type: CompileArgsfile.type}, summary_name: str.type) -> CxxCompileCommandArgsFiles.type:
271-
argsfiles = []
272-
argsfile_names = cmd_args()
273-
dependent_outputs = []
274-
argsfile_artifacts_by_ext = {}
275-
for ext, argsfile in argsfile_by_ext.items():
276-
argsfiles.append(argsfile.file)
277-
argsfile_names.add(cmd_args(argsfile.file).ignore_artifacts())
278-
dependent_outputs.extend(argsfile.input_args)
279-
argsfile_artifacts_by_ext[ext] = argsfile.file
280-
281-
argsfiles_summary = ctx.actions.write(summary_name, argsfile_names)
271+
argsfile_artifacts_by_ext = {ext: argsfile.file for ext, argsfile in argsfile_by_ext.items()}
282272

283273
return CxxCompileCommandArgsFiles(
284-
info = DefaultInfo(default_outputs = [argsfiles_summary] + argsfiles, other_outputs = dependent_outputs),
274+
info = get_argsfiles_output(ctx, argsfile_by_ext, summary_name),
285275
by_ext = argsfile_artifacts_by_ext,
286276
)
287277

0 commit comments

Comments
 (0)