Search in sources :

Example 1 with Verbosity

use of com.facebook.buck.util.Verbosity in project buck by facebook.

the class DxStepTest method createExecutionContext.

private ExecutionContext createExecutionContext(int verbosityLevel) throws IOException {
    Verbosity verbosity = VerbosityParser.getVerbosityForLevel(verbosityLevel);
    TestConsole console = new TestConsole(verbosity);
    return TestExecutionContext.newBuilder().setConsole(console).setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatformTarget)).build();
}
Also used : Verbosity(com.facebook.buck.util.Verbosity) TestConsole(com.facebook.buck.testutil.TestConsole)

Example 2 with Verbosity

use of com.facebook.buck.util.Verbosity in project buck by facebook.

the class RunShTestAndRecordResultStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
    TestResultSummary summary;
    if (context.getPlatform() == Platform.WINDOWS) {
        // Ignore sh_test on Windows.
        summary = new TestResultSummary(getShortName(), "sh_test", /* type */
        ResultType.SUCCESS, /* duration*/
        0, /* message */
        "sh_test ignored on Windows", /* stacktrace */
        null, /* stdout */
        null, /* stderr */
        null);
    } else {
        ShellStep test = new ShellStep(filesystem.getRootPath()) {

            boolean timedOut = false;

            @Override
            public String getShortName() {
                return pathToShellScript.toString();
            }

            @Override
            protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
                return ImmutableList.<String>builder().add(pathToShellScript.toString()).addAll(args).build();
            }

            @Override
            public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
                return ImmutableMap.<String, String>builder().put("NO_BUCKD", "1").putAll(env).build();
            }

            @Override
            protected boolean shouldPrintStderr(Verbosity verbosity) {
                // Do not stream this output because we want to capture it.
                return false;
            }

            @Override
            public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
                StepExecutionResult executionResult = super.execute(context);
                if (timedOut) {
                    throw new HumanReadableException("Timed out running test: " + testCaseName + ", with exitCode: " + executionResult.getExitCode());
                }
                return executionResult;
            }

            @Override
            protected Optional<Consumer<Process>> getTimeoutHandler(final ExecutionContext context) {
                return Optional.of(process -> timedOut = true);
            }

            @Override
            protected Optional<Long> getTimeout() {
                return testRuleTimeoutMs;
            }

            @Override
            protected boolean shouldPrintStdout(Verbosity verbosity) {
                // Do not stream this output because we want to capture it.
                return false;
            }
        };
        StepExecutionResult executionResult = test.execute(context);
        // Write test result.
        boolean isSuccess = executionResult.isSuccess();
        summary = new TestResultSummary(getShortName(), "sh_test", /* type */
        isSuccess ? ResultType.SUCCESS : ResultType.FAILURE, test.getDuration(), /* message */
        null, /* stacktrace */
        null, test.getStdout(), test.getStderr());
    }
    ObjectMapper mapper = context.getObjectMapper();
    try (OutputStream outputStream = filesystem.newFileOutputStream(pathToTestResultFile)) {
        mapper.writeValue(outputStream, summary);
    }
    // should be zero.
    return StepExecutionResult.SUCCESS;
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) Consumer(java.util.function.Consumer) HumanReadableException(com.facebook.buck.util.HumanReadableException) OutputStream(java.io.OutputStream) TestResultSummary(com.facebook.buck.test.TestResultSummary) Verbosity(com.facebook.buck.util.Verbosity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with Verbosity

use of com.facebook.buck.util.Verbosity in project buck by facebook.

the class RustCompileRule method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext buildContext, BuildableContext buildableContext) {
    Path output = getOutput();
    buildableContext.recordArtifact(output);
    SourcePathResolver resolver = buildContext.getSourcePathResolver();
    return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir), new SymlinkFilesIntoDirectoryStep(getProjectFilesystem(), getProjectFilesystem().getRootPath(), srcs.stream().map(resolver::getRelativePath).collect(MoreCollectors.toImmutableList()), scratchDir), new MakeCleanDirectoryStep(getProjectFilesystem(), getOutputDir(getBuildTarget(), getProjectFilesystem())), new ShellStep(getProjectFilesystem().getRootPath()) {

        @Override
        protected ImmutableList<String> getShellCommandInternal(ExecutionContext executionContext) {
            ImmutableList<String> linkerCmd = linker.getCommandPrefix(resolver);
            ImmutableList.Builder<String> cmd = ImmutableList.builder();
            Path src = scratchDir.resolve(resolver.getRelativePath(rootModule));
            cmd.addAll(compiler.getCommandPrefix(resolver)).addAll(executionContext.getAnsi().isAnsiTerminal() ? ImmutableList.of("--color=always") : ImmutableList.of()).add(String.format("-Clinker=%s", linkerCmd.get(0))).addAll(processLinkerArgs(linkerCmd.subList(1, linkerCmd.size()))).addAll(processLinkerArgs(Arg.stringify(linkerArgs, buildContext.getSourcePathResolver()))).addAll(Arg.stringify(args, buildContext.getSourcePathResolver())).add("-o", output.toString()).add(src.toString());
            return cmd.build();
        }

        /*
           * Make sure all stderr output from rustc is emitted, since its either a warning or an
           * error. In general Rust code should have zero warnings, or all warnings as errors.
           * Regardless, respect requests for silence.
           */
        @Override
        protected boolean shouldPrintStderr(Verbosity verbosity) {
            return !verbosity.isSilent();
        }

        @Override
        public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
            return compiler.getEnvironment(buildContext.getSourcePathResolver());
        }

        @Override
        public String getShortName() {
            return "rust-build";
        }
    });
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) ShellStep(com.facebook.buck.shell.ShellStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Verbosity(com.facebook.buck.util.Verbosity) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SymlinkFilesIntoDirectoryStep(com.facebook.buck.shell.SymlinkFilesIntoDirectoryStep) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with Verbosity

use of com.facebook.buck.util.Verbosity 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 5 with Verbosity

use of com.facebook.buck.util.Verbosity in project buck by facebook.

the class JavacExecutionContextSerializer method deserialize.

@SuppressWarnings("unchecked")
public static JavacExecutionContext deserialize(Map<String, Object> data, JavacEventSink eventSink, PrintStream stdErr, ClassLoaderCache classLoaderCache, ObjectMapper objectMapper, Console console) {
    Verbosity verbosity = Verbosity.valueOf((String) Preconditions.checkNotNull(data.get(VERBOSITY)));
    CellPathResolver cellPathResolver = CellPathResolverSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(CELL_PATH_RESOLVER)));
    JavaPackageFinder javaPackageFinder = JavaPackageFinderSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(JAVA_PACKAGE_FINDER)));
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(Paths.get((String) Preconditions.checkNotNull(data.get(PROJECT_FILE_SYSTEM_ROOT))));
    ClassUsageFileWriter classUsageFileWriter = ClassUsageFileWriterSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(CLASS_USAGE_FILE_WRITER)));
    ProcessExecutor processExecutor = ProcessExecutorSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(PROCESS_EXECUTOR)), console);
    ImmutableList<Path> absolutePathsForInputs = ImmutableList.copyOf(((List<String>) Preconditions.checkNotNull(data.get(ABSOLUTE_PATHS_FOR_INPUTS))).stream().map(s -> Paths.get(s)).iterator());
    Optional<DirectToJarOutputSettings> directToJarOutputSettings = Optional.empty();
    if (data.containsKey(DIRECT_TO_JAR_SETTINGS)) {
        directToJarOutputSettings = Optional.of(DirectToJarOutputSettingsSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(DIRECT_TO_JAR_SETTINGS))));
    }
    return JavacExecutionContext.of(eventSink, stdErr, classLoaderCache, objectMapper, verbosity, cellPathResolver, javaPackageFinder, projectFilesystem, classUsageFileWriter, (Map<String, String>) Preconditions.checkNotNull(data.get(ENVIRONMENT), "Missing environment when deserializing JavacExectionContext"), processExecutor, absolutePathsForInputs, directToJarOutputSettings);
}
Also used : Path(java.nio.file.Path) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) CellPathResolver(com.facebook.buck.rules.CellPathResolver) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Verbosity(com.facebook.buck.util.Verbosity) ProcessExecutor(com.facebook.buck.util.ProcessExecutor)

Aggregations

Verbosity (com.facebook.buck.util.Verbosity)10 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)4 Path (java.nio.file.Path)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 HumanReadableException (com.facebook.buck.util.HumanReadableException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ImmutableList (com.google.common.collect.ImmutableList)3 DefaultCellPathResolver (com.facebook.buck.rules.DefaultCellPathResolver)2 ExecutionContext (com.facebook.buck.step.ExecutionContext)2 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2 AndroidBuckConfig (com.facebook.buck.android.AndroidBuckConfig)1 AndroidDirectoryResolver (com.facebook.buck.android.AndroidDirectoryResolver)1 AndroidPlatformTarget (com.facebook.buck.android.AndroidPlatformTarget)1 DefaultAndroidDirectoryResolver (com.facebook.buck.android.DefaultAndroidDirectoryResolver)1 NoAndroidSdkException (com.facebook.buck.android.NoAndroidSdkException)1 ArtifactCache (com.facebook.buck.artifact_cache.ArtifactCache)1