Skip to content

Commit 6e2fcb7

Browse files
sellophaneGoogler
andauthored
Improve BuildInvoker capablities (#7589)
The capabilities of a build invoker are used like the hard requirements by the callers to obtain an appropriate invoker. For example, if a caller needs to build an android instrumentation test, it calls getBuildInvoker with a required capability BUILDS_AIT. This change updates the capabilities in such a way that they represent what caller requires, instead of what a build system can do. There is no behavior change in the IDE, the following changes are made to the capabilities based on what they're used for. 1. IS_LOCAL -> BUILD_AIT. 2. SUPPORTS_PARALLELISM -> BUILD_PARALLEL_SHARDS. 3. SUPPORTS_API -> RUN_REMOTE_QUERIES. 4. SUPPORTS_DBIP -> removed. 5. DEBUG_LOCAL_TEST -> added. Bug: 374906681 Test: n/a Change-Id: Id29c1e5eb6e3561552a8edc1e334963da97e2da3 AOSP: 226defcef8928f0846b8fb4346e840b5a2b38864 Co-authored-by: Googler <[email protected]>
1 parent 6583f71 commit 6e2fcb7

File tree

10 files changed

+51
-28
lines changed

10 files changed

+51
-28
lines changed

aswb/src/com/google/idea/blaze/android/run/runner/BlazeInstrumentationTestApkBuildStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession
9090
BuildInvoker invoker =
9191
Blaze.getBuildSystemProvider(project)
9292
.getBuildSystem()
93-
.getBuildInvoker(project, ImmutableSet.of(BuildInvoker.Capability.IS_LOCAL));
93+
.getBuildInvoker(project, ImmutableSet.of(BuildInvoker.Capability.BUILD_AIT)).orElseThrow();
9494
BlazeCommand.Builder command = BlazeCommand.builder(invoker, BlazeCommandName.BUILD);
9595
// TODO(mathewi) we implicitly rely here on the fact that the getBuildInvoker() call above
9696
// will always return a local invoker (deployInfoHelper below required that the artifacts

base/src/com/google/idea/blaze/base/bazel/BazelBuildSystem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public BuildSystemName getName() {
3636
}
3737

3838
@Override
39-
public BuildInvoker getBuildInvoker(Project project, Set<BuildInvoker.Capability> requirements) {
40-
return new LocalInvoker(project, this, BuildBinaryType.BAZEL);
39+
public Optional<BuildInvoker> getBuildInvoker(Project project, Set<BuildInvoker.Capability> requirements) {
40+
return Optional.of(new LocalInvoker(project, this, BuildBinaryType.BAZEL));
4141
}
4242

4343
@Override

base/src/com/google/idea/blaze/base/bazel/BuildSystem.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,26 @@ enum SyncStrategy {
7373
interface BuildInvoker {
7474

7575
enum Capability {
76-
IS_LOCAL, SUPPORTS_CLI, SUPPORTS_PARALLELISM, SUPPORTS_API, SUPPORTS_DBIP
76+
/**
77+
* Capability to build Android Instrumentation Test APK
78+
*/
79+
BUILD_AIT,
80+
/**
81+
* Capability to invoke blaze/bazel via CLI
82+
*/
83+
SUPPORT_CLI,
84+
/**
85+
* Capability to run parallel builds
86+
*/
87+
BUILD_PARALLEL_SHARDS,
88+
/**
89+
* Capability to run blaze/bazel query command via remote invocation
90+
*/
91+
RUN_REMOTE_QUERIES,
92+
/**
93+
* Capability to debug Android local test
94+
*/
95+
DEBUG_LOCAL_TEST
7796
}
7897

7998
default ImmutableSet<Capability> getCapabilities() {
@@ -142,13 +161,13 @@ default ImmutableSet<Capability> getCapabilities() {
142161
/**
143162
* Get a Blaze invoker with desired capabilities.
144163
*/
145-
BuildInvoker getBuildInvoker(Project project, Set<BuildInvoker.Capability> requirements);
164+
Optional<BuildInvoker> getBuildInvoker(Project project, Set<BuildInvoker.Capability> requirements);
146165

147166
/**
148167
* Get a Blaze invoker.
149168
*/
150169
default BuildInvoker getBuildInvoker(Project project) {
151-
return getBuildInvoker(project, ImmutableSet.of());
170+
return getBuildInvoker(project, ImmutableSet.of()).orElseThrow();
152171
}
153172

154173
/**
@@ -197,7 +216,7 @@ void populateBlazeVersionData(
197216
default BuildInvoker getDefaultInvoker(Project project) {
198217
if (Blaze.getProjectType(project) != ProjectType.QUERY_SYNC
199218
&& getSyncStrategy(project) == SyncStrategy.PARALLEL) {
200-
return getBuildInvoker(project, ImmutableSet.of(BuildInvoker.Capability.SUPPORTS_PARALLELISM));
219+
return getBuildInvoker(project, ImmutableSet.of(BuildInvoker.Capability.BUILD_PARALLEL_SHARDS)).orElseThrow();
201220
}
202221
return getBuildInvoker(project);
203222
}

base/src/com/google/idea/blaze/base/bazel/LocalInvoker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public BlazeCommandRunner getCommandRunner() {
8787

8888
@Override
8989
public ImmutableSet<Capability> getCapabilities() {
90-
return ImmutableSet.of(Capability.IS_LOCAL, Capability.SUPPORTS_CLI);
90+
return ImmutableSet.of(Capability.BUILD_AIT, Capability.SUPPORT_CLI, Capability.DEBUG_LOCAL_TEST);
9191
}
9292

9393
@Override

base/src/com/google/idea/blaze/base/qsync/BazelQueryRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public QuerySummary runQuery(QuerySpec query, BlazeContext context)
6767
if (PREFER_REMOTE_QUERIES.getValue()) {
6868
invoker =
6969
buildSystem
70-
.getBuildInvoker(project, ImmutableSet.of(BuildInvoker.Capability.SUPPORTS_API));
70+
.getBuildInvoker(project, ImmutableSet.of(BuildInvoker.Capability.RUN_REMOTE_QUERIES)).orElseThrow();
7171
} else {
7272
invoker = buildSystem.getDefaultInvoker(project);
7373
}

base/src/com/google/idea/blaze/base/sync/BuildPhaseSyncTask.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ private void doRun(BlazeContext context) throws SyncFailedException, SyncCancele
241241

242242
BuildInvoker syncBuildInvoker =
243243
parallel
244-
? buildSystem.getBuildInvoker(project, ImmutableSet.of(BuildInvoker.Capability.SUPPORTS_PARALLELISM))
244+
? buildSystem.getBuildInvoker(project, ImmutableSet.of(BuildInvoker.Capability.BUILD_PARALLEL_SHARDS)).orElseThrow()
245245
: defaultInvoker;
246246
final BlazercMigrator blazercMigrator = new BlazercMigrator(project);
247-
if (!syncBuildInvoker.getCapabilities().contains(BuildInvoker.Capability.SUPPORTS_CLI)
247+
if (!syncBuildInvoker.getCapabilities().contains(BuildInvoker.Capability.SUPPORT_CLI)
248248
&& blazercMigrator.needMigration()) {
249249
context.output(
250250
SummaryOutput.output(Prefix.INFO, "No .blazerc found at workspace root!").log().dedupe());
@@ -260,7 +260,7 @@ private void doRun(BlazeContext context) throws SyncFailedException, SyncCancele
260260
.setParallelBuilds(
261261
syncBuildInvoker
262262
.getCapabilities()
263-
.contains(BuildInvoker.Capability.SUPPORTS_PARALLELISM));
263+
.contains(BuildInvoker.Capability.BUILD_PARALLEL_SHARDS));
264264

265265
BlazeBuildOutputs.Legacy blazeBuildResult =
266266
getBlazeBuildResult(context, viewSet, shardedTargets, syncBuildInvoker, parallel);

base/src/com/google/idea/blaze/base/sync/sharding/ShardedTargetList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public BuildResult runShardedCommand(
9898
if (shardedTargets.size() == 1) {
9999
return invocation.apply(shardedTargets.get(0));
100100
}
101-
if (binary.getCapabilities().contains(BuildInvoker.Capability.SUPPORTS_PARALLELISM)
101+
if (binary.getCapabilities().contains(BuildInvoker.Capability.BUILD_PARALLEL_SHARDS)
102102
&& invokeParallel) {
103103
return runInParallel(project, context, invocation);
104104
}

base/tests/utils/unit/com/google/idea/blaze/base/bazel/BuildSystemProviderWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ public BuildSystemName getName() {
274274
}
275275

276276
@Override
277-
public BuildInvoker getBuildInvoker(
277+
public Optional<BuildInvoker> getBuildInvoker(
278278
Project project, Set<BuildInvoker.Capability> requirements) {
279-
return new BuildInvokerWrapper(inner.getBuildInvoker(project, requirements));
279+
return Optional.of(new BuildInvokerWrapper(inner.getBuildInvoker(project, requirements).orElseThrow()));
280280
}
281281

282282
@Override

base/tests/utils/unit/com/google/idea/blaze/base/bazel/FakeBuildSystem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public static Builder builder(BuildSystemName name) {
4646
public abstract BuildSystemName getName();
4747

4848
@Nullable
49-
abstract BuildInvoker getBuildInvoker();
49+
abstract Optional<BuildInvoker> getBuildInvoker();
5050

5151
@Override
52-
public BuildInvoker getBuildInvoker(Project project, Set<BuildInvoker.Capability> requirements) {
52+
public Optional<BuildInvoker> getBuildInvoker(Project project, Set<BuildInvoker.Capability> requirements) {
5353
return getBuildInvoker();
5454
}
5555
@Override

java/src/com/google/idea/blaze/java/run/BlazeJavaRunProfileState.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.common.base.CharMatcher;
2222
import com.google.common.base.Preconditions;
2323
import com.google.common.collect.ImmutableList;
24+
import com.google.common.collect.ImmutableSet;
2425
import com.google.common.util.concurrent.FutureCallback;
2526
import com.google.common.util.concurrent.Futures;
2627
import com.google.common.util.concurrent.ListenableFuture;
@@ -115,16 +116,17 @@ public void addKotlinxCoroutinesJavaAgent(String kotlinxCoroutinesJavaAgent) {
115116
protected ProcessHandler startProcess() throws ExecutionException {
116117
Project project = getConfiguration().getProject();
117118
BlazeContext context = BlazeContext.create();
118-
BuildInvoker invoker =
119-
Blaze.getBuildSystemProvider(project)
120-
.getBuildSystem()
121-
.getBuildInvoker(
122-
project, getExecutorType(), getConfiguration().getTargetKind());
123119
boolean debuggingLocalTest =
124120
TargetKindUtil.isLocalTest(getConfiguration().getTargetKind())
125121
&& getExecutorType().isDebugType();
122+
ImmutableSet<BuildInvoker.Capability> requirements =
123+
debuggingLocalTest ? ImmutableSet.of(BuildInvoker.Capability.DEBUG_LOCAL_TEST) : ImmutableSet.of();
124+
BuildInvoker invoker =
125+
Blaze.getBuildSystemProvider(project)
126+
.getBuildSystem()
127+
.getBuildInvoker(project, requirements).orElseThrow();
126128
if (debuggingLocalTest
127-
&& !invoker.getCapabilities().contains(BuildInvoker.Capability.SUPPORTS_CLI)) {
129+
&& !invoker.getCapabilities().contains(BuildInvoker.Capability.SUPPORT_CLI)) {
128130
return startProcessRunfilesCase(project);
129131
}
130132
return startProcessBazelCliCase(invoker, project, context);
@@ -193,7 +195,8 @@ protected ConsoleView createConsole() {
193195
return consoleView;
194196
}
195197
});
196-
} else {
198+
}
199+
else {
197200
blazeCommand =
198201
getBlazeCommandBuilder(
199202
project,
@@ -280,7 +283,8 @@ static BlazeCommand.Builder getBlazeCommandBuilder(
280283
int debugPort = handlerState.getDebugPortState().port;
281284
if (isBinary) {
282285
command.addExeFlags(debugPortFlag(false, debugPort));
283-
} else {
286+
}
287+
else {
284288
command.addBlazeFlags(BlazeFlags.JAVA_TEST_DEBUG);
285289
command.addBlazeFlags(debugPortFlag(true, debugPort));
286290
}
@@ -380,15 +384,15 @@ public void onSuccess(BlazeTestResults blazeTestResults) {
380384
// later. The LocalTestResultFinderStrategy won't work here since it writes/reads the
381385
// test results to a local file.
382386
verify(testResultFinderStrategy instanceof BlazeTestResultHolder);
383-
((BlazeTestResultHolder) testResultFinderStrategy).setTestResults(blazeTestResults);
387+
((BlazeTestResultHolder)testResultFinderStrategy).setTestResults(blazeTestResults);
384388
processHandler.detachProcess();
385389
}
386390

387391
@Override
388392
public void onFailure(Throwable throwable) {
389393
context.handleException(throwable.getMessage(), throwable);
390394
verify(testResultFinderStrategy instanceof BlazeTestResultHolder);
391-
((BlazeTestResultHolder) testResultFinderStrategy)
395+
((BlazeTestResultHolder)testResultFinderStrategy)
392396
.setTestResults(BlazeTestResults.NO_RESULTS);
393397
processHandler.detachProcess();
394398
}
@@ -402,7 +406,7 @@ public void processWillTerminate(@NotNull ProcessEvent event, boolean willBeDest
402406
if (willBeDestroyed) {
403407
context.setCancelled();
404408
verify(testResultFinderStrategy instanceof BlazeTestResultHolder);
405-
((BlazeTestResultHolder) testResultFinderStrategy)
409+
((BlazeTestResultHolder)testResultFinderStrategy)
406410
.setTestResults(BlazeTestResults.NO_RESULTS);
407411
processHandler.detachProcess();
408412
}

0 commit comments

Comments
 (0)