Search in sources :

Example 1 with ExecutableSymlinkAction

use of com.google.devtools.build.lib.analysis.actions.ExecutableSymlinkAction in project bazel by bazelbuild.

the class ShBinary method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws RuleErrorException {
    ImmutableList<Artifact> srcs = ruleContext.getPrerequisiteArtifacts("srcs", Mode.TARGET).list();
    if (srcs.size() != 1) {
        ruleContext.attributeError("srcs", "you must specify exactly one file in 'srcs'");
        return null;
    }
    Artifact symlink = ruleContext.createOutputArtifact();
    // Note that src is used as the executable script too
    Artifact src = srcs.get(0);
    // The interpretation of this deceptively simple yet incredibly generic rule is complicated
    // by the distinction between targets and (not properly encapsulated) artifacts. It depends
    // on the notion of other rule's "files-to-build" sets, which are undocumented, making it
    // impossible to give a precise definition of what this rule does in all cases (e.g. what
    // happens when srcs = ['x', 'y'] but 'x' is an empty filegroup?). This is a pervasive
    // problem in Blaze.
    ruleContext.registerAction(new ExecutableSymlinkAction(ruleContext.getActionOwner(), src, symlink));
    NestedSet<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder().add(src).add(symlink).build();
    Runfiles runfiles = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addTransitiveArtifacts(filesToBuild).addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES).build();
    RunfilesSupport runfilesSupport = RunfilesSupport.withExecutable(ruleContext, runfiles, symlink);
    return new RuleConfiguredTargetBuilder(ruleContext).setFilesToBuild(filesToBuild).setRunfilesSupport(runfilesSupport, symlink).addProvider(RunfilesProvider.class, RunfilesProvider.simple(runfiles)).build();
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ExecutableSymlinkAction(com.google.devtools.build.lib.analysis.actions.ExecutableSymlinkAction) RunfilesSupport(com.google.devtools.build.lib.analysis.RunfilesSupport) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 2 with ExecutableSymlinkAction

use of com.google.devtools.build.lib.analysis.actions.ExecutableSymlinkAction in project bazel by bazelbuild.

the class ExecutableSymlinkActionTest method testFailIfInputIsNotExecutable.

@Test
public void testFailIfInputIsNotExecutable() throws Exception {
    Path file = inputRoot.getPath().getChild("some-file");
    FileSystemUtils.createEmptyFile(file);
    file.setExecutable(/*executable=*/
    false);
    Artifact input = new Artifact(file, inputRoot);
    Artifact output = new Artifact(outputRoot.getPath().getChild("some-output"), outputRoot);
    ExecutableSymlinkAction action = new ExecutableSymlinkAction(NULL_ACTION_OWNER, input, output);
    try {
        action.execute(createContext());
        fail();
    } catch (ActionExecutionException e) {
        String want = "'some-file' is not executable";
        String got = e.getMessage();
        assertTrue(String.format("got %s, want %s", got, want), got.contains(want));
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ExecutableSymlinkAction(com.google.devtools.build.lib.analysis.actions.ExecutableSymlinkAction) Test(org.junit.Test)

Example 3 with ExecutableSymlinkAction

use of com.google.devtools.build.lib.analysis.actions.ExecutableSymlinkAction in project bazel by bazelbuild.

the class ExecutableSymlinkActionTest method testSimple.

@Test
public void testSimple() throws Exception {
    Path inputFile = inputRoot.getPath().getChild("some-file");
    Path outputFile = outputRoot.getPath().getChild("some-output");
    FileSystemUtils.createEmptyFile(inputFile);
    inputFile.setExecutable(/*executable=*/
    true);
    Artifact input = new Artifact(inputFile, inputRoot);
    Artifact output = new Artifact(outputFile, outputRoot);
    ExecutableSymlinkAction action = new ExecutableSymlinkAction(NULL_ACTION_OWNER, input, output);
    action.execute(createContext());
    assertEquals(inputFile, outputFile.resolveSymbolicLinks());
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ExecutableSymlinkAction(com.google.devtools.build.lib.analysis.actions.ExecutableSymlinkAction) Test(org.junit.Test)

Example 4 with ExecutableSymlinkAction

use of com.google.devtools.build.lib.analysis.actions.ExecutableSymlinkAction in project bazel by bazelbuild.

the class ExecutableSymlinkActionTest method testFailIfInputIsNotAFile.

@Test
public void testFailIfInputIsNotAFile() throws Exception {
    Path dir = inputRoot.getPath().getChild("some-dir");
    FileSystemUtils.createDirectoryAndParents(dir);
    Artifact input = new Artifact(dir, inputRoot);
    Artifact output = new Artifact(outputRoot.getPath().getChild("some-output"), outputRoot);
    ExecutableSymlinkAction action = new ExecutableSymlinkAction(NULL_ACTION_OWNER, input, output);
    try {
        action.execute(createContext());
        fail();
    } catch (ActionExecutionException e) {
        assertThat(e.getMessage()).contains("'some-dir' is not a file");
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ExecutableSymlinkAction(com.google.devtools.build.lib.analysis.actions.ExecutableSymlinkAction) Test(org.junit.Test)

Aggregations

ExecutableSymlinkAction (com.google.devtools.build.lib.analysis.actions.ExecutableSymlinkAction)4 Path (com.google.devtools.build.lib.vfs.Path)3 Test (org.junit.Test)3 Artifact (com.google.devtools.build.lib.actions.Artifact)1 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)1 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)1 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)1 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)1