Search in sources :

Example 1 with ParserConfig

use of com.facebook.buck.parser.ParserConfig in project buck by facebook.

the class TargetsCommand method buildTargetGraphAndTargets.

private TargetGraphAndBuildTargets buildTargetGraphAndTargets(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException, BuildFileParseException, BuildTargetException, VersionException {
    ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
    boolean ignoreBuckAutodepsFiles = false;
    // Parse the entire action graph, or (if targets are specified), only the specified targets and
    // their dependencies. If we're detecting test changes we need the whole graph as tests are not
    // dependencies.
    TargetGraphAndBuildTargets targetGraphAndBuildTargets;
    if (getArguments().isEmpty() || isDetectTestChanges()) {
        targetGraphAndBuildTargets = TargetGraphAndBuildTargets.builder().setBuildTargets(ImmutableSet.of()).setTargetGraph(params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, ImmutableList.of(TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get(""), params.getCell().getRoot()))), ignoreBuckAutodepsFiles, parserConfig.getDefaultFlavorsMode()).getTargetGraph()).build();
    } else {
        targetGraphAndBuildTargets = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()), ignoreBuckAutodepsFiles, parserConfig.getDefaultFlavorsMode());
    }
    return params.getBuckConfig().getTargetsVersions() ? toVersionedTargetGraph(params, targetGraphAndBuildTargets) : targetGraphAndBuildTargets;
}
Also used : ParserConfig(com.facebook.buck.parser.ParserConfig) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets)

Example 2 with ParserConfig

use of com.facebook.buck.parser.ParserConfig in project buck by facebook.

the class FetchCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    if (getArguments().isEmpty()) {
        params.getBuckEventBus().post(ConsoleEvent.severe("Must specify at least one build target to fetch."));
        return 1;
    }
    // Post the build started event, setting it to the Parser recorded start time if appropriate.
    BuildEvent.Started started = BuildEvent.started(getArguments());
    if (params.getParser().getParseStartTime().isPresent()) {
        params.getBuckEventBus().post(started, params.getParser().getParseStartTime().get());
    } else {
        params.getBuckEventBus().post(started);
    }
    FetchTargetNodeToBuildRuleTransformer ruleGenerator = createFetchTransformer(params);
    int exitCode;
    try (CommandThreadManager pool = new CommandThreadManager("Fetch", getConcurrencyLimit(params.getBuckConfig()))) {
        ActionGraphAndResolver actionGraphAndResolver;
        ImmutableSet<BuildTarget> buildTargets;
        try {
            ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
            TargetGraphAndBuildTargets result = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()), /* ignoreBuckAutodepsFiles */
            false, parserConfig.getDefaultFlavorsMode());
            if (params.getBuckConfig().getBuildVersions()) {
                result = toVersionedTargetGraph(params, result);
            }
            actionGraphAndResolver = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), ruleGenerator, result.getTargetGraph()));
            buildTargets = ruleGenerator.getDownloadableTargets();
        } catch (BuildTargetException | BuildFileParseException | VersionException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return 1;
        }
        CachingBuildEngineBuckConfig cachingBuildEngineBuckConfig = params.getBuckConfig().getView(CachingBuildEngineBuckConfig.class);
        LocalCachingBuildEngineDelegate localCachingBuildEngineDelegate = new LocalCachingBuildEngineDelegate(params.getFileHashCache());
        try (RuleKeyCacheScope<RuleKey> ruleKeyCacheScope = getDefaultRuleKeyCacheScope(params, new RuleKeyCacheRecycler.SettingsAffectingCache(params.getBuckConfig().getKeySeed(), actionGraphAndResolver.getActionGraph()));
            Build build = createBuild(params.getBuckConfig(), actionGraphAndResolver.getActionGraph(), actionGraphAndResolver.getResolver(), params.getCell(), params.getAndroidPlatformTargetSupplier(), new CachingBuildEngine(localCachingBuildEngineDelegate, pool.getExecutor(), pool.getExecutor(), new DefaultStepRunner(), getBuildEngineMode().orElse(cachingBuildEngineBuckConfig.getBuildEngineMode()), cachingBuildEngineBuckConfig.getBuildDepFiles(), cachingBuildEngineBuckConfig.getBuildMaxDepFileCacheEntries(), cachingBuildEngineBuckConfig.getBuildArtifactCacheSizeLimit(), params.getObjectMapper(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getResourceAwareSchedulingInfo(), new RuleKeyFactoryManager(params.getBuckConfig().getKeySeed(), fs -> localCachingBuildEngineDelegate.getFileHashCache(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getBuildInputRuleKeyFileSizeLimit(), ruleKeyCacheScope.getCache())), params.getArtifactCacheFactory().newInstance(), params.getConsole(), params.getBuckEventBus(), Optional.empty(), params.getPersistentWorkerPools(), params.getPlatform(), params.getEnvironment(), params.getObjectMapper(), params.getClock(), Optional.empty(), Optional.empty(), params.getExecutors())) {
            exitCode = build.executeAndPrintFailuresToEventBus(buildTargets, isKeepGoing(), params.getBuckEventBus(), params.getConsole(), getPathToBuildReport(params.getBuckConfig()));
        }
    }
    params.getBuckEventBus().post(BuildEvent.finished(started, exitCode));
    return exitCode;
}
Also used : BuildTargetException(com.facebook.buck.model.BuildTargetException) LocalCachingBuildEngineDelegate(com.facebook.buck.rules.LocalCachingBuildEngineDelegate) RuleKey(com.facebook.buck.rules.RuleKey) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) RuleKeyFactoryManager(com.facebook.buck.rules.keys.RuleKeyFactoryManager) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) BuildEvent(com.facebook.buck.rules.BuildEvent) BuildTarget(com.facebook.buck.model.BuildTarget) Build(com.facebook.buck.command.Build) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) RuleKeyCacheRecycler(com.facebook.buck.rules.keys.RuleKeyCacheRecycler) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) VersionException(com.facebook.buck.versions.VersionException) CachingBuildEngineBuckConfig(com.facebook.buck.rules.CachingBuildEngineBuckConfig)

Example 3 with ParserConfig

use of com.facebook.buck.parser.ParserConfig in project buck by facebook.

the class ProjectCommand method getFocusModules.

private Optional<ImmutableSet<UnflavoredBuildTarget>> getFocusModules(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException {
    if (modulesToFocusOn == null) {
        return Optional.empty();
    }
    Iterable<String> patterns = Splitter.onPattern("\\s+").split(modulesToFocusOn);
    // Parse patterns with the following syntax:
    // https://buckbuild.com/concept/build_target_pattern.html
    ImmutableList<TargetNodeSpec> specs = parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), patterns);
    // Resolve the list of targets matching the patterns.
    ImmutableSet<BuildTarget> passedInTargetsSet;
    ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
    try {
        passedInTargetsSet = params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, specs, SpeculativeParsing.of(false), parserConfig.getDefaultFlavorsMode()).stream().flatMap(Collection::stream).map(target -> target.withoutCell()).collect(MoreCollectors.toImmutableSet());
    } catch (BuildTargetException | BuildFileParseException | HumanReadableException e) {
        params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
        return Optional.empty();
    }
    LOG.debug("Selected targets: %s", passedInTargetsSet.toString());
    // Retrieve mapping: cell name -> path.
    ImmutableMap<String, Path> cellPaths = params.getCell().getCellPathResolver().getCellPaths();
    ImmutableMap<Path, String> cellNames = ImmutableBiMap.copyOf(cellPaths).inverse();
    // Create a set of unflavored targets that have cell names.
    ImmutableSet.Builder<UnflavoredBuildTarget> builder = ImmutableSet.builder();
    for (BuildTarget target : passedInTargetsSet) {
        String cell = cellNames.get(target.getCellPath());
        if (cell == null) {
            builder.add(target.getUnflavoredBuildTarget());
        } else {
            UnflavoredBuildTarget targetWithCell = UnflavoredBuildTarget.of(target.getCellPath(), Optional.of(cell), target.getBaseName(), target.getShortName());
            builder.add(targetWithCell);
        }
    }
    ImmutableSet<UnflavoredBuildTarget> passedInUnflavoredTargetsSet = builder.build();
    LOG.debug("Selected unflavored targets: %s", passedInUnflavoredTargetsSet.toString());
    return Optional.of(passedInUnflavoredTargetsSet);
}
Also used : BuildTargetException(com.facebook.buck.model.BuildTargetException) Path(java.nio.file.Path) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec)

Example 4 with ParserConfig

use of com.facebook.buck.parser.ParserConfig in project buck by facebook.

the class JavaSymbolFinder method possibleBuckFilesForSourceFile.

/**
   * Look at all the directories above a given source file, up to the project root, and return the
   * paths to any BUCK files that exist at those locations. These files are the only ones that could
   * define a rule that includes the given source file.
   */
private ImmutableList<Path> possibleBuckFilesForSourceFile(Path sourceFilePath) {
    ImmutableList.Builder<Path> possibleBuckFiles = ImmutableList.builder();
    Path dir = sourceFilePath.getParent();
    ParserConfig parserConfig = config.getView(ParserConfig.class);
    // For a source file like foo/bar/example.java, add paths like foo/bar/BUCK and foo/BUCK.
    while (dir != null) {
        Path buckFile = dir.resolve(parserConfig.getBuildFileName());
        if (projectFilesystem.isFile(buckFile)) {
            possibleBuckFiles.add(buckFile);
        }
        dir = dir.getParent();
    }
    // Finally, add ./BUCK in the root directory.
    Path rootBuckFile = Paths.get(parserConfig.getBuildFileName());
    if (projectFilesystem.exists(rootBuckFile)) {
        possibleBuckFiles.add(rootBuckFile);
    }
    return possibleBuckFiles.build();
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) ParserConfig(com.facebook.buck.parser.ParserConfig)

Example 5 with ParserConfig

use of com.facebook.buck.parser.ParserConfig in project buck by facebook.

the class Cell method createBuildFileParserFactory.

private ProjectBuildFileParserFactory createBuildFileParserFactory() {
    ParserConfig parserConfig = getBuckConfig().getView(ParserConfig.class);
    boolean useWatchmanGlob = parserConfig.getGlobHandler() == ParserConfig.GlobHandler.WATCHMAN && watchman.hasWildmatchGlob();
    boolean watchmanGlobStatResults = parserConfig.getWatchmanGlobSanityCheck() == ParserConfig.WatchmanGlobSanityCheck.STAT;
    boolean watchmanUseGlobGenerator = watchman.getCapabilities().contains(Watchman.Capability.GLOB_GENERATOR);
    boolean useMercurialGlob = parserConfig.getGlobHandler() == ParserConfig.GlobHandler.MERCURIAL;
    String pythonInterpreter = parserConfig.getPythonInterpreter(new ExecutableFinder());
    Optional<String> pythonModuleSearchPath = parserConfig.getPythonModuleSearchPath();
    return new DefaultProjectBuildFileParserFactory(ProjectBuildFileParserOptions.builder().setProjectRoot(getFilesystem().getRootPath()).setCellRoots(getCellPathResolver().getCellPaths()).setPythonInterpreter(pythonInterpreter).setPythonModuleSearchPath(pythonModuleSearchPath).setAllowEmptyGlobs(parserConfig.getAllowEmptyGlobs()).setIgnorePaths(filesystem.getIgnorePaths()).setBuildFileName(getBuildFileName()).setAutodepsFilesHaveSignatures(config.getIncludeAutodepsSignature()).setDefaultIncludes(parserConfig.getDefaultIncludes()).setDescriptions(getAllDescriptions()).setUseWatchmanGlob(useWatchmanGlob).setWatchmanGlobStatResults(watchmanGlobStatResults).setWatchmanUseGlobGenerator(watchmanUseGlobGenerator).setWatchman(watchman).setWatchmanQueryTimeoutMs(parserConfig.getWatchmanQueryTimeoutMs()).setUseMercurialGlob(useMercurialGlob).setRawConfig(getBuckConfig().getRawConfigForParser()).setBuildFileImportWhitelist(parserConfig.getBuildFileImportWhitelist()).build());
}
Also used : ExecutableFinder(com.facebook.buck.io.ExecutableFinder) DefaultProjectBuildFileParserFactory(com.facebook.buck.json.DefaultProjectBuildFileParserFactory) ParserConfig(com.facebook.buck.parser.ParserConfig)

Aggregations

ParserConfig (com.facebook.buck.parser.ParserConfig)15 BuildTarget (com.facebook.buck.model.BuildTarget)8 Path (java.nio.file.Path)6 BuildFileParseException (com.facebook.buck.json.BuildFileParseException)5 BuildTargetException (com.facebook.buck.model.BuildTargetException)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 ExecutableFinder (com.facebook.buck.io.ExecutableFinder)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 DefaultProjectBuildFileParserFactory (com.facebook.buck.json.DefaultProjectBuildFileParserFactory)4 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)4 Description (com.facebook.buck.rules.Description)4 TargetGraphAndBuildTargets (com.facebook.buck.rules.TargetGraphAndBuildTargets)4 TargetNode (com.facebook.buck.rules.TargetNode)4 DefaultTypeCoercerFactory (com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory)4 HumanReadableException (com.facebook.buck.util.HumanReadableException)4 ImmutableList (com.google.common.collect.ImmutableList)4 Build (com.facebook.buck.command.Build)3 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)3 Logger (com.facebook.buck.log.Logger)3 PythonBuckConfig (com.facebook.buck.python.PythonBuckConfig)3