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));
}
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;
}
}
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;
}
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);
}
}
}
}
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/*/*/*, 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();
}
Aggregations