use of com.facebook.buck.parser.NoSuchBuildTargetException 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.parser.NoSuchBuildTargetException in project buck by facebook.
the class PublishCommand method publishTargets.
private boolean publishTargets(ImmutableList<BuildTarget> buildTargets, CommandRunnerParams params) {
ImmutableSet.Builder<MavenPublishable> publishables = ImmutableSet.builder();
boolean success = true;
for (BuildTarget buildTarget : buildTargets) {
BuildRule buildRule = null;
try {
buildRule = getBuild().getRuleResolver().requireRule(buildTarget);
} catch (NoSuchBuildTargetException e) {
// This doesn't seem physically possible!
throw new RuntimeException(e);
}
Preconditions.checkNotNull(buildRule);
if (!(buildRule instanceof MavenPublishable)) {
params.getBuckEventBus().post(ConsoleEvent.severe("Cannot publish rule of type %s", buildRule.getClass().getName()));
success &= false;
continue;
}
MavenPublishable publishable = (MavenPublishable) buildRule;
if (!publishable.getMavenCoords().isPresent()) {
params.getBuckEventBus().post(ConsoleEvent.severe("No maven coordinates specified for %s", buildTarget.getUnflavoredBuildTarget().getFullyQualifiedName()));
success &= false;
continue;
}
publishables.add(publishable);
}
Publisher publisher = new Publisher(params.getCell().getFilesystem(), Optional.ofNullable(remoteRepo), Optional.ofNullable(username), Optional.ofNullable(password), dryRun);
try {
ImmutableSet<DeployResult> deployResults = publisher.publish(new SourcePathResolver(new SourcePathRuleFinder(getBuild().getRuleResolver())), publishables.build());
for (DeployResult deployResult : deployResults) {
printArtifactsInformation(params, deployResult);
}
} catch (DeploymentException e) {
params.getConsole().printBuildFailureWithoutStacktraceDontUnwrap(e);
return false;
}
return success;
}
use of com.facebook.buck.parser.NoSuchBuildTargetException in project buck by facebook.
the class RunCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
if (!hasTargetSpecified()) {
params.getBuckEventBus().post(ConsoleEvent.severe("No target given to run"));
params.getBuckEventBus().post(ConsoleEvent.severe("buck run <target> <arg1> <arg2>..."));
return 1;
}
// Make sure the target is built.
BuildCommand buildCommand = new BuildCommand(ImmutableList.of(getTarget(params.getBuckConfig())));
int exitCode = buildCommand.runWithoutHelp(params);
if (exitCode != 0) {
return exitCode;
}
String targetName = getTarget(params.getBuckConfig());
BuildTarget target = Iterables.getOnlyElement(getBuildTargets(params.getCell().getCellPathResolver(), ImmutableSet.of(targetName)));
Build build = buildCommand.getBuild();
BuildRule targetRule;
try {
targetRule = build.getRuleResolver().requireRule(target);
} catch (NoSuchBuildTargetException e) {
throw new HumanReadableException(e.getHumanReadableErrorMessage());
}
BinaryBuildRule binaryBuildRule = null;
if (targetRule instanceof BinaryBuildRule) {
binaryBuildRule = (BinaryBuildRule) targetRule;
}
if (binaryBuildRule == null) {
params.getBuckEventBus().post(ConsoleEvent.severe("target " + targetName + " is not a binary rule (only binary rules can be `run`)"));
return 1;
}
// Ideally, we would take fullCommand, disconnect from NailGun, and run the command in the
// user's shell. Currently, if you use `buck run` with buckd and ctrl-C to kill the command
// being run, occasionally I get the following error when I try to run `buck run` again:
//
// Daemon is busy, please wait or run "buck kill" to terminate it.
//
// Clearly something bad has happened here. If you are using `buck run` to start up a server
// or some other process that is meant to "run forever," then it's pretty common to do:
// `buck run`, test server, hit ctrl-C, edit server code, repeat. This should not wedge buckd.
SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(build.getRuleResolver()));
Tool executable = binaryBuildRule.getExecutableCommand();
ListeningProcessExecutor processExecutor = new ListeningProcessExecutor();
ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().addAllCommand(executable.getCommandPrefix(resolver)).addAllCommand(getTargetArguments()).setEnvironment(ImmutableMap.<String, String>builder().putAll(params.getEnvironment()).putAll(executable.getEnvironment(resolver)).build()).setDirectory(params.getCell().getFilesystem().getRootPath()).build();
ForwardingProcessListener processListener = new ForwardingProcessListener(Channels.newChannel(params.getConsole().getStdOut()), Channels.newChannel(params.getConsole().getStdErr()));
ListeningProcessExecutor.LaunchedProcess process = processExecutor.launchProcess(processExecutorParams, processListener);
try {
return processExecutor.waitForProcess(process);
} finally {
processExecutor.destroyProcess(process, /* force */
false);
processExecutor.waitForProcess(process);
}
}
use of com.facebook.buck.parser.NoSuchBuildTargetException 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));
}
}
use of com.facebook.buck.parser.NoSuchBuildTargetException in project buck by facebook.
the class KotlinLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
BuildTarget target = params.getBuildTarget();
// creating the action graph from the target graph.
if (CalculateAbi.isAbiTarget(target)) {
BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
BuildRule libraryRule = resolver.requireRule(libraryTarget);
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
}
ImmutableSortedSet<Flavor> flavors = target.getFlavors();
BuildRuleParams paramsWithMavenFlavor = null;
if (flavors.contains(JavaLibrary.MAVEN_JAR)) {
paramsWithMavenFlavor = params;
// Maven rules will depend upon their vanilla versions, so the latter have to be constructed
// without the maven flavor to prevent output-path conflict
params = params.withoutFlavor(JavaLibrary.MAVEN_JAR);
}
if (flavors.contains(JavaLibrary.SRC_JAR)) {
args.mavenCoords = args.mavenCoords.map(input -> AetherUtil.addClassifier(input, AetherUtil.CLASSIFIER_SOURCES));
if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
return new JavaSourceJar(params, args.srcs, args.mavenCoords);
} else {
return MavenUberJar.SourceJar.create(Preconditions.checkNotNull(paramsWithMavenFlavor), args.srcs, args.mavenCoords, args.mavenPomTemplate);
}
}
JavacOptions javacOptions = JavacOptionsFactory.create(defaultOptions, params, resolver, ruleFinder, args);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), exportedDeps, resolver.getAllRules(args.providedDeps))), ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))));
DefaultKotlinLibrary defaultKotlinLibrary = new DefaultKotlinLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), Optional.empty(), Optional.empty(), ImmutableList.of(), exportedDeps, resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), false, ImmutableSet.of(), new KotlincToJarStepFactory(kotlinBuckConfig.getKotlinCompiler().get(), args.extraKotlincArguments), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, args.removeClasses);
if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
return defaultKotlinLibrary;
} else {
return MavenUberJar.create(defaultKotlinLibrary, Preconditions.checkNotNull(paramsWithMavenFlavor), args.mavenCoords, args.mavenPomTemplate);
}
}
Aggregations