Skip to content

Commit

Permalink
Mark configurations as tool or non-tool in cquery/aquery proto output
Browse files Browse the repository at this point in the history
1. Add a field to the Configuration message in the BES indicating if a
Configuration is a tool configuration.

2. In cquery and aquery proto output, add a field to the Configuration message
indicating if it's a tool configuration.

RELNOTES: In aquery and cquery proto output, indicate if a configuration is a
tool or non-tool configuration.
PiperOrigin-RevId: 429567132
  • Loading branch information
ehaugh authored and copybara-github committed Feb 18, 2022
1 parent 22c4f88 commit fb92e2d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ private BuildConfigurationEvent createBuildEvent() {
.setPlatformName(getCpu())
.putAllMakeVariable(getMakeEnvironment())
.setCpu(getCpu())
.setIsTool(isToolConfiguration())
.build());
return new BuildConfigurationEvent(eventId, builder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ message Configuration {
string platform_name = 2;
string cpu = 3;
map<string, string> make_variable = 4;
// Whether this configuration is used for building tools.
bool is_tool = 5;
}

// Payload of the event indicating the expansion of a target pattern.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public ImmutableList<Configuration> getConfigurations() {
.setMnemonic(configProto.getMnemonic())
.setPlatformName(configProto.getPlatformName())
.setId(entry.getValue())
.setIsTool(configProto.getIsTool())
.build();
})
.collect(toImmutableList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Configuration createProto(BuildEvent config, int id) throws InterruptedException
.setChecksum(config.getEventId().getConfiguration().getId())
.setMnemonic(configProto.getMnemonic())
.setPlatformName(configProto.getPlatformName())
.setIsTool(configProto.getIsTool())
.setId(id)
.build();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/protobuf/analysis_v2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ message Configuration {

// The checksum representation of the configuration options;
string checksum = 4;

// Whether this configuration is used for building tools.
bool is_tool = 5;
}

message KeyValuePair {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ java_test(
deps = [
":configured_target_query_helper",
":configured_target_query_test",
"//src/main/java/com/google/devtools/build/lib/analysis:config/transition_factories",
"//src/main/java/com/google/devtools/build/lib/analysis:config/execution_transition_factory",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/query2",
Expand All @@ -132,7 +132,6 @@ java_test(
"//src/main/protobuf:analysis_v2_java_proto",
"//src/main/protobuf:build_java_proto",
"//src/test/java/com/google/devtools/build/lib/analysis/util",
"//src/test/java/com/google/devtools/build/lib/query2/testutil",
"//third_party:guava",
"//third_party:junit4",
"//third_party:truth",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.google.devtools.build.lib.analysis.AnalysisProtosV2;
import com.google.devtools.build.lib.analysis.AnalysisProtosV2.Configuration;
import com.google.devtools.build.lib.analysis.AnalysisProtosV2.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.config.TransitionFactories;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
import com.google.devtools.build.lib.analysis.util.MockRule;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.NullEventHandler;
Expand Down Expand Up @@ -122,8 +122,6 @@ public void testSelectInAttribute() throws Exception {

@Test
public void testConfigurations() throws Exception {
FooPatchTransition attributePatchTransition = new FooPatchTransition("SET BY PATCH");

MockRule ruleWithPatch =
() ->
MockRule.define(
Expand All @@ -132,7 +130,7 @@ public void testConfigurations() throws Exception {
builder.add(
attr("deps", LABEL_LIST)
.allowedFileTypes(FileTypeSet.ANY_FILE)
.cfg(TransitionFactories.of(attributePatchTransition))));
.cfg(ExecutionTransitionFactory.create())));
MockRule parentRuleClass =
() ->
MockRule.define(
Expand All @@ -157,14 +155,6 @@ public void testConfigurations() throws Exception {
List<Configuration> configurations = cqueryResult.getConfigurationsList();
assertThat(configurations).hasSize(2);

assertThat(configurations)
.ignoringFieldDescriptors(
Configuration.getDescriptor().findFieldByName("checksum"),
Configuration.getDescriptor().findFieldByName("id"))
.containsExactly(
Configuration.newBuilder().setMnemonic("k8-fastbuild").setPlatformName("k8").build(),
Configuration.newBuilder().setMnemonic("k8-fastbuild").setPlatformName("k8").build());

List<ConfiguredTarget> resultsList = cqueryResult.getResultsList();

ConfiguredTarget parentRuleProto = getRuleProtoByName(resultsList, "//test:parent_rule");
Expand All @@ -177,6 +167,16 @@ public void testConfigurations() throws Exception {
Configuration parentConfiguration =
getConfigurationForId(configurations, parentRuleProto.getConfigurationId());
assertThat(parentConfiguration.getChecksum()).isEqualTo(parentRule.getConfigurationChecksum());
assertThat(parentConfiguration)
.ignoringFieldDescriptors(
Configuration.getDescriptor().findFieldByName("checksum"),
Configuration.getDescriptor().findFieldByName("id"))
.isEqualTo(
Configuration.newBuilder()
.setMnemonic("k8-fastbuild")
.setPlatformName("k8")
.setIsTool(false)
.build());

ConfiguredTarget transitionRuleProto =
getRuleProtoByName(resultsList, "//test:transition_rule");
Expand All @@ -193,6 +193,10 @@ public void testConfigurations() throws Exception {
ConfiguredTarget depRuleProto = getRuleProtoByName(resultsList, "//test:dep");
Configuration depRuleConfiguration =
getConfigurationForId(configurations, depRuleProto.getConfigurationId());
assertThat(depRuleConfiguration.getPlatformName()).isEqualTo("k8");
assertThat(depRuleConfiguration.getMnemonic()).matches("k8-opt-exec-.*");
assertThat(depRuleConfiguration.getIsTool()).isTrue();

KeyedConfiguredTarget depRule = getKeyedTargetByLabel(keyedTargets, "//test:dep");

assertThat(depRuleProto.getConfiguration().getChecksum())
Expand Down

0 comments on commit fb92e2d

Please sign in to comment.