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();
}
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));
}
}
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());
}
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");
}
}
Aggregations