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;
}
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();
}
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;
}
}
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);
}
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);
}
}
Aggregations