Skip to content

Commit

Permalink
When encountering an unrecoverable IO error during pre-execution-phas…
Browse files Browse the repository at this point in the history
…e work use the more appropriate and correct ExecutorInitException than ViewCreationException. Importantly, note that ExecutorInitException will give us the right exit code and since it's a subclass of AbruptExitException we get the right build status codes too.

--
MOS_MIGRATED_REVID=99208200
  • Loading branch information
haxorz authored and laszlocsomor committed Jul 28, 2015
1 parent 8f56558 commit ca06fa2
Showing 1 changed file with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.ViewCreationFailedException;
import com.google.devtools.build.lib.analysis.WorkspaceStatusAction;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection;
Expand Down Expand Up @@ -339,8 +338,7 @@ void executeBuild(UUID buildId, AnalysisResult analysisResult,
BuildResult buildResult, @Nullable SkyframeExecutor skyframeExecutor,
BuildConfigurationCollection configurations,
ImmutableMap<PathFragment, Path> packageRoots)
throws BuildFailedException, InterruptedException, AbruptExitException, TestExecException,
ViewCreationFailedException {
throws BuildFailedException, InterruptedException, TestExecException, AbruptExitException {
Stopwatch timer = Stopwatch.createStarted();
prepare(packageRoots, configurations);

Expand Down Expand Up @@ -478,8 +476,7 @@ void executeBuild(UUID buildId, AnalysisResult analysisResult,
}

private void prepare(ImmutableMap<PathFragment, Path> packageRoots,
BuildConfigurationCollection configurations)
throws ViewCreationFailedException {
BuildConfigurationCollection configurations) throws ExecutorInitException {
// Prepare for build.
Profiler.instance().markPhase(ProfilePhase.PREPARE);

Expand All @@ -494,13 +491,12 @@ private void createToolsSymlinks() throws ExecutorInitException {
try {
runtime.getBinTools().setupBuildTools();
} catch (ExecException e) {
throw new ExecutorInitException("Tools symlink creation failed: "
+ e.getMessage() + "; build aborted", e);
throw new ExecutorInitException("Tools symlink creation failed", e);
}
}

private void plantSymlinkForest(ImmutableMap<PathFragment, Path> packageRoots,
BuildConfigurationCollection configurations) throws ViewCreationFailedException {
BuildConfigurationCollection configurations) throws ExecutorInitException {
try {
FileSystemUtils.deleteTreesBelowNotPrefixed(getExecRoot(),
new String[] { ".", "_", Constants.PRODUCT_NAME + "-"});
Expand All @@ -510,44 +506,44 @@ private void plantSymlinkForest(ImmutableMap<PathFragment, Path> packageRoots,
}
FileSystemUtils.plantLinkForest(packageRoots, getExecRoot());
} catch (IOException e) {
throw new ViewCreationFailedException("Source forest creation failed: " + e.getMessage()
+ "; build aborted", e);
throw new ExecutorInitException("Source forest creation failed", e);
}
}

private void createActionLogDirectory() throws ViewCreationFailedException {
private void createActionLogDirectory() throws ExecutorInitException {
Path directory = runtime.getDirectories().getActionConsoleOutputDirectory();
try {
if (directory.exists()) {
FileSystemUtils.deleteTree(directory);
}
directory.createDirectory();
} catch (IOException ex) {
throw new ViewCreationFailedException("couldn't delete action output directory: " +
ex.getMessage());
} catch (IOException e) {
throw new ExecutorInitException("Couldn't delete action output directory", e);
}
}

/**
* Prepare for a local output build.
*/
private void startLocalOutputBuild() throws BuildFailedException {
private void startLocalOutputBuild() throws ExecutorInitException {
long startTime = Profiler.nanoTimeMaybe();

try {
Path outputPath = runtime.getOutputPath();
Path localOutputPath = runtime.getDirectories().getLocalOutputPath();

if (outputPath.isSymbolicLink()) {
// Remove the existing symlink first.
outputPath.delete();
if (localOutputPath.exists()) {
// Pre-existing local output directory. Move to outputPath.
localOutputPath.renameTo(outputPath);
try {
// Remove the existing symlink first.
outputPath.delete();
if (localOutputPath.exists()) {
// Pre-existing local output directory. Move to outputPath.
localOutputPath.renameTo(outputPath);
}
} catch (IOException e) {
throw new ExecutorInitException("Couldn't handle local output directory symlinks", e);
}
}
} catch (IOException e) {
throw new BuildFailedException(e.getMessage());
} finally {
Profiler.instance().logSimpleTask(startTime, ProfilerTask.INFO,
"Starting local output build");
Expand Down

0 comments on commit ca06fa2

Please sign in to comment.