Search in sources :

Example 6 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class AndroidStudioInfoAspect method derivedArtifact.

private static Artifact derivedArtifact(ConfiguredTarget base, RuleContext ruleContext, String suffix) {
    BuildConfiguration configuration = ruleContext.getConfiguration();
    assert configuration != null;
    Root binDirectory = configuration.getBinDirectory(ruleContext.getRule().getRepository());
    PathFragment derivedFilePath = getOutputFilePath(base, ruleContext, suffix);
    return ruleContext.getAnalysisEnvironment().getDerivedArtifact(derivedFilePath, binDirectory);
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) Root(com.google.devtools.build.lib.actions.Root) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 7 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class OutputDirectoryLinksUtils method relativize.

// Helper to getPrettyPath.  Returns file, relativized w.r.t. the referent of
// "linkname", or null if it was a not a child.
private static PathFragment relativize(Path file, Path workspaceDirectory, String linkname) {
    PathFragment link = new PathFragment(linkname);
    try {
        Path dir = workspaceDirectory.getRelative(link);
        PathFragment levelOneLinkTarget = dir.readSymbolicLink();
        if (levelOneLinkTarget.isAbsolute() && file.startsWith(dir = file.getRelative(levelOneLinkTarget))) {
            return link.getRelative(file.relativeTo(dir));
        }
    } catch (IOException e) {
    /* ignore */
    }
    return null;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException)

Example 8 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class OutputDirectoryLinksUtils method getPrettyPath.

/**
   * Returns a convenient path to the specified file, relativizing it and using output-dir symlinks
   * if possible.  Otherwise, return a path relative to the workspace directory if possible.
   * Otherwise, return the absolute path.
   *
   * <p>This method must be called after the symlinks are created at the end of a build. If called
   * before, the pretty path may be incorrect if the symlinks end up pointing somewhere new.
   */
public static PathFragment getPrettyPath(Path file, String workspaceName, Path workspaceDirectory, String symlinkPrefix, String productName) {
    for (String link : LINKS) {
        PathFragment result = relativize(file, workspaceDirectory, symlinkPrefix + link);
        if (result != null) {
            return result;
        }
    }
    PathFragment result = relativize(file, workspaceDirectory, execRootSymlink(symlinkPrefix, workspaceName));
    if (result != null) {
        return result;
    }
    ImmutableList<String> outputSymlinkNames = getOutputSymlinkNames(productName, symlinkPrefix);
    checkArgument(!outputSymlinkNames.isEmpty());
    result = relativize(file, workspaceDirectory, outputSymlinkNames.get(0));
    if (result != null) {
        return result;
    }
    return file.asFragment();
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 9 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class Label method parseCommandLineLabel.

/**
   * Resolves a relative label using a workspace-relative path to the current working directory. The
   * method handles these cases:
   * <ul>
   *   <li>The label is absolute.
   *   <li>The label starts with a colon.
   *   <li>The label consists of a relative path, a colon, and a local part.
   *   <li>The label consists only of a local part.
   * </ul>
   *
   * <p>Note that this method does not support any of the special syntactic constructs otherwise
   * supported on the command line, like ":all", "/...", and so on.
   *
   * <p>It would be cleaner to use the TargetPatternEvaluator for this resolution, but that is not
   * possible, because it is sometimes necessary to resolve a relative label before the package path
   * is setup; in particular, before the tools/defaults package is created.
   *
   * @throws LabelSyntaxException if the resulting label is not valid
   */
public static Label parseCommandLineLabel(String label, PathFragment workspaceRelativePath) throws LabelSyntaxException {
    Preconditions.checkArgument(!workspaceRelativePath.isAbsolute());
    if (LabelValidator.isAbsolute(label)) {
        return parseAbsolute(label);
    }
    int index = label.indexOf(':');
    if (index < 0) {
        index = 0;
        label = ":" + label;
    }
    PathFragment path = workspaceRelativePath.getRelative(label.substring(0, index));
    // validity check.
    return create(path.getPathString(), label.substring(index + 1));
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 10 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class PackageIdentifier method discoverFromExecPath.

/**
   * Tries to infer the package identifier from the given exec path. This method does not perform
   * any I/O, but looks solely at the structure of the exec path. The resulting identifier may
   * actually be a subdirectory of a package rather than a package, e.g.:
   * <pre><code>
   * + WORKSPACE
   * + foo/BUILD
   * + foo/bar/bar.java
   * </code></pre>
   *
   * In this case, this method returns a package identifier for foo/bar, even though that is not a
   * package. Callers need to look up the actual package if needed.
   *
   * @throws LabelSyntaxException if the exec path seems to be for an external repository that doe
   *         not have a valid repository name (see {@link RepositoryName#create})
   */
public static PackageIdentifier discoverFromExecPath(PathFragment execPath, boolean forFiles) throws LabelSyntaxException {
    Preconditions.checkArgument(!execPath.isAbsolute(), execPath);
    PathFragment tofind = forFiles ? Preconditions.checkNotNull(execPath.getParentDirectory(), "Must pass in files, not root directory") : execPath;
    if (tofind.startsWith(new PathFragment(Label.EXTERNAL_PATH_PREFIX))) {
        // TODO(ulfjack): Remove this when kchodorow@'s exec root rearrangement has been rolled out.
        RepositoryName repository = RepositoryName.create("@" + tofind.getSegment(1));
        return PackageIdentifier.create(repository, tofind.subFragment(2, tofind.segmentCount()));
    } else if (!tofind.normalize().isNormalized()) {
        RepositoryName repository = RepositoryName.create("@" + tofind.getSegment(1));
        return PackageIdentifier.create(repository, tofind.subFragment(2, tofind.segmentCount()));
    } else {
        return PackageIdentifier.createInMainRepo(tofind);
    }
}
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