Skip to content

Commit

Permalink
Break a huge method into two (#7220)
Browse files Browse the repository at this point in the history
Bug: n/a
Test: n/a
Change-Id: I5b2579d0e7a829073913d5586d27745003b59f4c

AOSP: 8e747db32fde69d20ae904fdcfed0c2b502c5585

Co-authored-by: Googler <[email protected]>
  • Loading branch information
LeFrosch and Googler authored Jan 17, 2025
1 parent 8984aa2 commit 65ecc64
Showing 1 changed file with 46 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public void addKotlinxCoroutinesJavaAgent(String kotlinxCoroutinesJavaAgent) {
protected ProcessHandler startProcess() throws ExecutionException {
Project project = getConfiguration().getProject();

BlazeCommand.Builder blazeCommand;
BuildInvoker invoker =
Blaze.getBuildSystemProvider(project)
.getBuildSystem()
Expand All @@ -110,39 +109,48 @@ protected ProcessHandler startProcess() throws ExecutionException {
getExecutorType(),
getConfiguration().getTargetKind());
BlazeTestUiSession testUiSession = null;
if (TargetKindUtil.isLocalTest(getConfiguration().getTargetKind())
&& !invoker.getCommandRunner().canUseCli()
&& getExecutorType().isDebugType()) {
File downloadDir = getDownloadDir();
WorkspaceRoot workspaceRoot =
new WorkspaceRoot(
new File(downloadDir, WorkspaceRoot.fromProject(project).directory().getName()));
ImmutableList.Builder<String> commandBuilder =
ImmutableList.<String>builder()
.add("env")
.add("-")
.add(JAVA_RUNFILES_ENV + downloadDir.getAbsolutePath());
boolean debuggingLocalTest = TargetKindUtil.isLocalTest(getConfiguration().getTargetKind())
&& getExecutorType().isDebugType();
if (debuggingLocalTest && !invoker.getCommandRunner().canUseCli()) {
return startProcessRunfilesCase(project);
}
return startProcessBazelCliCase(invoker, project, testUiSession);
}

// android_local_tests need additional env variables
if (TargetKindUtil.isAndroidLocalTest(getConfiguration().getTargetKind())) {
commandBuilder
.add(TEST_TIMEOUT_ENV + "300")
.add(TEST_SIZE_ENV + "medium")
.add(
TEST_DIAGNOSTICS_OUTPUT_DIR_ENV
+ downloadDir.getAbsolutePath()
+ TEST_DIAGNOSTICS_OUTPUT_DIR);
}
private ProcessHandler startProcessRunfilesCase(Project project) throws ExecutionException {
File downloadDir = getDownloadDir();
WorkspaceRoot workspaceRoot =
new WorkspaceRoot(
new File(downloadDir, WorkspaceRoot.fromProject(project).directory().getName()));
ImmutableList.Builder<String> commandBuilder =
ImmutableList.<String>builder()
.add("env")
.add("-")
.add(JAVA_RUNFILES_ENV + downloadDir.getAbsolutePath());

// android_local_tests need additional env variables
if (TargetKindUtil.isAndroidLocalTest(getConfiguration().getTargetKind())) {
commandBuilder
.add(getEntryPointScript())
.add(debugPortFlag(false, getState(getConfiguration()).getDebugPortState().port));
if (TargetKindUtil.isAndroidLocalTest(getConfiguration().getTargetKind())
&& BlazeCommandRunnerExperiments.USE_SINGLEJAR_FOR_DEBUGGING.getValue()) {
commandBuilder.add("--singlejar");
}
return getScopedProcessHandler(project, commandBuilder.build(), workspaceRoot);
.add(TEST_TIMEOUT_ENV + "300")
.add(TEST_SIZE_ENV + "medium")
.add(
TEST_DIAGNOSTICS_OUTPUT_DIR_ENV
+ downloadDir.getAbsolutePath()
+ TEST_DIAGNOSTICS_OUTPUT_DIR);
}
commandBuilder
.add(getEntryPointScript())
.add(debugPortFlag(false, getState(getConfiguration()).getDebugPortState().port));
if (TargetKindUtil.isAndroidLocalTest(getConfiguration().getTargetKind())
&& BlazeCommandRunnerExperiments.USE_SINGLEJAR_FOR_DEBUGGING.getValue()) {
commandBuilder.add("--singlejar");
}
return getScopedProcessHandler(project, commandBuilder.build(), workspaceRoot);
}

private ProcessHandler startProcessBazelCliCase(BuildInvoker invoker, Project project, BlazeTestUiSession testUiSession)
throws ExecutionException {
BlazeCommand.Builder blazeCommand;
try (BuildResultHelper buildResultHelper = invoker.createBuildResultHelper()) {
if (useTestUi()
&& BlazeTestEventsHandler.targetsSupported(project, getConfiguration().getTargets())) {
Expand All @@ -159,32 +167,32 @@ && getExecutorType().isDebugType()) {
if (testUiSession != null) {
blazeCommand =
getBlazeCommandBuilder(
project,
getConfiguration(),
testUiSession.getBlazeFlags(),
getExecutorType(),
kotlinxCoroutinesJavaAgent);
project,
getConfiguration(),
testUiSession.getBlazeFlags(),
getExecutorType(),
kotlinxCoroutinesJavaAgent);
final BlazeTestUiSession finalTestUiSession = testUiSession;
setConsoleBuilder(
new TextConsoleBuilderImpl(project) {
@Override
protected ConsoleView createConsole() {
return SmRunnerUtils.getConsoleView(
project, getConfiguration(), getEnvironment().getExecutor(), finalTestUiSession);
project, getConfiguration(), getEnvironment().getExecutor(), finalTestUiSession);
}
});
} else {
blazeCommand =
getBlazeCommandBuilder(
project,
project,
getConfiguration(),
ImmutableList.of(),
getExecutorType(),
kotlinxCoroutinesJavaAgent);
}
addConsoleFilters(
ToolWindowTaskIssueOutputFilter.createWithDefaultParsers(
project,
project,
WorkspaceRoot.fromProject(project),
BlazeInvocationContext.ContextType.RunConfiguration));

Expand Down

0 comments on commit 65ecc64

Please sign in to comment.