Search in sources :

Example 6 with ParserConfig

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

the class JavaSymbolFinderIntegrationTest method shouldFindTargetDefiningSymbol.

@Test
public void shouldFindTargetDefiningSymbol() throws IOException, InterruptedException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "symbol_finder", temporaryFolder);
    workspace.setUp();
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    ImmutableMap<String, String> environment = ImmutableMap.copyOf(System.getenv());
    Config rawConfig = Configs.createDefaultConfig(projectFilesystem.getRootPath());
    BuckConfig config = new BuckConfig(rawConfig, projectFilesystem, Architecture.detect(), Platform.detect(), environment, new DefaultCellPathResolver(projectFilesystem.getRootPath(), rawConfig));
    ParserConfig parserConfig = config.getView(ParserConfig.class);
    PythonBuckConfig pythonBuckConfig = new PythonBuckConfig(config, new ExecutableFinder());
    ImmutableSet<Description<?>> allDescriptions = KnownBuildRuleTypesTestUtil.getDefaultKnownBuildRuleTypes(projectFilesystem, environment).getAllDescriptions();
    SrcRootsFinder srcRootsFinder = new SrcRootsFinder(projectFilesystem);
    ProjectBuildFileParserFactory projectBuildFileParserFactory = new DefaultProjectBuildFileParserFactory(ProjectBuildFileParserOptions.builder().setProjectRoot(projectFilesystem.getRootPath()).setPythonInterpreter(pythonBuckConfig.getPythonInterpreter()).setAllowEmptyGlobs(parserConfig.getAllowEmptyGlobs()).setIgnorePaths(projectFilesystem.getIgnorePaths()).setBuildFileName(parserConfig.getBuildFileName()).setDefaultIncludes(parserConfig.getDefaultIncludes()).setDescriptions(allDescriptions).setBuildFileImportWhitelist(parserConfig.getBuildFileImportWhitelist()).build());
    BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
    JavaSymbolFinder finder = new JavaSymbolFinder(projectFilesystem, srcRootsFinder, DEFAULT_JAVAC_OPTIONS, new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())), projectBuildFileParserFactory, config, buckEventBus, new TestConsole(), environment);
    SetMultimap<String, BuildTarget> foundTargets = finder.findTargetsForSymbols(ImmutableSet.of("com.example.a.A"));
    assertEquals("JavaSymbolFinder failed to find the right target.", ImmutableSetMultimap.of("com.example.a.A", BuildTargetFactory.newInstance(projectFilesystem, "//java/com/example/a:a")), foundTargets);
}
Also used : PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) BuckEventBus(com.facebook.buck.event.BuckEventBus) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) Description(com.facebook.buck.rules.Description) Config(com.facebook.buck.config.Config) BuckConfig(com.facebook.buck.cli.BuckConfig) ParserConfig(com.facebook.buck.parser.ParserConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) DefaultProjectBuildFileParserFactory(com.facebook.buck.json.DefaultProjectBuildFileParserFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ProjectBuildFileParserFactory(com.facebook.buck.json.ProjectBuildFileParserFactory) DefaultProjectBuildFileParserFactory(com.facebook.buck.json.DefaultProjectBuildFileParserFactory) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckConfig(com.facebook.buck.cli.BuckConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) ParserConfig(com.facebook.buck.parser.ParserConfig) Test(org.junit.Test)

Example 7 with ParserConfig

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

the class InstallCommand method getInstallHelperTargets.

private ImmutableSet<String> getInstallHelperTargets(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException, BuildTargetException, BuildFileParseException {
    ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
    ImmutableSet.Builder<String> installHelperTargets = ImmutableSet.builder();
    for (int index = 0; index < getArguments().size(); index++) {
        // TODO(ryu2): Cache argument parsing
        TargetNodeSpec spec = parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()).get(index);
        BuildTarget target = FluentIterable.from(params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, ImmutableList.of(spec), SpeculativeParsing.of(false), parserConfig.getDefaultFlavorsMode())).transformAndConcat(Functions.identity()).first().get();
        TargetNode<?, ?> node = params.getParser().getTargetNode(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, target);
        if (node != null && Description.getBuildRuleType(node.getDescription()).equals(Description.getBuildRuleType(AppleBundleDescription.class))) {
            for (Flavor flavor : node.getBuildTarget().getFlavors()) {
                if (ApplePlatform.needsInstallHelper(flavor.getName())) {
                    AppleConfig appleConfig = new AppleConfig(params.getBuckConfig());
                    Optional<BuildTarget> deviceHelperTarget = appleConfig.getAppleDeviceHelperTarget();
                    Optionals.addIfPresent(Optionals.bind(deviceHelperTarget, input -> !input.toString().isEmpty() ? Optional.of(input.toString()) : Optional.empty()), installHelperTargets);
                }
            }
        }
    }
    return installHelperTargets.build();
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) AppleSimulatorDiscovery(com.facebook.buck.apple.simulator.AppleSimulatorDiscovery) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AdbOptions(com.facebook.buck.step.AdbOptions) AdbHelper(com.facebook.buck.android.AdbHelper) InstallEvent(com.facebook.buck.event.InstallEvent) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AppleConfig(com.facebook.buck.apple.AppleConfig) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FluentIterable(com.google.common.collect.FluentIterable) ApplePlatform(com.facebook.buck.apple.ApplePlatform) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Locale(java.util.Locale) AppleCoreSimulatorServiceController(com.facebook.buck.apple.simulator.AppleCoreSimulatorServiceController) Path(java.nio.file.Path) Optionals(com.facebook.buck.util.Optionals) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AppleSimulator(com.facebook.buck.apple.simulator.AppleSimulator) BuildTargetException(com.facebook.buck.model.BuildTargetException) Option(org.kohsuke.args4j.Option) AppleInfoPlistParsing(com.facebook.buck.apple.AppleInfoPlistParsing) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) List(java.util.List) AppleBundleDescription(com.facebook.buck.apple.AppleBundleDescription) AppleSimulatorController(com.facebook.buck.apple.simulator.AppleSimulatorController) UninstallOptions(com.facebook.buck.cli.UninstallCommand.UninstallOptions) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Description(com.facebook.buck.rules.Description) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Assertions(com.facebook.infer.annotation.Assertions) Build(com.facebook.buck.command.Build) MoreExceptions(com.facebook.buck.util.MoreExceptions) SourcePath(com.facebook.buck.rules.SourcePath) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) Lists(com.google.common.collect.Lists) AppleDeviceHelper(com.facebook.buck.apple.device.AppleDeviceHelper) ParserConfig(com.facebook.buck.parser.ParserConfig) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Nullable(javax.annotation.Nullable) Logger(com.facebook.buck.log.Logger) Functions(com.google.common.base.Functions) UnixUserIdFetcher(com.facebook.buck.util.UnixUserIdFetcher) TargetNode(com.facebook.buck.rules.TargetNode) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) AppleBundle(com.facebook.buck.apple.AppleBundle) HasInstallableApk(com.facebook.buck.android.HasInstallableApk) SpeculativeParsing(com.facebook.buck.parser.SpeculativeParsing) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InputStream(java.io.InputStream) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) Flavor(com.facebook.buck.model.Flavor) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec)

Example 8 with ParserConfig

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

the class ProjectCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    int rc = runPreprocessScriptIfNeeded(params);
    if (rc != 0) {
        return rc;
    }
    Ide projectIde = getIdeFromBuckConfig(params.getBuckConfig()).orElse(null);
    boolean needsFullRecursiveParse = deprecatedIntelliJProjectGenerationEnabled && projectIde != Ide.XCODE;
    try (CommandThreadManager pool = new CommandThreadManager("Project", getConcurrencyLimit(params.getBuckConfig()))) {
        ImmutableSet<BuildTarget> passedInTargetsSet;
        TargetGraph projectGraph;
        List<String> targets = getArguments();
        if (projectIde != Ide.XCODE && !deprecatedIntelliJProjectGenerationEnabled && targets.isEmpty()) {
            targets = ImmutableList.of("//...");
        }
        try {
            ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
            passedInTargetsSet = ImmutableSet.copyOf(Iterables.concat(params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), targets), SpeculativeParsing.of(true), parserConfig.getDefaultFlavorsMode())));
            needsFullRecursiveParse = needsFullRecursiveParse || passedInTargetsSet.isEmpty();
            projectGraph = getProjectGraphForIde(params, pool.getExecutor(), passedInTargetsSet, needsFullRecursiveParse);
        } catch (BuildTargetException | BuildFileParseException | HumanReadableException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return 1;
        }
        projectIde = getIdeBasedOnPassedInTargetsAndProjectGraph(params.getBuckConfig(), passedInTargetsSet, Optional.of(projectGraph));
        if (projectIde == ProjectCommand.Ide.XCODE) {
            checkForAndKillXcodeIfRunning(params, getIdePrompt(params.getBuckConfig()));
        }
        ProjectPredicates projectPredicates = ProjectPredicates.forIde(projectIde);
        ImmutableSet<BuildTarget> graphRoots;
        if (passedInTargetsSet.isEmpty()) {
            graphRoots = getRootsFromPredicate(projectGraph, projectPredicates.getProjectRootsPredicate());
        } else if (projectIde == Ide.INTELLIJ && needsFullRecursiveParse) {
            ImmutableSet<BuildTarget> supplementalGraphRoots = getRootBuildTargetsForIntelliJ(Ide.INTELLIJ, projectGraph, projectPredicates);
            graphRoots = Sets.union(passedInTargetsSet, supplementalGraphRoots).immutableCopy();
        } else {
            graphRoots = passedInTargetsSet;
        }
        TargetGraphAndTargets targetGraphAndTargets;
        try {
            targetGraphAndTargets = createTargetGraph(params, projectGraph, graphRoots, projectPredicates.getAssociatedProjectPredicate(), isWithTests(params.getBuckConfig()), isWithDependenciesTests(params.getBuckConfig()), needsFullRecursiveParse, pool.getExecutor());
        } catch (BuildFileParseException | TargetGraph.NoSuchNodeException | BuildTargetException | HumanReadableException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return 1;
        }
        if (getDryRun()) {
            for (TargetNode<?, ?> targetNode : targetGraphAndTargets.getTargetGraph().getNodes()) {
                params.getConsole().getStdOut().println(targetNode.toString());
            }
            return 0;
        }
        params.getBuckEventBus().post(ProjectGenerationEvent.started());
        int result;
        try {
            switch(projectIde) {
                case INTELLIJ:
                    result = runIntellijProjectGenerator(params, projectGraph, targetGraphAndTargets, passedInTargetsSet);
                    break;
                case XCODE:
                    result = runXcodeProjectGenerator(params, pool.getExecutor(), targetGraphAndTargets, passedInTargetsSet);
                    break;
                default:
                    // unreachable
                    throw new IllegalStateException("'ide' should always be of type 'INTELLIJ' or 'XCODE'");
            }
        } finally {
            params.getBuckEventBus().post(ProjectGenerationEvent.finished());
        }
        return result;
    }
}
Also used : BuildTargetException(com.facebook.buck.model.BuildTargetException) TargetGraphAndTargets(com.facebook.buck.rules.TargetGraphAndTargets) TargetGraph(com.facebook.buck.rules.TargetGraph) 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)

Example 9 with ParserConfig

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

the class TargetsCommand method getMatchingNodes.

private SortedMap<String, TargetNode<?, ?>> getMatchingNodes(CommandRunnerParams params, TargetGraphAndBuildTargets targetGraphAndBuildTargets, Optional<ImmutableSet<Class<? extends Description<?>>>> descriptionClasses) throws IOException {
    PathArguments.ReferencedFiles referencedFiles = getReferencedFiles(params.getCell().getFilesystem().getRootPath());
    SortedMap<String, TargetNode<?, ?>> matchingNodes;
    // If all of the referenced files are paths outside the project root, then print nothing.
    if (!referencedFiles.absolutePathsOutsideProjectRootOrNonExistingPaths.isEmpty() && referencedFiles.relativePathsUnderProjectRoot.isEmpty()) {
        matchingNodes = ImmutableSortedMap.of();
    } else {
        ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
        ImmutableSet<BuildTarget> matchingBuildTargets = targetGraphAndBuildTargets.getBuildTargets();
        matchingNodes = getMatchingNodes(targetGraphAndBuildTargets.getTargetGraph(), referencedFiles.relativePathsUnderProjectRoot.isEmpty() ? Optional.empty() : Optional.of(referencedFiles.relativePathsUnderProjectRoot), matchingBuildTargets.isEmpty() ? Optional.empty() : Optional.of(matchingBuildTargets), descriptionClasses.get().isEmpty() ? Optional.empty() : descriptionClasses, isDetectTestChanges(), parserConfig.getBuildFileName());
    }
    return matchingNodes;
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) ParserConfig(com.facebook.buck.parser.ParserConfig)

Example 10 with ParserConfig

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

the class TargetsCommand method buildTargetGraphAndTargetsForShowRules.

private TargetGraphAndBuildTargets buildTargetGraphAndTargetsForShowRules(CommandRunnerParams params, ListeningExecutorService executor, Optional<ImmutableSet<Class<? extends Description<?>>>> descriptionClasses) throws InterruptedException, BuildFileParseException, BuildTargetException, IOException {
    if (getArguments().isEmpty()) {
        ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
        TargetGraphAndBuildTargets completeTargetGraphAndBuildTargets = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, ImmutableList.of(TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get(""), params.getCell().getRoot()))), false, parserConfig.getDefaultFlavorsMode());
        SortedMap<String, TargetNode<?, ?>> matchingNodes = getMatchingNodes(params, completeTargetGraphAndBuildTargets, descriptionClasses);
        Iterable<BuildTarget> buildTargets = FluentIterable.from(matchingNodes.values()).transform(TargetNode::getBuildTarget);
        return TargetGraphAndBuildTargets.builder().setTargetGraph(completeTargetGraphAndBuildTargets.getTargetGraph()).setBuildTargets(buildTargets).build();
    } else {
        return params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()), false);
    }
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets)

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