Search in sources :

Example 1 with RunfilesSupplierImpl

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));
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 2 with RunfilesSupplierImpl

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);
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) TestResultData(com.google.devtools.build.lib.view.test.TestStatus.TestResultData) HashMap(java.util.HashMap) SimpleSpawn(com.google.devtools.build.lib.actions.SimpleSpawn) ImmutableList(com.google.common.collect.ImmutableList) Builder(com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder) IOException(java.io.IOException) EnvironmentalExecException(com.google.devtools.build.lib.actions.EnvironmentalExecException) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) ResolvedPaths(com.google.devtools.build.lib.rules.test.TestRunnerAction.ResolvedPaths) Executor(com.google.devtools.build.lib.actions.Executor) Builder(com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder) TestAttempt(com.google.devtools.build.lib.rules.test.TestAttempt) SimpleSpawn(com.google.devtools.build.lib.actions.SimpleSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) Pair(com.google.devtools.build.lib.util.Pair)

Example 3 with RunfilesSupplierImpl

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);
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Test(org.junit.Test)

Example 4 with RunfilesSupplierImpl

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);
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Test(org.junit.Test)

Example 5 with RunfilesSupplierImpl

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);
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Artifact(com.google.devtools.build.lib.actions.Artifact) EmptyRunfilesSupplier(com.google.devtools.build.lib.actions.EmptyRunfilesSupplier) RunfilesSupplier(com.google.devtools.build.lib.actions.RunfilesSupplier) Test(org.junit.Test)

Aggregations

RunfilesSupplierImpl (com.google.devtools.build.lib.analysis.RunfilesSupplierImpl)12 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)11 Test (org.junit.Test)10 Artifact (com.google.devtools.build.lib.actions.Artifact)9 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)7 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)6 EmptyRunfilesSupplier (com.google.devtools.build.lib.actions.EmptyRunfilesSupplier)6 RunfilesSupplier (com.google.devtools.build.lib.actions.RunfilesSupplier)6 AbstractAction (com.google.devtools.build.lib.actions.AbstractAction)2 Action (com.google.devtools.build.lib.actions.Action)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 EnvironmentalExecException (com.google.devtools.build.lib.actions.EnvironmentalExecException)1 Executor (com.google.devtools.build.lib.actions.Executor)1 SimpleSpawn (com.google.devtools.build.lib.actions.SimpleSpawn)1 Spawn (com.google.devtools.build.lib.actions.Spawn)1 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)1 ActionCombinationFactory (com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory)1