use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class InstallCommand method install.
private int install(CommandRunnerParams params) throws IOException, InterruptedException, NoSuchBuildTargetException {
Build build = super.getBuild();
int exitCode = 0;
for (BuildTarget buildTarget : getBuildTargets()) {
BuildRule buildRule = build.getRuleResolver().requireRule(buildTarget);
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(build.getRuleResolver()));
if (buildRule instanceof HasInstallableApk) {
ExecutionContext executionContext = ExecutionContext.builder().from(build.getExecutionContext()).setAdbOptions(Optional.of(adbOptions(params.getBuckConfig()))).setTargetDeviceOptions(Optional.of(targetDeviceOptions())).setExecutors(params.getExecutors()).setCellPathResolver(params.getCell().getCellPathResolver()).build();
exitCode = installApk(params, (HasInstallableApk) buildRule, executionContext, pathResolver);
if (exitCode != 0) {
return exitCode;
}
} else if (buildRule instanceof AppleBundle) {
AppleBundle appleBundle = (AppleBundle) buildRule;
InstallEvent.Started started = InstallEvent.started(appleBundle.getBuildTarget());
params.getBuckEventBus().post(started);
InstallResult installResult = installAppleBundle(params, appleBundle, appleBundle.getProjectFilesystem(), build.getExecutionContext().getProcessExecutor(), pathResolver);
params.getBuckEventBus().post(InstallEvent.finished(started, installResult.getExitCode() == 0, installResult.getLaunchedPid(), Optional.empty()));
exitCode = installResult.getExitCode();
if (exitCode != 0) {
return exitCode;
}
} else {
params.getBuckEventBus().post(ConsoleEvent.severe(String.format("Specified rule %s must be of type android_binary() or apk_genrule() or " + "apple_bundle() but was %s().\n", buildRule.getFullyQualifiedName(), buildRule.getType())));
return 1;
}
}
return exitCode;
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class Project method processJsonConfig.
private ExitCodeAndOutput processJsonConfig(File jsonTempFile, boolean generateMinimalProject) throws IOException, InterruptedException {
ImmutableList.Builder<String> argsBuilder = ImmutableList.<String>builder().add(pythonInterpreter).add(PATH_TO_INTELLIJ_PY).add(jsonTempFile.getAbsolutePath());
if (generateMinimalProject) {
argsBuilder.add("--generate_minimum_project");
}
if (turnOffAutoSourceGeneration) {
argsBuilder.add("--disable_android_auto_generation_setting");
}
final ImmutableList<String> args = argsBuilder.build();
ShellStep command = new ShellStep(projectFilesystem.getRootPath()) {
@Override
public String getShortName() {
return "python";
}
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
return args;
}
};
Console console = executionContext.getConsole();
Console childConsole = new Console(Verbosity.SILENT, console.getStdOut(), console.getStdErr(), Ansi.withoutTty());
int exitCode;
try (ExecutionContext childContext = ExecutionContext.builder().from(executionContext).setConsole(childConsole).setExecutors(executionContext.getExecutors()).build()) {
exitCode = command.execute(childContext).getExitCode();
}
return new ExitCodeAndOutput(exitCode, command.getStdout(), command.getStderr());
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class JavacStep method tryBuildWithFirstOrderDeps.
private StepExecutionResult tryBuildWithFirstOrderDeps(ExecutionContext context, ProjectFilesystem filesystem) throws InterruptedException, IOException {
try {
javacOptions.validateOptions(classpathChecker::validateClasspath);
} catch (IOException e) {
context.postEvent(ConsoleEvent.severe("Invalid Java compiler options: %s", e.getMessage()));
return StepExecutionResult.ERROR;
}
Verbosity verbosity = context.getVerbosity().isSilent() ? Verbosity.STANDARD_INFORMATION : context.getVerbosity();
try (CapturingPrintStream stdout = new CapturingPrintStream();
CapturingPrintStream stderr = new CapturingPrintStream();
ExecutionContext firstOrderContext = context.createSubContext(stdout, stderr, Optional.of(verbosity))) {
Javac javac = getJavac();
JavacExecutionContext javacExecutionContext = JavacExecutionContext.of(new JavacEventSinkToBuckEventBusBridge(firstOrderContext.getBuckEventBus()), stderr, firstOrderContext.getClassLoaderCache(), firstOrderContext.getObjectMapper(), verbosity, firstOrderContext.getCellPathResolver(), firstOrderContext.getJavaPackageFinder(), filesystem, usedClassesFileWriter, firstOrderContext.getEnvironment(), firstOrderContext.getProcessExecutor(), getAbsolutePathsForJavacInputs(javac), directToJarOutputSettings);
return performBuild(context, stdout, stderr, javac, javacExecutionContext);
}
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class Javadoc method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(output);
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
steps.add(new RmStep(getProjectFilesystem(), output));
// Fast path: nothing to do so just create an empty zip and return.
if (sources.isEmpty()) {
steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSet.<Path>of(), /* junk paths */
false, ZipCompressionLevel.MIN_COMPRESSION_LEVEL, output));
return steps.build();
}
Path sourcesListFilePath = scratchDir.resolve("all-sources.txt");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
// Write an @-file with all the source files in
steps.add(new WriteFileStep(getProjectFilesystem(), Joiner.on("\n").join(sources.stream().map(context.getSourcePathResolver()::getAbsolutePath).map(Path::toString).iterator()), sourcesListFilePath, /* can execute */
false));
Path atArgs = scratchDir.resolve("options");
// Write an @-file with the classpath
StringBuilder argsBuilder = new StringBuilder("-classpath ");
Joiner.on(File.pathSeparator).appendTo(argsBuilder, getDeps().stream().filter(HasClasspathEntries.class::isInstance).flatMap(rule -> ((HasClasspathEntries) rule).getTransitiveClasspaths().stream()).map(context.getSourcePathResolver()::getAbsolutePath).map(Object::toString).iterator());
steps.add(new WriteFileStep(getProjectFilesystem(), argsBuilder.toString(), atArgs, /* can execute */
false));
Path uncompressedOutputDir = scratchDir.resolve("docs");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), uncompressedOutputDir));
steps.add(new ShellStep(getProjectFilesystem().resolve(scratchDir)) {
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
return ImmutableList.of("javadoc", "-Xdoclint:none", "-notimestamp", "-d", uncompressedOutputDir.getFileName().toString(), "@" + getProjectFilesystem().resolve(atArgs), "@" + getProjectFilesystem().resolve(sourcesListFilePath));
}
@Override
public String getShortName() {
return "javadoc";
}
});
steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSet.of(), /* junk paths */
false, DEFAULT_COMPRESSION_LEVEL, uncompressedOutputDir));
return steps.build();
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class JavaSymbolsRule method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
Step mkdirStep = new MkdirStep(getProjectFilesystem(), outputPath.getParent());
Step extractSymbolsStep = new AbstractExecutionStep("java-symbols") {
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException {
Symbols symbols = symbolsFinder.extractSymbols();
Symbols symbolsToSerialize;
if (generatedSymbols.isEmpty()) {
symbolsToSerialize = symbols;
} else {
symbolsToSerialize = new Symbols(Iterables.concat(symbols.provided, generatedSymbols), symbols.required, symbols.exported);
}
try (OutputStream output = getProjectFilesystem().newFileOutputStream(outputPath)) {
context.getObjectMapper().writeValue(output, symbolsToSerialize);
}
return StepExecutionResult.SUCCESS;
}
};
return ImmutableList.of(mkdirStep, extractSymbolsStep);
}
Aggregations