Skip to content

Commit 56d624b

Browse files
wilwellcopybara-github
wilwell
authored andcommitted
Separate ExecException.java from main actions target.
PiperOrigin-RevId: 413105213
1 parent 47ad531 commit 56d624b

15 files changed

+102
-101
lines changed

src/main/java/com/google/devtools/build/lib/actions/ActionExecutionException.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.devtools.build.lib.skyframe.DetailedException;
2525
import com.google.devtools.build.lib.util.DetailedExitCode;
2626
import com.google.devtools.build.lib.util.ExitCode;
27+
import javax.annotation.Nullable;
2728
import net.starlark.java.syntax.Location;
2829

2930
/**
@@ -115,6 +116,47 @@ private static NestedSet<Cause> rootCausesFromAction(
115116
detailedExitCode));
116117
}
117118

119+
public static ActionExecutionException fromExecException(ExecException exception, Action action) {
120+
return fromExecException(exception, null, action);
121+
}
122+
123+
/**
124+
* Returns a new ActionExecutionException given an optional action subtask describing which part
125+
* of the action failed (should be null for standard action failures). When appropriate (we use
126+
* some heuristics to decide), produces an abbreviated message incorporating just the termination
127+
* status if available.
128+
*
129+
* @param exception initial ExecException
130+
* @param actionSubtask additional information about the action
131+
* @param action failed action
132+
* @return ActionExecutionException object describing the action failure
133+
*/
134+
public static ActionExecutionException fromExecException(
135+
ExecException exception, @Nullable String actionSubtask, Action action) {
136+
// Message from ActionExecutionException will be prepended with action.describe() where
137+
// necessary: because not all ActionExecutionExceptions come from this codepath, it is safer
138+
// for consumers to manually prepend. We still put action.describe() in the failure detail
139+
// message argument.
140+
String message =
141+
(actionSubtask == null ? "" : actionSubtask + ": ")
142+
+ exception.getMessageForActionExecutionException();
143+
144+
DetailedExitCode code =
145+
DetailedExitCode.of(exception.getFailureDetail(action.describe() + " failed: " + message));
146+
147+
if (exception instanceof LostInputsExecException) {
148+
return ((LostInputsExecException) exception).fromExecException(message, action, code);
149+
}
150+
151+
return fromExecException(exception, message, action, code);
152+
}
153+
154+
public static ActionExecutionException fromExecException(
155+
ExecException exception, String message, Action action, DetailedExitCode code) {
156+
return new ActionExecutionException(
157+
message, exception, action, exception.isCatastrophic(), code);
158+
}
159+
118160
/** Returns the action that failed. */
119161
public ActionAnalysisMetadata getAction() {
120162
return action;

src/main/java/com/google/devtools/build/lib/actions/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,9 @@ java_library(
346346
"//third_party:error_prone_annotations",
347347
],
348348
)
349+
350+
java_library(
351+
name = "exec_exception",
352+
srcs = ["ExecException.java"],
353+
deps = ["//src/main/protobuf:failure_details_java_proto"],
354+
)

src/main/java/com/google/devtools/build/lib/actions/ExecException.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
package com.google.devtools.build.lib.actions;
1616

1717
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
18-
import com.google.devtools.build.lib.util.DetailedExitCode;
19-
import com.google.errorprone.annotations.ForOverride;
20-
import javax.annotation.Nullable;
2118

2219
/**
2320
* An exception indication that the execution of an action has failed OR could not be attempted OR
@@ -82,52 +79,9 @@ public boolean isCatastrophic() {
8279
return catastrophe;
8380
}
8481

85-
/**
86-
* Returns a new ActionExecutionException without a message prefix.
87-
*
88-
* @param action failed action
89-
* @return ActionExecutionException object describing the action failure
90-
*/
91-
public final ActionExecutionException toActionExecutionException(Action action) {
92-
return toActionExecutionException(null, action);
93-
}
94-
95-
/**
96-
* Returns a new ActionExecutionException given an optional action subtask describing which part
97-
* of the action failed (should be null for standard action failures). When appropriate (we use
98-
* some heuristics to decide), produces an abbreviated message incorporating just the termination
99-
* status if available.
100-
*
101-
* @param actionSubtask additional information about the action
102-
* @param action failed action
103-
* @return ActionExecutionException object describing the action failure
104-
*/
105-
public final ActionExecutionException toActionExecutionException(
106-
@Nullable String actionSubtask, Action action) {
107-
// Message from ActionExecutionException will be prepended with action.describe() where
108-
// necessary: because not all ActionExecutionExceptions come from this codepath, it is safer
109-
// for consumers to manually prepend. We still put action.describe() in the failure detail
110-
// message argument.
111-
String message =
112-
(actionSubtask == null ? "" : actionSubtask + ": ")
113-
+ getMessageForActionExecutionException();
114-
return toActionExecutionException(
115-
message,
116-
action,
117-
DetailedExitCode.of(getFailureDetail(action.describe() + " failed: " + message)));
118-
}
119-
120-
@ForOverride
121-
protected ActionExecutionException toActionExecutionException(
122-
String message, Action action, DetailedExitCode code) {
123-
return new ActionExecutionException(message, this, action, isCatastrophic(), code);
124-
}
125-
126-
@ForOverride
12782
protected String getMessageForActionExecutionException() {
12883
return getMessage();
12984
}
13085

131-
@ForOverride
13286
protected abstract FailureDetail getFailureDetail(String message);
13387
}

src/main/java/com/google/devtools/build/lib/actions/LostInputsExecException.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ public ActionInputDepOwners getOwners() {
6464
return owners;
6565
}
6666

67-
@Override
68-
protected ActionExecutionException toActionExecutionException(
67+
protected ActionExecutionException fromExecException(
6968
String message, Action action, DetailedExitCode code) {
7069
return new LostInputsActionExecutionException(
7170
message, lostInputs, owners, action, /*cause=*/ this, code);

src/main/java/com/google/devtools/build/lib/analysis/actions/AbstractFileWriteAction.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,14 @@ public ActionContinuationOrResult execute()
8989
return this;
9090
}
9191
} catch (ExecException e) {
92-
throw e.toActionExecutionException(
93-
AbstractFileWriteAction.this);
92+
throw ActionExecutionException.fromExecException(e, AbstractFileWriteAction.this);
9493
}
9594
afterWrite(actionExecutionContext);
9695
return ActionContinuationOrResult.of(ActionResult.create(nextContinuation.get()));
9796
}
9897
};
9998
} catch (ExecException e) {
100-
throw e.toActionExecutionException(
101-
this);
99+
throw ActionExecutionException.fromExecException(e, this);
102100
}
103101
}
104102

src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public final ActionContinuationOrResult beginExecution(
318318
beforeExecute(actionExecutionContext);
319319
spawn = getSpawn(actionExecutionContext);
320320
} catch (ExecException e) {
321-
throw e.toActionExecutionException(this);
321+
throw ActionExecutionException.fromExecException(e, this);
322322
} catch (CommandLineExpansionException e) {
323323
throw createCommandLineException(e);
324324
}
@@ -1413,7 +1413,7 @@ public ActionContinuationOrResult execute()
14131413
}
14141414
return new SpawnActionContinuation(actionExecutionContext, nextContinuation);
14151415
} catch (ExecException e) {
1416-
throw e.toActionExecutionException(SpawnAction.this);
1416+
throw ActionExecutionException.fromExecException(e, SpawnAction.this);
14171417
}
14181418
}
14191419
}

src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ public ActionContinuationOrResult execute()
164164
return this;
165165
}
166166
} catch (ExecException e) {
167-
throw e.toActionExecutionException(
168-
TemplateExpansionAction.this);
167+
throw ActionExecutionException.fromExecException(e, TemplateExpansionAction.this);
169168
}
170169
return ActionContinuationOrResult.of(ActionResult.create(nextContinuation.get()));
171170
}

src/main/java/com/google/devtools/build/lib/analysis/test/TestRunnerAction.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -956,10 +956,10 @@ public ActionContinuationOrResult beginExecution(
956956
testActionContext.isTestKeepGoing(),
957957
cancelFuture);
958958
} catch (ExecException e) {
959-
throw e.toActionExecutionException(this);
959+
throw ActionExecutionException.fromExecException(e, this);
960960
} catch (IOException e) {
961-
throw new EnvironmentalExecException(e, Code.TEST_RUNNER_IO_EXCEPTION)
962-
.toActionExecutionException(this);
961+
throw ActionExecutionException.fromExecException(
962+
new EnvironmentalExecException(e, Code.TEST_RUNNER_IO_EXCEPTION), this);
963963
}
964964
}
965965

@@ -1256,10 +1256,11 @@ public ActionContinuationOrResult execute()
12561256
Preconditions.checkState(actualMaxAttempts != 0);
12571257
return process(result, actualMaxAttempts);
12581258
} catch (ExecException e) {
1259-
throw e.toActionExecutionException(this.testRunnerAction);
1259+
throw ActionExecutionException.fromExecException(e, this.testRunnerAction);
12601260
} catch (IOException e) {
1261-
throw new EnvironmentalExecException(e, Code.TEST_RUNNER_IO_EXCEPTION)
1262-
.toActionExecutionException(this.testRunnerAction);
1261+
throw ActionExecutionException.fromExecException(
1262+
new EnvironmentalExecException(e, Code.TEST_RUNNER_IO_EXCEPTION),
1263+
this.testRunnerAction);
12631264
}
12641265
}
12651266

src/main/java/com/google/devtools/build/lib/bazel/coverage/CoverageReportActionBuilder.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,29 @@
6464

6565
/**
6666
* A class to create the coverage report generator action.
67-
*
68-
* <p>The coverage report action is created after every test shard action is created, at the
69-
* very end of the analysis phase. There is only one coverage report action per coverage
70-
* command invocation. It can also be viewed as a single sink node of the action graph.
71-
*
67+
*
68+
* <p>The coverage report action is created after every test shard action is created, at the very
69+
* end of the analysis phase. There is only one coverage report action per coverage command
70+
* invocation. It can also be viewed as a single sink node of the action graph.
71+
*
7272
* <p>Its inputs are the individual coverage.dat files from the test outputs (each shard produces
73-
* one) and the baseline coverage artifacts. Note that each ConfiguredTarget among the
74-
* transitive dependencies of the top level test targets may provide baseline coverage artifacts.
75-
*
73+
* one) and the baseline coverage artifacts. Note that each ConfiguredTarget among the transitive
74+
* dependencies of the top level test targets may provide baseline coverage artifacts.
75+
*
7676
* <p>The coverage report generation can have two phases, though they both run in the same action.
7777
* The source code of the coverage report tool {@code lcov_merger} is in the {@code
78-
* testing/coverage/lcov_merger} directory. The deployed binaries used by Blaze are under
79-
* {@code tools/coverage}.
80-
*
78+
* testing/coverage/lcov_merger} directory. The deployed binaries used by Blaze are under {@code
79+
* tools/coverage}.
80+
*
8181
* <p>The first phase is merging the individual coverage files into a single report file. The
8282
* location of this file is reported by Blaze. This phase always happens if the {@code
8383
* --combined_report=lcov} or {@code --combined_report=html}.
84-
*
84+
*
8585
* <p>The second phase is generating an html report. It only happens if {@code
86-
* --combined_report=html}. The action generates an html output file potentially for every
87-
* tested source file into the report. Since this set of files is unknown in the analysis
88-
* phase (the tool figures it out from the contents of the merged coverage report file)
89-
* the action always runs locally when {@code --combined_report=html}.
86+
* --combined_report=html}. The action generates an html output file potentially for every tested
87+
* source file into the report. Since this set of files is unknown in the analysis phase (the tool
88+
* figures it out from the contents of the merged coverage report file) the action always runs
89+
* locally when {@code --combined_report=html}.
9090
*/
9191
public final class CoverageReportActionBuilder {
9292

@@ -147,7 +147,7 @@ public ActionResult execute(ActionExecutionContext actionExecutionContext)
147147
actionExecutionContext.getEventHandler().handle(Event.info(locationMessage));
148148
return ActionResult.create(spawnResults);
149149
} catch (ExecException e) {
150-
throw e.toActionExecutionException(this);
150+
throw ActionExecutionException.fromExecException(e, this);
151151
}
152152
}
153153

src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public void createSymlinks(
116116
.createSymlinksDirectly(
117117
action.getOutputManifest().getPath().getParentDirectory(), runfiles);
118118
} catch (IOException e) {
119-
throw new EnvironmentalExecException(e, Code.SYMLINK_TREE_CREATION_IO_EXCEPTION)
120-
.toActionExecutionException(action);
119+
throw ActionExecutionException.fromExecException(
120+
new EnvironmentalExecException(e, Code.SYMLINK_TREE_CREATION_IO_EXCEPTION), action);
121121
}
122122

123123
Path inputManifest =
@@ -136,7 +136,7 @@ public void createSymlinks(
136136
actionExecutionContext.getFileOutErr());
137137
}
138138
} catch (ExecException e) {
139-
throw e.toActionExecutionException(action);
139+
throw ActionExecutionException.fromExecException(e, action);
140140
}
141141
}
142142
}

src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ private NestedSet<Artifact> findUsedHeaders(
454454
createFailureDetail("Find used headers failure", Code.FIND_USED_HEADERS_IO_EXCEPTION));
455455
}
456456
} catch (ExecException e) {
457-
throw e.toActionExecutionException("include scanning", this);
457+
throw ActionExecutionException.fromExecException(e, "include scanning", this);
458458
}
459459
}
460460

@@ -1814,7 +1814,7 @@ public ActionContinuationOrResult execute()
18141814
dotDContents = getDotDContents(spawnResults.get(0));
18151815
} catch (ExecException e) {
18161816
copyTempOutErrToActionOutErr();
1817-
throw e.toActionExecutionException(CppCompileAction.this);
1817+
throw ActionExecutionException.fromExecException(e, CppCompileAction.this);
18181818
} catch (InterruptedException e) {
18191819
copyTempOutErrToActionOutErr();
18201820
throw e;
@@ -1892,9 +1892,10 @@ private void copyTempOutErrToActionOutErr() throws ActionExecutionException {
18921892
}
18931893
}
18941894
} catch (IOException e) {
1895-
throw new EnvironmentalExecException(
1896-
e, createFailureDetail("OutErr copy failure", Code.COPY_OUT_ERR_FAILURE))
1897-
.toActionExecutionException(CppCompileAction.this);
1895+
throw ActionExecutionException.fromExecException(
1896+
new EnvironmentalExecException(
1897+
e, createFailureDetail("OutErr copy failure", Code.COPY_OUT_ERR_FAILURE)),
1898+
CppCompileAction.this);
18981899
}
18991900
}
19001901
}

src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public Artifact create(
109109
};
110110

111111
private static final String LINK_GUID = "58ec78bd-1176-4e36-8143-439f656b181d";
112-
112+
113113
@Nullable private final String mnemonic;
114114
private final LibraryToLink outputLibrary;
115115
private final Artifact linkOutput;
@@ -451,8 +451,7 @@ public ActionContinuationOrResult execute()
451451
}
452452
return ActionContinuationOrResult.of(ActionResult.create(nextContinuation.get()));
453453
} catch (ExecException e) {
454-
throw e.toActionExecutionException(
455-
CppLinkAction.this);
454+
throw ActionExecutionException.fromExecException(e, CppLinkAction.this);
456455
}
457456
}
458457
}

src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,10 @@ private Deps.Dependencies readFullOutputDeps(
664664
return createFullOutputDeps(
665665
Iterables.getOnlyElement(results), outputDepsProto, getInputs(), actionExecutionContext);
666666
} catch (IOException e) {
667-
throw new EnvironmentalExecException(
668-
e, createFailureDetail(".jdeps read IOException", Code.JDEPS_READ_IO_EXCEPTION))
669-
.toActionExecutionException(this);
667+
throw ActionExecutionException.fromExecException(
668+
new EnvironmentalExecException(
669+
e, createFailureDetail(".jdeps read IOException", Code.JDEPS_READ_IO_EXCEPTION)),
670+
this);
670671
}
671672
}
672673

@@ -742,12 +743,13 @@ public ActionContinuationOrResult execute()
742743
// We don't create any tree artifacts anyway.
743744
/*cleanupArchivedArtifacts=*/ false);
744745
} catch (IOException e) {
745-
throw new EnvironmentalExecException(
746+
throw ActionExecutionException.fromExecException(
747+
new EnvironmentalExecException(
746748
e,
747749
createFailureDetail(
748750
"Failed to delete reduced action outputs",
749-
Code.REDUCED_CLASSPATH_FALLBACK_CLEANUP_FAILURE))
750-
.toActionExecutionException(JavaCompileAction.this);
751+
Code.REDUCED_CLASSPATH_FALLBACK_CLEANUP_FAILURE)),
752+
JavaCompileAction.this);
751753
}
752754
actionExecutionContext.getMetadataHandler().resetOutputs(getOutputs());
753755
Spawn spawn;
@@ -764,7 +766,7 @@ public ActionContinuationOrResult execute()
764766
return new JavaFallbackActionContinuation(
765767
actionExecutionContext, results, fallbackContinuation);
766768
} catch (ExecException e) {
767-
throw e.toActionExecutionException(JavaCompileAction.this);
769+
throw ActionExecutionException.fromExecException(e, JavaCompileAction.this);
768770
}
769771
}
770772
}
@@ -808,7 +810,7 @@ public ActionContinuationOrResult execute()
808810
ActionResult.create(
809811
ImmutableList.copyOf(Iterables.concat(primaryResults, fallbackResults))));
810812
} catch (ExecException e) {
811-
throw e.toActionExecutionException(JavaCompileAction.this);
813+
throw ActionExecutionException.fromExecException(e, JavaCompileAction.this);
812814
}
813815
}
814816
}

0 commit comments

Comments
 (0)