Skip to content

Commit

Permalink
Add a new field to "bazel aquery" that reports scheduling dependencies.
Browse files Browse the repository at this point in the history
Aquery previously reported these files as being the inputs of a middleman action whose output is a regular input of the action. They are now a separate concept called "scheduling dependencies" which need to be handled separately.

RELNOTES[NEW]: "bazel aquery" now returns the headers C++ compilation actions can include if the --include_scheduling_dependencies command line option is set.

PiperOrigin-RevId: 575173830
Change-Id: I4a801ec8602463afd03e45d706b4dfe1f86b11e8
  • Loading branch information
lberki authored and copybara-github committed Oct 20, 2023
1 parent 9772f03 commit 6b912c5
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public BlazeCommandResult dumpActionGraphFromSkyframe(CommandEnvironment env) {
new ActionGraphDump(
aqueryOptions.includeCommandline,
aqueryOptions.includeArtifacts,
aqueryOptions.includeSchedulingDependencies,
actionFilters,
aqueryOptions.includeParamFiles,
aqueryOptions.includeFileWriteContents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ private void dumpSkyframeStateAfterBuild(
new ActionGraphDump(
/* includeActionCmdLine= */ false,
/* includeArtifacts= */ true,
/* includeSchedulingDependencies= */ true,
/* actionFilters= */ null,
/* includeParamFiles= */ false,
/* includeFileWriteContents */ false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class ActionGraphProtoOutputFormatterCallback extends AqueryThreadsafeCal
new ActionGraphDump(
options.includeCommandline,
options.includeArtifacts,
options.includeSchedulingDependencies,
this.actionFilters,
options.includeParamFiles,
options.includeFileWriteContents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,19 @@ private void writeAction(ActionAnalysisMetadata action, PrintStream printStream)
action.getInputs().toList().stream()
.map(input -> escapeBytestringUtf8(input.getExecPathString()))
.sorted()
.collect(Collectors.joining(", ")))
.collect(Collectors.joining(", ")));

if (options.includeSchedulingDependencies && !action.getSchedulingDependencies().isEmpty()) {
stringBuilder
.append(" SchedulingDependencies: [")
.append(
action.getSchedulingDependencies().toList().stream()
.map(input -> escapeBytestringUtf8(input.getExecPathString()))
.sorted()
.collect(Collectors.joining(", ")));
}

stringBuilder
.append("]\n")
.append(" Outputs: [")
.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ public class AqueryOptions extends CommonQueryOptions {
"Includes names of the action inputs and outputs in the output " + "(potentially large).")
public boolean includeArtifacts;

@Option(
name = "include_scheduling_dependencies",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.QUERY,
effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
help =
"Includes names of the scheduling dependencies of actions "
+ "(potentially large). "
+ "Only takes effect if --include_artifacts is also set.")
public boolean includeSchedulingDependencies;

@Option(
name = "include_param_files",
defaultValue = "false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class ActionGraphDump {
@Nullable private final AqueryActionFilter actionFilters;
private final boolean includeActionCmdLine;
private final boolean includeArtifacts;
private final boolean includeSchedulingDependencies;
private final boolean includeParamFiles;
private final boolean includeFileWriteContents;
private final AqueryOutputHandler aqueryOutputHandler;
Expand All @@ -78,6 +79,7 @@ public class ActionGraphDump {
public ActionGraphDump(
boolean includeActionCmdLine,
boolean includeArtifacts,
boolean includeSchedulingDependencies,
AqueryActionFilter actionFilters,
boolean includeParamFiles,
boolean includeFileWriteContents,
Expand All @@ -87,6 +89,7 @@ public ActionGraphDump(
/* actionGraphTargets= */ ImmutableList.of("..."),
includeActionCmdLine,
includeArtifacts,
includeSchedulingDependencies,
actionFilters,
includeParamFiles,
includeFileWriteContents,
Expand All @@ -98,6 +101,7 @@ public ActionGraphDump(
List<String> actionGraphTargets,
boolean includeActionCmdLine,
boolean includeArtifacts,
boolean includeSchedulingDependencies,
AqueryActionFilter actionFilters,
boolean includeParamFiles,
boolean includeFileWriteContents,
Expand All @@ -106,6 +110,7 @@ public ActionGraphDump(
this.actionGraphTargets = ImmutableSet.copyOf(actionGraphTargets);
this.includeActionCmdLine = includeActionCmdLine;
this.includeArtifacts = includeArtifacts;
this.includeSchedulingDependencies = includeSchedulingDependencies;
this.actionFilters = actionFilters;
this.includeParamFiles = includeParamFiles;
this.includeFileWriteContents = includeFileWriteContents;
Expand Down Expand Up @@ -261,6 +266,12 @@ private void dumpSingleAction(ConfiguredTarget configuredTarget, ActionAnalysisM
actionBuilder.addInputDepSetIds(knownNestedSets.dataToIdAndStreamOutputProto(inputs));
}

NestedSet<Artifact> schedulingDependencies = action.getSchedulingDependencies();
if (includeSchedulingDependencies && !schedulingDependencies.isEmpty()) {
actionBuilder.addInputDepSetIds(
knownNestedSets.dataToIdAndStreamOutputProto(schedulingDependencies));
}

// store outputs
for (Artifact artifact : action.getOutputs()) {
actionBuilder.addOutputIds(knownArtifacts.dataToIdAndStreamOutputProto(artifact));
Expand Down
5 changes: 5 additions & 0 deletions src/main/protobuf/analysis_v2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ message Action {
// input discovery, the contents of this set might change during execution.
repeated uint32 input_dep_set_ids = 8;

// The set of scheduling dependency dep sets the action depends on.
// Only set of both --include_artifacts and --include_scheduling_dependencies
// is set to true.
repeated uint32 scheduling_dep_dep_set_ids = 20;

// The list of Artifact IDs that represent the output files that this action
// will generate.
repeated uint32 output_ids = 9;
Expand Down
28 changes: 28 additions & 0 deletions src/test/shell/integration/aquery_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,34 @@ EOF
assert_not_contains "Outputs: \[" output
}

function test_aquery_include_scheduling_dependencies() {
local pkg="${FUNCNAME[0]}"
mkdir -p "$pkg" || fail "mkdir -p $pkg"
cat > "$pkg/BUILD" <<'EOF'
cc_binary(name="b", srcs=["b.cc"], deps=[":l"])
cc_library(name="l", hdrs=["library_header.h"])
EOF

bazel aquery \
--include_artifacts \
--include_scheduling_dependencies \
"mnemonic(CppCompile,//$pkg:b)" > output 2> "$TEST_log" \
|| fail "Expected success"
cat output >> "$TEST_log"

assert_contains "SchedulingDependencies:.*library_header.h" output

bazel aquery \
--include_artifacts \
--include_scheduling_dependencies \
--output=jsonproto \
"mnemonic(CppCompile,//$pkg:b)" > output 2> "$TEST_log" \
|| fail "Expected success"
cat output >> "$TEST_log"
assert_contains "library_header.h" output
}


function test_aquery_starlark_env() {
local pkg="${FUNCNAME[0]}"
mkdir -p "$pkg" || fail "mkdir -p $pkg"
Expand Down

0 comments on commit 6b912c5

Please sign in to comment.