Search in sources :

Example 1 with ProjectWatch

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));
    }
}
Also used : Path(java.nio.file.Path) AssertScopeExclusiveAccess(com.facebook.buck.util.concurrent.AssertScopeExclusiveAccess) ProjectWatch(com.facebook.buck.io.ProjectWatch) IOException(java.io.IOException) BserDeserializer(com.facebook.buck.bser.BserDeserializer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ProjectWatch

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));
}
Also used : ProjectWatch(com.facebook.buck.io.ProjectWatch)

Aggregations

ProjectWatch (com.facebook.buck.io.ProjectWatch)2 BserDeserializer (com.facebook.buck.bser.BserDeserializer)1 AssertScopeExclusiveAccess (com.facebook.buck.util.concurrent.AssertScopeExclusiveAccess)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1