use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class TestFileOutErr method newInMemoryFile.
private static Path newInMemoryFile(File root, String name) {
InMemoryFileSystem inMemFS = new InMemoryFileSystem();
Path directory = inMemFS.getPath(root.getPath());
try {
FileSystemUtils.createDirectoryAndParents(directory);
} catch (IOException e) {
throw new IllegalStateException(e);
}
return directory.getRelative(name);
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class BuildFileASTTest method parseBuildFile.
/**
* Parses the contents of the specified string (using DUMMY_PATH as the fake
* filename) and returns the AST. Resets the error handler beforehand.
*/
private BuildFileAST parseBuildFile(String... lines) throws IOException {
Path file = scratch.file("/a/build/file/BUILD", lines);
ParserInputSource inputSource = ParserInputSource.create(file, file.getFileSize());
return BuildFileAST.parseBuildFile(inputSource, getEventHandler());
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class Package method getTarget.
/**
* Returns the target (a member of this package) whose name is "targetName".
* First rules are searched, then output files, then input files. The target
* name must be valid, as defined by {@code LabelValidator#validateTargetName}.
*
* @throws NoSuchTargetException if the specified target was not found.
*/
public Target getTarget(String targetName) throws NoSuchTargetException {
Target target = targets.get(targetName);
if (target != null) {
return target;
}
// No such target.
// If there's a file on the disk that's not mentioned in the BUILD file,
// produce a more informative error. NOTE! this code path is only executed
// on failure, which is (relatively) very rare. In the common case no
// stat(2) is executed.
Path filename = getPackageDirectory().getRelative(targetName);
String suffix;
if (!new PathFragment(targetName).isNormalized()) {
// Don't check for file existence in this case because the error message
// would be confusing and wrong. If the targetName is "foo/bar/.", and
// there is a directory "foo/bar", it doesn't mean that "//pkg:foo/bar/."
// is a valid label.
suffix = "";
} else if (filename.isDirectory()) {
suffix = "; however, a source directory of this name exists. (Perhaps add " + "'exports_files([\"" + targetName + "\"])' to " + name + "/BUILD, or define a " + "filegroup?)";
} else if (filename.exists()) {
suffix = "; however, a source file of this name exists. (Perhaps add " + "'exports_files([\"" + targetName + "\"])' to " + name + "/BUILD?)";
} else {
suffix = SpellChecker.didYouMean(targetName, targets.keySet());
}
throw makeNoSuchTargetException(targetName, suffix);
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class PathPackageLocator method getPackageBuildFileNullable.
/**
* Like #getPackageBuildFile(), but returns null instead of throwing.
* @param packageIdentifier the name of the package.
* @param cache a filesystem-level cache of stat() calls.
*/
public Path getPackageBuildFileNullable(PackageIdentifier packageIdentifier, AtomicReference<? extends UnixGlob.FilesystemCalls> cache) {
Preconditions.checkArgument(!packageIdentifier.getRepository().isDefault());
if (packageIdentifier.getRepository().isMain()) {
return getFilePath(packageIdentifier.getPackageFragment().getRelative("BUILD"), cache);
} else {
Verify.verify(outputBase != null, String.format("External package '%s' needs to be loaded but this PathPackageLocator instance does not " + "support external packages", packageIdentifier));
// This works only to some degree, because it relies on the presence of the repository under
// $OUTPUT_BASE/external, which is created by the appropriate RepositoryDirectoryValue. This
// is true for the invocation in GlobCache, but not for the locator.getBuildFileForPackage()
// invocation in Parser#include().
Path buildFile = outputBase.getRelative(packageIdentifier.getSourceRoot()).getRelative("BUILD");
FileStatus stat = cache.get().statNullable(buildFile, Symlinks.FOLLOW);
if (stat != null && stat.isFile()) {
return buildFile;
} else {
return null;
}
}
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class WorkerFactory method create.
@Override
public Worker create(WorkerKey key) throws Exception {
int workerId = pidCounter.getAndIncrement();
Path logFile = workerBaseDir.getRelative("worker-" + workerId + "-" + key.getMnemonic() + ".log");
Worker worker;
boolean sandboxed = workerOptions.workerSandboxing || key.mustBeSandboxed();
if (sandboxed) {
Path workDir = workerBaseDir.getRelative("worker-" + workerId + "-" + key.getMnemonic());
worker = new SandboxedWorker(key, workerId, workDir, logFile);
} else {
worker = new Worker(key, workerId, key.getExecRoot(), logFile);
}
worker.prepareExecution(key);
worker.createProcess();
if (workerOptions.workerVerbose) {
reporter.handle(Event.info(String.format("Created new %s %s worker (id %d), logging to %s", sandboxed ? "sandboxed" : "non-sandboxed", key.getMnemonic(), workerId, logFile)));
}
return worker;
}
Aggregations