use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class AndroidNdkRepositoryFunction method getNdkRelease.
private static NdkRelease getNdkRelease(Path directory, Environment env) throws RepositoryFunctionException, InterruptedException {
// For NDK r11+
Path releaseFilePath = directory.getRelative("source.properties");
if (!releaseFilePath.exists()) {
// For NDK r10e
releaseFilePath = directory.getRelative("RELEASE.TXT");
}
SkyKey releaseFileKey = FileValue.key(RootedPath.toRootedPath(directory, releaseFilePath));
String releaseFileContent;
try {
env.getValueOrThrow(releaseFileKey, IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
releaseFileContent = new String(FileSystemUtils.readContent(releaseFilePath));
} catch (IOException | FileSymlinkException | InconsistentFilesystemException e) {
throw new RepositoryFunctionException(new IOException("Could not read " + releaseFilePath.getBaseName() + " in Android NDK: " + e.getMessage()), Transience.PERSISTENT);
}
return NdkRelease.create(releaseFileContent.trim());
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class StandaloneTestStrategy method exec.
@Override
public void exec(TestRunnerAction action, ActionExecutionContext actionExecutionContext) throws ExecException, InterruptedException {
Path execRoot = actionExecutionContext.getExecutor().getExecRoot();
Path coverageDir = execRoot.getRelative(action.getCoverageDirectory());
Path runfilesDir = getLocalRunfilesDirectory(action, actionExecutionContext, binTools, action.getLocalShellEnvironment(), action.isEnableRunfiles());
Path tmpDir = tmpDirRoot.getChild(getTmpDirName(action.getExecutionSettings().getExecutable().getExecPath()));
Map<String, String> env = setupEnvironment(action, execRoot, runfilesDir, tmpDir);
Path workingDirectory = runfilesDir.getRelative(action.getRunfilesPrefix());
ResolvedPaths resolvedPaths = action.resolve(execRoot);
Map<String, String> info = new HashMap<>();
// This key is only understood by StandaloneSpawnStrategy.
info.put("timeout", "" + getTimeout(action));
info.putAll(action.getTestProperties().getExecutionInfo());
Spawn spawn = new SimpleSpawn(action, getArgs(COLLECT_COVERAGE, action), ImmutableMap.copyOf(env), ImmutableMap.copyOf(info), new RunfilesSupplierImpl(runfilesDir.asFragment(), action.getExecutionSettings().getRunfiles()), /*inputs=*/
ImmutableList.copyOf(action.getInputs()), /*tools=*/
ImmutableList.<Artifact>of(), /*filesetManifests=*/
ImmutableList.<Artifact>of(), ImmutableList.copyOf(action.getSpawnOutputs()), action.getTestProperties().getLocalResourceUsage(executionOptions.usingLocalTestJobs()));
Executor executor = actionExecutionContext.getExecutor();
TestResultData.Builder dataBuilder = TestResultData.newBuilder();
try {
int maxAttempts = getTestAttempts(action);
TestResultData data = executeTestAttempt(action, spawn, actionExecutionContext, execRoot, coverageDir, tmpDir, workingDirectory);
int attempt;
for (attempt = 1; data.getStatus() != BlazeTestStatus.PASSED && attempt < maxAttempts; attempt++) {
processFailedTestAttempt(attempt, executor, action, dataBuilder, data, actionExecutionContext.getFileOutErr());
data = executeTestAttempt(action, spawn, actionExecutionContext, execRoot, coverageDir, tmpDir, workingDirectory);
}
processLastTestAttempt(attempt, dataBuilder, data);
ImmutableList.Builder<Pair<String, Path>> testOutputsBuilder = new ImmutableList.Builder<>();
if (action.getTestLog().getPath().exists()) {
testOutputsBuilder.add(Pair.of("test.log", action.getTestLog().getPath()));
}
if (resolvedPaths.getXmlOutputPath().exists()) {
testOutputsBuilder.add(Pair.of("test.xml", resolvedPaths.getXmlOutputPath()));
}
executor.getEventBus().post(new TestAttempt(action, attempt, data.getTestPassed(), data.getRunDurationMillis(), testOutputsBuilder.build(), true));
finalizeTest(actionExecutionContext, action, dataBuilder.build());
} catch (IOException e) {
executor.getEventHandler().handle(Event.error("Caught I/O exception: " + e));
throw new EnvironmentalExecException("unexpected I/O exception", e);
}
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class StandaloneTestStrategy method processFailedTestAttempt.
private void processFailedTestAttempt(int attempt, Executor executor, TestRunnerAction action, Builder dataBuilder, TestResultData data, FileOutErr outErr) throws IOException {
ImmutableList.Builder<Pair<String, Path>> testOutputsBuilder = new ImmutableList.Builder<>();
// Rename outputs
String namePrefix = FileSystemUtils.removeExtension(action.getTestLog().getExecPath().getBaseName());
Path attemptsDir = action.getTestLog().getPath().getParentDirectory().getChild(namePrefix + "_attempts");
attemptsDir.createDirectory();
String attemptPrefix = "attempt_" + attempt;
Path testLog = attemptsDir.getChild(attemptPrefix + ".log");
if (action.getTestLog().getPath().exists()) {
action.getTestLog().getPath().renameTo(testLog);
testOutputsBuilder.add(Pair.of("test.log", testLog));
}
ResolvedPaths resolvedPaths = action.resolve(executor.getExecRoot());
if (resolvedPaths.getXmlOutputPath().exists()) {
Path destinationPath = attemptsDir.getChild(attemptPrefix + ".xml");
resolvedPaths.getXmlOutputPath().renameTo(destinationPath);
testOutputsBuilder.add(Pair.of("test.xml", destinationPath));
}
// Add the test log to the output
dataBuilder.addFailedLogs(testLog.toString());
dataBuilder.addTestTimes(data.getTestTimes(0));
dataBuilder.addAllTestProcessTimes(data.getTestProcessTimesList());
executor.getEventBus().post(new TestAttempt(action, attempt, data.getTestPassed(), data.getRunDurationMillis(), testOutputsBuilder.build(), false));
processTestOutput(executor, outErr, new TestResult(action, data, false), testLog);
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class StandaloneTestStrategy method processTestOutput.
/**
* Outputs test result to the stdout after test has finished (e.g. for --test_output=all or
* --test_output=errors). Will also try to group output lines together (up to 10000 lines) so
* parallel test outputs will not get interleaved.
*/
protected void processTestOutput(Executor executor, FileOutErr outErr, TestResult result, Path testLogPath) throws IOException {
Path testOutput = executor.getExecRoot().getRelative(testLogPath.asFragment());
boolean isPassed = result.getData().getTestPassed();
try {
if (TestLogHelper.shouldOutputTestLog(executionOptions.testOutput, isPassed)) {
TestLogHelper.writeTestLog(testOutput, result.getTestName(), outErr.getOutputStream());
}
} finally {
if (isPassed) {
executor.getEventHandler().handle(Event.of(EventKind.PASS, null, result.getTestName()));
} else {
if (result.getData().getStatus() == BlazeTestStatus.TIMEOUT) {
executor.getEventHandler().handle(Event.of(EventKind.TIMEOUT, null, result.getTestName() + " (see " + testOutput + ")"));
} else {
executor.getEventHandler().handle(Event.of(EventKind.FAIL, null, result.getTestName() + " (see " + testOutput + ")"));
}
}
}
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class TestStrategy method getLocalRunfilesDirectory.
/**
* Returns the runfiles directory associated with the test executable, creating/updating it if
* necessary and --build_runfile_links is specified.
*/
protected static Path getLocalRunfilesDirectory(TestRunnerAction testAction, ActionExecutionContext actionExecutionContext, BinTools binTools, ImmutableMap<String, String> shellEnvironment, boolean enableRunfiles) throws ExecException, InterruptedException {
TestTargetExecutionSettings execSettings = testAction.getExecutionSettings();
Path runfilesDir = execSettings.getRunfilesDir();
// as a flag to the build.
if (execSettings.getRunfilesSymlinksCreated()) {
return runfilesDir;
}
// Synchronize runfiles tree generation on the runfiles manifest artifact.
// This is necessary, because we might end up with multiple test runner actions
// trying to generate same runfiles tree in case of --runs_per_test > 1 or
// local test sharding.
long startTime = Profiler.nanoTimeMaybe();
synchronized (execSettings.getInputManifest()) {
Profiler.instance().logSimpleTask(startTime, ProfilerTask.WAIT, testAction);
updateLocalRunfilesDirectory(testAction, runfilesDir, actionExecutionContext, binTools, shellEnvironment, enableRunfiles);
}
return runfilesDir;
}
Aggregations