Search in sources :

Example 11 with BuildFileParseException

use of com.facebook.buck.json.BuildFileParseException in project buck by facebook.

the class InstallCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    int exitCode = checkArguments(params);
    if (exitCode != 0) {
        return exitCode;
    }
    try (CommandThreadManager pool = new CommandThreadManager("Install", getConcurrencyLimit(params.getBuckConfig()))) {
        // Get the helper targets if present
        ImmutableSet<String> installHelperTargets;
        try {
            installHelperTargets = getInstallHelperTargets(params, pool.getExecutor());
        } catch (BuildTargetException | BuildFileParseException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return 1;
        }
        // Build the targets
        exitCode = super.run(params, pool.getExecutor(), installHelperTargets);
        if (exitCode != 0) {
            return exitCode;
        }
    }
    // Install the targets
    try {
        exitCode = install(params);
    } catch (NoSuchBuildTargetException e) {
        throw new HumanReadableException(e.getHumanReadableErrorMessage());
    }
    if (exitCode != 0) {
        return exitCode;
    }
    return exitCode;
}
Also used : BuildTargetException(com.facebook.buck.model.BuildTargetException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) HumanReadableException(com.facebook.buck.util.HumanReadableException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildFileParseException(com.facebook.buck.json.BuildFileParseException)

Example 12 with BuildFileParseException

use of com.facebook.buck.json.BuildFileParseException 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 13 with BuildFileParseException

use of com.facebook.buck.json.BuildFileParseException 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 14 with BuildFileParseException

use of com.facebook.buck.json.BuildFileParseException in project buck by facebook.

the class QueryCommand method collectAndPrintAttributes.

private void collectAndPrintAttributes(CommandRunnerParams params, BuckQueryEnvironment env, Set<QueryTarget> queryResult) throws QueryException {
    PatternsMatcher patternsMatcher = new PatternsMatcher(outputAttributes.get());
    SortedMap<String, SortedMap<String, Object>> result = Maps.newTreeMap();
    for (QueryTarget target : queryResult) {
        if (!(target instanceof QueryBuildTarget)) {
            continue;
        }
        TargetNode<?, ?> node = env.getNode(target);
        try {
            SortedMap<String, Object> sortedTargetRule = params.getParser().getRawTargetNode(env.getParserState(), params.getCell(), node);
            if (sortedTargetRule == null) {
                params.getConsole().printErrorText("unable to find rule for target " + node.getBuildTarget().getFullyQualifiedName());
                continue;
            }
            SortedMap<String, Object> attributes = Maps.newTreeMap();
            if (patternsMatcher.hasPatterns()) {
                for (String key : sortedTargetRule.keySet()) {
                    String snakeCaseKey = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, key);
                    if (patternsMatcher.matches(snakeCaseKey)) {
                        attributes.put(snakeCaseKey, sortedTargetRule.get(key));
                    }
                }
            }
            result.put(node.getBuildTarget().getUnflavoredBuildTarget().getFullyQualifiedName(), attributes);
        } catch (BuildFileParseException e) {
            params.getConsole().printErrorText("unable to find rule for target " + node.getBuildTarget().getFullyQualifiedName());
            continue;
        }
    }
    StringWriter stringWriter = new StringWriter();
    try {
        params.getObjectMapper().writerWithDefaultPrettyPrinter().writeValue(stringWriter, result);
    } catch (IOException e) {
        // Shouldn't be possible while writing to a StringWriter...
        throw new RuntimeException(e);
    }
    String output = stringWriter.getBuffer().toString();
    params.getConsole().getStdOut().println(output);
}
Also used : PatternsMatcher(com.facebook.buck.util.PatternsMatcher) IOException(java.io.IOException) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) QueryTarget(com.facebook.buck.query.QueryTarget) StringWriter(java.io.StringWriter) SortedMap(java.util.SortedMap) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget)

Example 15 with BuildFileParseException

use of com.facebook.buck.json.BuildFileParseException in project buck by facebook.

the class QueryCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    if (arguments.isEmpty()) {
        params.getBuckEventBus().post(ConsoleEvent.severe("Must specify at least the query expression"));
        return 1;
    }
    try (CommandThreadManager pool = new CommandThreadManager("Query", getConcurrencyLimit(params.getBuckConfig()));
        PerBuildState parserState = new PerBuildState(params.getParser(), params.getBuckEventBus(), pool.getExecutor(), params.getCell(), getEnableParserProfiling(), SpeculativeParsing.of(true), /* ignoreBuckAutodepsFiles */
        false)) {
        BuckQueryEnvironment env = BuckQueryEnvironment.from(params, parserState, getEnableParserProfiling());
        ListeningExecutorService executor = pool.getExecutor();
        return formatAndRunQuery(params, env, executor);
    } catch (QueryException | BuildFileParseException e) {
        throw new HumanReadableException(e);
    }
}
Also used : QueryException(com.facebook.buck.query.QueryException) HumanReadableException(com.facebook.buck.util.HumanReadableException) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) PerBuildState(com.facebook.buck.parser.PerBuildState)

Aggregations

BuildFileParseException (com.facebook.buck.json.BuildFileParseException)24 BuildTarget (com.facebook.buck.model.BuildTarget)14 BuildTargetException (com.facebook.buck.model.BuildTargetException)13 Path (java.nio.file.Path)13 IOException (java.io.IOException)12 TargetNode (com.facebook.buck.rules.TargetNode)11 HumanReadableException (com.facebook.buck.util.HumanReadableException)11 ImmutableSet (com.google.common.collect.ImmutableSet)11 ImmutableList (com.google.common.collect.ImmutableList)10 Cell (com.facebook.buck.rules.Cell)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Map (java.util.Map)8 Nullable (javax.annotation.Nullable)8 TargetGraph (com.facebook.buck.rules.TargetGraph)7 Lists (com.google.common.collect.Lists)7 List (java.util.List)7 Optional (java.util.Optional)7 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)6 ParserConfig (com.facebook.buck.parser.ParserConfig)6 TargetGraphAndBuildTargets (com.facebook.buck.rules.TargetGraphAndBuildTargets)6