use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class TreeArtifactMetadataTest method testEqualTreeArtifacts.
@Test
public void testEqualTreeArtifacts() throws Exception {
Artifact treeArtifact = createTreeArtifact("out");
ImmutableList<PathFragment> children = ImmutableList.of(new PathFragment("one"), new PathFragment("two"));
TreeArtifactValue valueOne = evaluateTreeArtifact(treeArtifact, children);
MemoizingEvaluator evaluator = driver.getGraphForTesting();
evaluator.delete(new Predicate<SkyKey>() {
@Override
public boolean apply(SkyKey key) {
// Delete action execution node to force our artifacts to be re-evaluated.
return actions.contains(key.argument());
}
});
TreeArtifactValue valueTwo = evaluateTreeArtifact(treeArtifact, children);
assertThat(valueOne.getDigest()).isNotSameAs(valueTwo.getDigest());
assertThat(valueOne).isEqualTo(valueTwo);
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class TreeArtifactMetadataTest method testIOExceptionEndToEnd.
/**
* Tests that ArtifactFunction rethrows transitive {@link IOException}s as
* {@link MissingInputFileException}s.
*/
@Test
public void testIOExceptionEndToEnd() throws Throwable {
final IOException exception = new IOException("boop");
setupRoot(new CustomInMemoryFs() {
@Override
public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
if (path.getBaseName().equals("one")) {
throw exception;
}
return super.stat(path, followSymlinks);
}
});
try {
Artifact artifact = createTreeArtifact("outOne");
TreeArtifactValue value = evaluateTreeArtifact(artifact, ImmutableList.of(new PathFragment("one")));
fail("MissingInputFileException expected, got " + value);
} catch (Exception e) {
assertThat(Throwables.getRootCause(e).getMessage()).contains(exception.getMessage());
}
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class TreeArtifactMetadataTest method testIdenticalTreeArtifactsProduceTheSameDigests.
@Test
public void testIdenticalTreeArtifactsProduceTheSameDigests() throws Exception {
// Make sure different root dirs for set artifacts don't produce different digests.
Artifact one = createTreeArtifact("outOne");
Artifact two = createTreeArtifact("outTwo");
ImmutableList<PathFragment> children = ImmutableList.of(new PathFragment("one"), new PathFragment("two"));
TreeArtifactValue valueOne = evaluateTreeArtifact(one, children);
TreeArtifactValue valueTwo = evaluateTreeArtifact(two, children);
assertThat(valueOne.getDigest()).isEqualTo(valueTwo.getDigest());
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class JavaCommon method getJavaBinSubstitution.
/**
* Returns the string that the stub should use to determine the JVM
* @param launcher if non-null, the cc_binary used to launch the Java Virtual Machine
*/
public static String getJavaBinSubstitution(RuleContext ruleContext, @Nullable Artifact launcher) {
Preconditions.checkState(ruleContext.getConfiguration().hasFragment(Jvm.class));
PathFragment javaExecutable;
if (launcher != null) {
javaExecutable = launcher.getRootRelativePath();
} else {
javaExecutable = ruleContext.getFragment(Jvm.class).getRunfilesJavaExecutable();
}
if (!javaExecutable.isAbsolute()) {
javaExecutable = new PathFragment(new PathFragment(ruleContext.getWorkspaceName()), javaExecutable);
}
javaExecutable = javaExecutable.normalize();
if (ruleContext.getConfiguration().runfilesEnabled()) {
String prefix = "";
if (!javaExecutable.isAbsolute()) {
prefix = "${JAVA_RUNFILES}/";
}
return "JAVABIN=${JAVABIN:-" + prefix + javaExecutable.getPathString() + "}";
} else {
return "JAVABIN=${JAVABIN:-$(rlocation " + javaExecutable.getPathString() + ")}";
}
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class JavaHelper method getJavaResourcePath.
public static PathFragment getJavaResourcePath(JavaSemantics semantics, RuleContext ruleContext, Artifact resource) {
PathFragment rootRelativePath = resource.getRootRelativePath();
if (!resource.getOwner().getWorkspaceRoot().isEmpty()) {
PathFragment workspace = new PathFragment(resource.getOwner().getWorkspaceRoot());
rootRelativePath = rootRelativePath.relativeTo(workspace);
}
if (!ruleContext.attributes().has("resource_strip_prefix", Type.STRING) || !ruleContext.attributes().isAttributeValueExplicitlySpecified("resource_strip_prefix")) {
return semantics.getDefaultJavaResourcePath(rootRelativePath);
}
PathFragment prefix = new PathFragment(ruleContext.attributes().get("resource_strip_prefix", Type.STRING));
if (!rootRelativePath.startsWith(prefix)) {
ruleContext.attributeError("resource_strip_prefix", String.format("Resource file '%s' is not under the specified prefix to strip", rootRelativePath));
return rootRelativePath;
}
return rootRelativePath.relativeTo(prefix);
}
Aggregations