Skip to content

Commit

Permalink
Implement getStarlarkArgv() for CppCompileAction
Browse files Browse the repository at this point in the history
CppLinkAction already has the implementation, it's certainly useful to have it for CppCompileAction for easier unittesting.

RELNOTES: None.
PiperOrigin-RevId: 427484386
  • Loading branch information
hlopko authored and copybara-github committed Feb 9, 2022
1 parent 41cb00c commit aaba5be
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,15 @@ public List<String> getArguments() throws CommandLineExpansionException {
return compileCommandLine.getArguments(paramFilePath, getOverwrittenVariables());
}

@Override
public Sequence<String> getStarlarkArgv() throws EvalException, InterruptedException {
try {
return StarlarkList.immutableCopyOf(getArguments());
} catch (CommandLineExpansionException ex) {
throw new EvalException(ex);
}
}

@Override
public Sequence<CommandLineArgsApi> getStarlarkArgs() throws EvalException {
ImmutableSet<Artifact> directoryInputs =
Expand Down
37 changes: 37 additions & 0 deletions src/test/shell/bazel/cc_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,43 @@ EOF
|| fail "args didn't contain tree artifact paths"
}

function test_argv_in_compile_action() {
local package="${FUNCNAME[0]}"
mkdir -p "${package}"

cat > "${package}/lib.bzl" <<EOF
def _actions_test_impl(target, ctx):
action = [a for a in target.actions if a.mnemonic == "CppCompile"][0]
aspect_out = ctx.actions.declare_file('aspect_out')
ctx.actions.run_shell(inputs = action.inputs,
outputs = [aspect_out],
command = "echo \$@ > " + aspect_out.path,
arguments = action.argv)
return [OutputGroupInfo(out=[aspect_out])]
actions_test_aspect = aspect(implementation = _actions_test_impl)
EOF

touch "${package}/x.cc"
cat > "${package}/BUILD" <<EOF
cc_library(
name = "x",
srcs = ["x.cc"],
)
EOF

bazel build "${package}:x" \
--aspects="//${package}:lib.bzl%actions_test_aspect" \
--output_groups=out

cat "bazel-bin/${package}/aspect_out" | \
grep "\(gcc\|clang\|clanc-cl.exe\|cl.exe\)" \
|| fail "args didn't contain the tool path"

cat "bazel-bin/${package}/aspect_out" | grep "a.*o .*b.*o .*c.*o" \
|| fail "args didn't contain tree artifact paths"
}

function test_directory_arg_compile_action() {
# This test assumes the presence of "nodeps" dynamic libraries, which do not
# function on Apple platforms.
Expand Down

0 comments on commit aaba5be

Please sign in to comment.