Skip to content

Commit

Permalink
Extract out get_argsfiles_output function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chatura-atapattu authored and facebook-github-bot committed Jun 15, 2023
1 parent 9387a6d commit 5838bef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
13 changes: 13 additions & 0 deletions prelude/cxx/argsfiles.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,16 @@ CompileArgsfiles = record(
# Absolute path argsfiles used for extra outputs, mapped by extension.
absolute = field({str.type: CompileArgsfile.type}, default = {}),
)

def get_argsfiles_output(ctx: "context", argsfile_by_ext: {str.type: CompileArgsfile.type}, summary_name: str.type) -> DefaultInfo.type:
argsfiles = []
argsfile_names = cmd_args()
dependent_outputs = []
for _, argsfile in argsfile_by_ext.items():
argsfiles.append(argsfile.file)
argsfile_names.add(cmd_args(argsfile.file).ignore_artifacts())
dependent_outputs.extend(argsfile.input_args)

argsfiles_summary = ctx.actions.write(summary_name, argsfile_names)

return DefaultInfo(default_outputs = [argsfiles_summary] + argsfiles, other_outputs = dependent_outputs)
16 changes: 3 additions & 13 deletions prelude/cxx/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ load(
"@prelude//utils:utils.bzl",
"flatten",
)
load(":argsfiles.bzl", "CompileArgsfile", "CompileArgsfiles")
load(":argsfiles.bzl", "CompileArgsfile", "CompileArgsfiles", "get_argsfiles_output")
load(":attr_selection.bzl", "cxx_by_language_ext")
load(
":compiler.bzl",
Expand Down Expand Up @@ -268,20 +268,10 @@ def create_compile_cmds(
)

def _get_argsfile_output(ctx: "context", argsfile_by_ext: {str.type: CompileArgsfile.type}, summary_name: str.type) -> CxxCompileCommandArgsFiles.type:
argsfiles = []
argsfile_names = cmd_args()
dependent_outputs = []
argsfile_artifacts_by_ext = {}
for ext, argsfile in argsfile_by_ext.items():
argsfiles.append(argsfile.file)
argsfile_names.add(cmd_args(argsfile.file).ignore_artifacts())
dependent_outputs.extend(argsfile.input_args)
argsfile_artifacts_by_ext[ext] = argsfile.file

argsfiles_summary = ctx.actions.write(summary_name, argsfile_names)
argsfile_artifacts_by_ext = {ext: argsfile.file for ext, argsfile in argsfile_by_ext.items()}

return CxxCompileCommandArgsFiles(
info = DefaultInfo(default_outputs = [argsfiles_summary] + argsfiles, other_outputs = dependent_outputs),
info = get_argsfiles_output(ctx, argsfile_by_ext, summary_name),
by_ext = argsfile_artifacts_by_ext,
)

Expand Down

0 comments on commit 5838bef

Please sign in to comment.