use of com.facebook.buck.io.ProjectWatch in project buck by facebook.
the class ProjectBuildFileParser method getAllRulesInternal.
@VisibleForTesting
protected ImmutableList<Map<String, Object>> getAllRulesInternal(Path buildFile) throws IOException, BuildFileParseException {
ensureNotClosed();
initIfNeeded();
// Check isInitialized implications (to avoid Eradicate warnings).
Preconditions.checkNotNull(buckPyStdinWriter);
Preconditions.checkNotNull(buckPyProcess);
ParseBuckFileEvent.Started parseBuckFileStarted = ParseBuckFileEvent.started(buildFile);
buckEventBus.post(parseBuckFileStarted);
ImmutableList<Map<String, Object>> values = ImmutableList.of();
String profile = "";
try (AssertScopeExclusiveAccess.Scope scope = assertSingleThreadedParsing.scope()) {
Path cellPath = options.getProjectRoot().toAbsolutePath();
String watchRoot = cellPath.toString();
String projectPrefix = "";
if (options.getWatchman().getProjectWatches().containsKey(cellPath)) {
ProjectWatch projectWatch = options.getWatchman().getProjectWatches().get(cellPath);
watchRoot = projectWatch.getWatchRoot();
if (projectWatch.getProjectPrefix().isPresent()) {
projectPrefix = projectWatch.getProjectPrefix().get();
}
}
bserSerializer.serializeToStream(ImmutableMap.of("buildFile", buildFile.toString(), "watchRoot", watchRoot, "projectPrefix", projectPrefix), buckPyStdinWriter);
buckPyStdinWriter.flush();
LOG.verbose("Parsing output of process %s...", buckPyProcess);
Object deserializedValue;
try {
deserializedValue = bserDeserializer.deserializeBserValue(buckPyProcess.getInputStream());
} catch (BserDeserializer.BserEofException e) {
LOG.warn(e, "Parser exited while decoding BSER data");
throw new IOException("Parser exited unexpectedly", e);
}
BuildFilePythonResult resultObject = handleDeserializedValue(deserializedValue);
Path buckPyPath = getPathToBuckPy(options.getDescriptions());
handleDiagnostics(buildFile, buckPyPath.getParent(), resultObject.getDiagnostics(), buckEventBus);
values = resultObject.getValues();
LOG.verbose("Got rules: %s", values);
LOG.verbose("Parsed %d rules from %s", values.size(), buildFile);
profile = resultObject.getProfile();
if (profile != null && profile.length() > 0) {
LOG.debug("Profile result: %s", profile);
}
return values;
} finally {
buckEventBus.post(ParseBuckFileEvent.finished(parseBuckFileStarted, values, profile));
}
}
use of com.facebook.buck.io.ProjectWatch in project buck by facebook.
the class AbstractBuildFileSpec method forEachBuildFile.
/**
* Find all build in the given {@link ProjectFilesystem}, and pass each to the given callable.
*/
public void forEachBuildFile(ProjectFilesystem filesystem, String buildFileName, ParserConfig.BuildFileSearchMethod buildFileSearchMethod, Watchman watchman, Consumer<Path> function) throws IOException, InterruptedException {
// If non-recursive, we just want the build file in the target spec's given base dir.
if (!isRecursive()) {
function.accept(filesystem.resolve(getBasePath().resolve(buildFileName)));
return;
}
LOG.debug("Finding build files for %s under %s...", getBasePath(), filesystem.getRootPath());
long walkStartTimeNanos = System.nanoTime();
// Otherwise, we need to do a recursive walk to find relevant build files.
boolean tryWatchman = buildFileSearchMethod == ParserConfig.BuildFileSearchMethod.WATCHMAN && watchman.getWatchmanClient().isPresent() && watchman.getProjectWatches().containsKey(filesystem.getRootPath());
boolean walkComplete = false;
if (tryWatchman) {
ProjectWatch projectWatch = Preconditions.checkNotNull(watchman.getProjectWatches().get(filesystem.getRootPath()));
LOG.debug("Searching for %s files (watch root %s, project prefix %s, base path %s) with Watchman", buildFileName, projectWatch.getWatchRoot(), projectWatch.getProjectPrefix(), getBasePath());
walkComplete = forEachBuildFileWatchman(filesystem, watchman.getWatchmanClient().get(), projectWatch.getWatchRoot(), projectWatch.getProjectPrefix(), getBasePath(), buildFileName, function);
} else {
LOG.debug("Not using Watchman (search method %s, client present %s, root present %s)", buildFileSearchMethod, watchman.getWatchmanClient().isPresent(), watchman.getProjectWatches().containsKey(filesystem.getRootPath()));
}
if (!walkComplete) {
LOG.debug("Searching for %s files under %s using physical filesystem crawl (note: this is slow)", buildFileName, filesystem.getRootPath());
forEachBuildFileFilesystem(filesystem, buildFileName, function);
}
long walkTimeNanos = System.nanoTime() - walkStartTimeNanos;
LOG.debug("Completed search in %d ms.", TimeUnit.NANOSECONDS.toMillis(walkTimeNanos));
}
Aggregations