Search in sources :

Example 86 with PathFragment

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);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) MemoizingEvaluator(com.google.devtools.build.skyframe.MemoizingEvaluator) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Example 87 with PathFragment

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());
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) MissingInputFileException(com.google.devtools.build.lib.actions.MissingInputFileException) SkyFunctionException(com.google.devtools.build.skyframe.SkyFunctionException) IOException(java.io.IOException) Test(org.junit.Test)

Example 88 with PathFragment

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

Example 89 with PathFragment

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() + ")}";
    }
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 90 with PathFragment

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

Aggregations

PathFragment (com.google.devtools.build.lib.vfs.PathFragment)512 Test (org.junit.Test)208 Artifact (com.google.devtools.build.lib.actions.Artifact)184 Path (com.google.devtools.build.lib.vfs.Path)111 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)65 SkyKey (com.google.devtools.build.skyframe.SkyKey)56 IOException (java.io.IOException)38 ArrayList (java.util.ArrayList)35 ImmutableList (com.google.common.collect.ImmutableList)32 Root (com.google.devtools.build.lib.actions.Root)32 HashMap (java.util.HashMap)27 Label (com.google.devtools.build.lib.cmdline.Label)26 LinkedHashMap (java.util.LinkedHashMap)26 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)23 ImmutableMap (com.google.common.collect.ImmutableMap)22 Map (java.util.Map)21 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)20 FilesetTraversalParams (com.google.devtools.build.lib.actions.FilesetTraversalParams)16 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)16 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)16