use of com.facebook.buck.model.BuildTargetException in project buck by facebook.
the class TargetNodeParsePipeline method computeNode.
@Override
protected TargetNode<?, ?> computeNode(final Cell cell, final BuildTarget buildTarget, final Map<String, Object> rawNode) throws BuildTargetException {
try (final SimplePerfEvent.Scope scope = SimplePerfEvent.scopeIgnoringShortEvents(eventBus, PerfEventId.of("GetTargetNode"), "target", buildTarget, targetNodePipelineLifetimeEventScope, getMinimumPerfEventTimeMs(), TimeUnit.MILLISECONDS)) {
Function<PerfEventId, SimplePerfEvent.Scope> perfEventScopeFunction = perfEventId -> SimplePerfEvent.scopeIgnoringShortEvents(eventBus, perfEventId, scope, getMinimumPerfEventTimeMs(), TimeUnit.MILLISECONDS);
final TargetNode<?, ?> targetNode = delegate.createTargetNode(cell, cell.getAbsolutePathToBuildFile(buildTarget), buildTarget, rawNode, perfEventScopeFunction);
if (speculativeDepsTraversal) {
executorService.submit(() -> {
for (BuildTarget depTarget : targetNode.getDeps()) {
Path depCellPath = depTarget.getCellPath();
// non-threadsafe way making it inconvenient to access from the pipeline.
if (depCellPath.equals(cell.getRoot())) {
try {
if (depTarget.isFlavored()) {
getNodeJob(cell, BuildTarget.of(depTarget.getUnflavoredBuildTarget()));
}
getNodeJob(cell, depTarget);
} catch (BuildTargetException e) {
// No biggie, we'll hit the error again in the non-speculative path.
LOG.info(e, "Could not schedule speculative parsing for %s", depTarget);
}
}
}
});
}
return targetNode;
}
}
use of com.facebook.buck.model.BuildTargetException 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.model.BuildTargetException 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.model.BuildTargetException 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.model.BuildTargetException in project buck by facebook.
the class AuditClasspathCommand method runWithoutHelp.
@Override
public int runWithoutHelp(final CommandRunnerParams params) throws IOException, InterruptedException {
// Create a TargetGraph that is composed of the transitive closure of all of the dependent
// BuildRules for the specified BuildTargets.
final ImmutableSet<BuildTarget> targets = getArgumentsFormattedAsBuildTargets(params.getBuckConfig()).stream().map(input -> BuildTargetParser.INSTANCE.parse(input, BuildTargetPatternParser.fullyQualified(), params.getCell().getCellPathResolver())).collect(MoreCollectors.toImmutableSet());
if (targets.isEmpty()) {
params.getBuckEventBus().post(ConsoleEvent.severe("Please specify at least one build target."));
return 1;
}
TargetGraph targetGraph;
try (CommandThreadManager pool = new CommandThreadManager("Audit", getConcurrencyLimit(params.getBuckConfig()))) {
targetGraph = params.getParser().buildTargetGraph(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), targets);
} catch (BuildFileParseException | BuildTargetException e) {
params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
return 1;
}
try {
if (shouldGenerateDotOutput()) {
return printDotOutput(params, targetGraph);
} else if (shouldGenerateJsonOutput()) {
return printJsonClasspath(params, targetGraph, targets);
} else {
return printClasspath(params, targetGraph, targets);
}
} catch (NoSuchBuildTargetException | VersionException e) {
throw new HumanReadableException(e, MoreExceptions.getHumanReadableOrLocalizedMessage(e));
}
}
Aggregations