Search in sources :

Example 96 with ExecutionContext

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;
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) Build(com.facebook.buck.command.Build) BuildTarget(com.facebook.buck.model.BuildTarget) AppleBundle(com.facebook.buck.apple.AppleBundle) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) HasInstallableApk(com.facebook.buck.android.HasInstallableApk)

Example 97 with ExecutionContext

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());
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) ShellStep(com.facebook.buck.shell.ShellStep) Console(com.facebook.buck.util.Console)

Example 98 with ExecutionContext

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);
    }
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) CapturingPrintStream(com.facebook.buck.util.CapturingPrintStream) IOException(java.io.IOException) Verbosity(com.facebook.buck.util.Verbosity)

Example 99 with ExecutionContext

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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ZipStep(com.facebook.buck.zip.ZipStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ZipStep(com.facebook.buck.zip.ZipStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ShellStep(com.facebook.buck.shell.ShellStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) RmStep(com.facebook.buck.step.fs.RmStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) ShellStep(com.facebook.buck.shell.ShellStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Example 100 with ExecutionContext

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);
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) OutputStream(java.io.OutputStream) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep)

Aggregations

ExecutionContext (com.facebook.buck.step.ExecutionContext)176 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)140 Test (org.junit.Test)128 Path (java.nio.file.Path)79 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)67 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)66 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)55 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)50 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)45 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)44 Step (com.facebook.buck.step.Step)34 ImmutableList (com.google.common.collect.ImmutableList)32 BuildTarget (com.facebook.buck.model.BuildTarget)31 SourcePath (com.facebook.buck.rules.SourcePath)26 TestConsole (com.facebook.buck.testutil.TestConsole)25 FakeProcess (com.facebook.buck.util.FakeProcess)21 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)20 ImmutableMap (com.google.common.collect.ImmutableMap)20 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)19 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)19