use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testInputTreeArtifactPerActionFileCache.
@Test
public void testInputTreeArtifactPerActionFileCache() throws Exception {
TouchingTestAction actionOne = new TouchingTestAction(outOneFileOne, outOneFileTwo);
registerAction(actionOne);
final Artifact normalOutput = createDerivedArtifact("normal/out");
Action testAction = new TestAction(TestAction.NO_EFFECT, ImmutableList.of(outOne), ImmutableList.of(normalOutput)) {
@Override
public void execute(ActionExecutionContext actionExecutionContext) {
try {
// Check the file cache for input TreeFileArtifacts.
ActionInputFileCache fileCache = actionExecutionContext.getActionInputFileCache();
assertThat(fileCache.getDigest(outOneFileOne)).isNotNull();
assertThat(fileCache.getDigest(outOneFileTwo)).isNotNull();
// Touch the action output.
touchFile(normalOutput);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
registerAction(testAction);
buildArtifact(normalOutput);
}
use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testDigestInjection.
// This is more a smoke test than anything, because it turns out that:
// 1) there is no easy way to turn fast digests on/off for these test cases, and
// 2) injectDigest() doesn't really complain if you inject bad digests or digests
// for nonexistent files. Instead some weird error shows up down the line.
// In fact, there are no tests for injectDigest anywhere in the codebase.
// So all we're really testing here is that injectDigest() doesn't throw a weird exception.
// TODO(bazel-team): write real tests for injectDigest, here and elsewhere.
@Test
public void testDigestInjection() throws Exception {
TreeArtifactTestAction action = new TreeArtifactTestAction(outOne) {
@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException {
try {
writeFile(outOneFileOne, "one");
writeFile(outOneFileTwo, "two");
MetadataHandler md = actionExecutionContext.getMetadataHandler();
FileStatus stat = outOneFileOne.getPath().stat(Symlinks.NOFOLLOW);
md.injectDigest(outOneFileOne, new InjectedStat(stat.getLastModifiedTime(), stat.getSize(), stat.getNodeId()), Hashing.md5().hashString("one", Charset.forName("UTF-8")).asBytes());
stat = outOneFileTwo.getPath().stat(Symlinks.NOFOLLOW);
md.injectDigest(outOneFileTwo, new InjectedStat(stat.getLastModifiedTime(), stat.getSize(), stat.getNodeId()), Hashing.md5().hashString("two", Charset.forName("UTF-8")).asBytes());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
registerAction(action);
buildArtifact(action.getSoleOutput());
}
use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testOutputsAreReadOnlyAndExecutable.
@Test
public void testOutputsAreReadOnlyAndExecutable() throws Exception {
final Artifact out = createTreeArtifact("output");
TreeArtifactTestAction action = new TreeArtifactTestAction(out) {
@Override
public void execute(ActionExecutionContext actionExecutionContext) {
try {
writeFile(out.getPath().getChild("one"), "one");
writeFile(out.getPath().getChild("two"), "two");
writeFile(out.getPath().getChild("three").getChild("four"), "three/four");
registerOutput(actionExecutionContext, "one");
registerOutput(actionExecutionContext, "two");
registerOutput(actionExecutionContext, "three/four");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
registerAction(action);
buildArtifact(action.getSoleOutput());
checkDirectoryPermissions(out.getPath());
checkFilePermissions(out.getPath().getChild("one"));
checkFilePermissions(out.getPath().getChild("two"));
checkDirectoryPermissions(out.getPath().getChild("three"));
checkFilePermissions(out.getPath().getChild("three").getChild("four"));
}
use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected.
@Test
public void testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected() throws Exception {
// Failure expected
StoredEventHandler storingEventHandler = new StoredEventHandler();
reporter.removeHandler(failFastHandler);
reporter.addHandler(storingEventHandler);
final Artifact out = createTreeArtifact("output");
TreeArtifactTestAction action = new TreeArtifactTestAction(out) {
@Override
public void execute(ActionExecutionContext actionExecutionContext) {
try {
writeFile(out.getPath().getChild("one"), "one");
writeFile(out.getPath().getChild("two"), "two");
FileSystemUtils.ensureSymbolicLink(out.getPath().getChild("links").getChild("link"), "../../output/random/pointer");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
registerAction(action);
try {
buildArtifact(action.getSoleOutput());
// Should have thrown
fail();
} catch (BuildFailedException e) {
List<Event> errors = ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
assertThat(errors).hasSize(2);
assertThat(errors.get(0).getMessage()).contains("A TreeArtifact may not contain relative symlinks whose target paths traverse " + "outside of the TreeArtifact");
assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
}
}
use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class SymlinkActionTest method testSymlink.
@Test
public void testSymlink() throws Exception {
Executor executor = new TestExecutorBuilder(directories, null).build();
action.execute(new ActionExecutionContext(executor, null, null, null, ImmutableMap.<String, String>of(), null));
assertTrue(output.isSymbolicLink());
assertEquals(input, output.resolveSymbolicLinks());
assertEquals(inputArtifact, action.getPrimaryInput());
assertEquals(outputArtifact, action.getPrimaryOutput());
}
Aggregations