Search in sources :

Example 11 with PathFragment

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

the class PackageIdentifier method parse.

public static PackageIdentifier parse(String input) throws LabelSyntaxException {
    String repo;
    String packageName;
    int packageStartPos = input.indexOf("//");
    if (input.startsWith("@") && packageStartPos > 0) {
        repo = input.substring(0, packageStartPos);
        packageName = input.substring(packageStartPos + 2);
    } else if (input.startsWith("@")) {
        throw new LabelSyntaxException("starts with a '@' but does not contain '//'");
    } else if (packageStartPos == 0) {
        repo = RepositoryName.DEFAULT_REPOSITORY;
        packageName = input.substring(2);
    } else {
        repo = RepositoryName.DEFAULT_REPOSITORY;
        packageName = input;
    }
    String error = RepositoryName.validate(repo);
    if (error != null) {
        throw new LabelSyntaxException(error);
    }
    error = LabelValidator.validatePackageName(packageName);
    if (error != null) {
        throw new LabelSyntaxException(error);
    }
    return create(repo, new PathFragment(packageName));
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 12 with PathFragment

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

the class RepositoryName method fromPathFragment.

/**
   * Extracts the repository name from a PathFragment that was created with
   * {@code PackageIdentifier.getSourceRoot}.
   *
   * @return a {@code Pair} of the extracted repository name and the path fragment with stripped
   * of "external/"-prefix and repository name, or null if none was found or the repository name
   * was invalid.
   */
public static Pair<RepositoryName, PathFragment> fromPathFragment(PathFragment path) {
    if (path.segmentCount() < 2 || !path.getSegment(0).equals(Label.EXTERNAL_PATH_PREFIX)) {
        return null;
    }
    try {
        RepositoryName repoName = RepositoryName.create("@" + path.getSegment(1));
        PathFragment subPath = path.subFragment(2, path.segmentCount());
        return Pair.of(repoName, subPath);
    } catch (LabelSyntaxException e) {
        return null;
    }
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 13 with PathFragment

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

the class SpawnInputExpander method getInputMapping.

/**
   * Convert the inputs of the given spawn to a map from exec-root relative paths to action inputs.
   * In some cases, this generates empty files, for which it uses {@link #EMPTY_FILE}.
   */
public SortedMap<PathFragment, ActionInput> getInputMapping(Spawn spawn, ArtifactExpander artifactExpander, ActionInputFileCache actionInputFileCache, FilesetActionContext filesetContext) throws IOException {
    TreeMap<PathFragment, ActionInput> inputMap = new TreeMap<>();
    addInputs(inputMap, spawn, artifactExpander);
    addRunfilesToInputs(inputMap, spawn.getRunfilesSupplier(), actionInputFileCache);
    for (Artifact manifest : spawn.getFilesetManifests()) {
        parseFilesetManifest(inputMap, manifest, filesetContext.getWorkspaceName());
    }
    return inputMap;
}
Also used : ActionInput(com.google.devtools.build.lib.actions.ActionInput) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) TreeMap(java.util.TreeMap) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 14 with PathFragment

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

the class SpawnInputExpander method addRunfilesToInputs.

/** Adds runfiles inputs from runfilesSupplier to inputMappings. */
@VisibleForTesting
void addRunfilesToInputs(Map<PathFragment, ActionInput> inputMap, RunfilesSupplier runfilesSupplier, ActionInputFileCache actionFileCache) throws IOException {
    Map<PathFragment, Map<PathFragment, Artifact>> rootsAndMappings = null;
    rootsAndMappings = runfilesSupplier.getMappings();
    for (Entry<PathFragment, Map<PathFragment, Artifact>> rootAndMappings : rootsAndMappings.entrySet()) {
        PathFragment root = rootAndMappings.getKey();
        for (Entry<PathFragment, Artifact> mapping : rootAndMappings.getValue().entrySet()) {
            PathFragment targetPrefix = root.getRelative(mapping.getKey());
            Artifact localArtifact = mapping.getValue();
            if (localArtifact != null) {
                if (strict && !actionFileCache.isFile(localArtifact)) {
                    throw new IOException("Not a file: " + localArtifact.getPath().getPathString());
                }
                addMapping(inputMap, targetPrefix, localArtifact);
            } else {
                addMapping(inputMap, targetPrefix, EMPTY_FILE);
            }
        }
    }
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Artifact(com.google.devtools.build.lib.actions.Artifact) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 15 with PathFragment

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

the class AndroidSdkRepositoryFunction method getAndroidDeviceSystemImageDirs.

/**
   * Gets PathFragments for /sdk/system-images/*&#47;*&#47;*, which are the directories in the
   * SDK that contain system images needed for android_device.
   *
   * If the sdk/system-images directory does not exist, an empty set is returned.
   */
private static ImmutableSortedSet<PathFragment> getAndroidDeviceSystemImageDirs(Path androidSdkPath, Environment env) throws RepositoryFunctionException, InterruptedException {
    if (!androidSdkPath.getRelative(SYSTEM_IMAGES_DIR).exists()) {
        return ImmutableSortedSet.of();
    }
    DirectoryListingValue systemImagesDirectoryValue = AndroidRepositoryUtils.getDirectoryListing(androidSdkPath, SYSTEM_IMAGES_DIR, env);
    if (systemImagesDirectoryValue == null) {
        return null;
    }
    ImmutableMap<PathFragment, DirectoryListingValue> apiLevelSystemImageDirs = getSubdirectoryListingValues(androidSdkPath, SYSTEM_IMAGES_DIR, systemImagesDirectoryValue, env);
    if (apiLevelSystemImageDirs == null) {
        return null;
    }
    ImmutableSortedSet.Builder<PathFragment> pathFragments = ImmutableSortedSet.naturalOrder();
    for (PathFragment apiLevelDir : apiLevelSystemImageDirs.keySet()) {
        ImmutableMap<PathFragment, DirectoryListingValue> apiTypeSystemImageDirs = getSubdirectoryListingValues(androidSdkPath, apiLevelDir, apiLevelSystemImageDirs.get(apiLevelDir), env);
        if (apiTypeSystemImageDirs == null) {
            return null;
        }
        for (PathFragment apiTypeDir : apiTypeSystemImageDirs.keySet()) {
            for (Dirent architectureSystemImageDir : apiTypeSystemImageDirs.get(apiTypeDir).getDirents()) {
                pathFragments.add(apiTypeDir.getRelative(architectureSystemImageDir.getName()));
            }
        }
    }
    return pathFragments.build();
}
Also used : DirectoryListingValue(com.google.devtools.build.lib.skyframe.DirectoryListingValue) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Dirent(com.google.devtools.build.lib.vfs.Dirent)

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