use of com.google.devtools.build.lib.analysis.RunfilesSupplierImpl in project bazel by bazelbuild.
the class ApkActionsBuilder method legacyBuildApk.
/**
* Registers generating actions for {@code outApk} that builds the APK specified.
*
* <p>If {@code signingKey} is not null, the apk will be signed with it using the V1 signature
* scheme.
*/
private void legacyBuildApk(RuleContext ruleContext, Artifact outApk, Artifact signingKey, String message) {
SpawnAction.Builder actionBuilder = new SpawnAction.Builder().setExecutable(AndroidSdkProvider.fromRuleContext(ruleContext).getApkBuilder()).setProgressMessage(message).setMnemonic("AndroidApkBuilder").addOutputArgument(outApk);
if (javaResourceZip != null) {
actionBuilder.addArgument("-rj").addInputArgument(javaResourceZip);
}
Pair<Artifact, Runfiles> nativeSymlinksManifestAndRunfiles = nativeLibs.createApkBuilderSymlinks(ruleContext);
if (nativeSymlinksManifestAndRunfiles != null) {
Artifact nativeSymlinksManifest = nativeSymlinksManifestAndRunfiles.first;
Runfiles nativeSymlinksRunfiles = nativeSymlinksManifestAndRunfiles.second;
PathFragment nativeSymlinksDir = nativeSymlinksManifest.getExecPath().getParentDirectory();
actionBuilder.addRunfilesSupplier(new RunfilesSupplierImpl(nativeSymlinksDir, nativeSymlinksRunfiles, nativeSymlinksManifest)).addInput(nativeSymlinksManifest).addInputs(nativeLibs.getAllNativeLibs()).addArgument("-nf").addArgument(nativeSymlinksDir.getPathString());
}
if (nativeLibs.getName() != null) {
actionBuilder.addArgument("-rf").addArgument(nativeLibs.getName().getExecPath().getParentDirectory().getPathString()).addInput(nativeLibs.getName());
}
if (nativeLibsZips != null) {
for (Artifact nativeLibsZip : nativeLibsZips) {
actionBuilder.addArgument("-z").addInputArgument(nativeLibsZip);
}
}
if (javaResourceFile != null) {
actionBuilder.addArgument("-rf").addArgument((javaResourceFile.getExecPath().getParentDirectory().getPathString())).addInput(javaResourceFile);
}
if (signingKey == null) {
actionBuilder.addArgument("-u");
} else {
actionBuilder.addArgument("-ks").addArgument(signingKey.getExecPathString());
actionBuilder.addInput(signingKey);
}
actionBuilder.addArgument("-z").addInputArgument(resourceApk);
if (classesDex != null) {
actionBuilder.addArgument(classesDex.getFilename().endsWith(".dex") ? "-f" : "-z").addInputArgument(classesDex);
}
ruleContext.registerAction(actionBuilder.build(ruleContext));
}
use of com.google.devtools.build.lib.analysis.RunfilesSupplierImpl 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.analysis.RunfilesSupplierImpl in project bazel by bazelbuild.
the class BaseSpawnTest method testGetEnvironmentAddsRunfilesWhenOnlyOneSuppliedViaRunfilesSupplier.
@Test
public void testGetEnvironmentAddsRunfilesWhenOnlyOneSuppliedViaRunfilesSupplier() {
Map<String, String> baseEnviron = ImmutableMap.of("HELLO", "world");
final String runfilesDir = "runfilesdir";
BaseSpawn underTest = minimalBaseSpawn(baseEnviron, new RunfilesSupplierImpl(new PathFragment(runfilesDir), Runfiles.EMPTY));
Map<String, String> expected = ImmutableMap.<String, String>builder().putAll(baseEnviron).put("PYTHON_RUNFILES", runfilesDir).put("JAVA_RUNFILES", runfilesDir).build();
assertThat(underTest.getEnvironment()).isEqualTo(expected);
}
use of com.google.devtools.build.lib.analysis.RunfilesSupplierImpl in project bazel by bazelbuild.
the class BaseSpawnTest method testGetEnvironmentDoesntAddRunfilesWhenMultipleManifestsSupplied.
@Test
public void testGetEnvironmentDoesntAddRunfilesWhenMultipleManifestsSupplied() {
Map<String, String> baseEnviron = ImmutableMap.of("HELLO", "world");
BaseSpawn underTest = minimalBaseSpawn(baseEnviron, new CompositeRunfilesSupplier(new RunfilesSupplierImpl(new PathFragment("rfdir1"), Runfiles.EMPTY), new RunfilesSupplierImpl(new PathFragment("rfdir2"), Runfiles.EMPTY)));
assertThat(underTest.getEnvironment()).isEqualTo(baseEnviron);
}
use of com.google.devtools.build.lib.analysis.RunfilesSupplierImpl in project bazel by bazelbuild.
the class SpawnInputExpanderTest method testRunfilesSymlink.
@Test
public void testRunfilesSymlink() throws Exception {
Artifact artifact = new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
Runfiles runfiles = new Runfiles.Builder("workspace").addSymlink(new PathFragment("symlink"), artifact).build();
RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
Mockito.when(mockCache.isFile(artifact)).thenReturn(true);
expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
assertThat(inputMappings).hasSize(1);
assertThat(inputMappings).containsEntry(new PathFragment("runfiles/workspace/symlink"), artifact);
}
Aggregations