Search in sources :

Example 1 with Main

use of com.facebook.buck.cli.Main in project buck by facebook.

the class ProjectWorkspace method runBuckCommandWithEnvironmentOverridesAndContext.

public ProcessResult runBuckCommandWithEnvironmentOverridesAndContext(Path repoRoot, Optional<NGContext> context, ImmutableMap<String, String> environmentOverrides, CapturingPrintStream stderr, String... args) throws IOException {
    assertTrue("setUp() must be run before this method is invoked", isSetUp);
    CapturingPrintStream stdout = new CapturingPrintStream();
    InputStream stdin = new ByteArrayInputStream("".getBytes());
    // Construct a limited view of the parent environment for the child.
    // TODO(#5754812): we should eventually get tests working without requiring these be set.
    ImmutableList<String> inheritedEnvVars = ImmutableList.of("ANDROID_HOME", "ANDROID_NDK", "ANDROID_NDK_REPOSITORY", "ANDROID_SDK", // scripts provided by the groovy distribution in order to remove these two.
    "GROOVY_HOME", "JAVA_HOME", "NDK_HOME", "PATH", "PATHEXT", // Needed by ndk-build on Windows
    "OS", "ProgramW6432", "ProgramFiles(x86)", // The haskell integration tests call into GHC, which needs HOME to be set.
    "HOME", // TODO(#6586154): set TMP variable for ShellSteps
    "TMP");
    Map<String, String> envBuilder = new HashMap<>();
    for (String variable : inheritedEnvVars) {
        String value = System.getenv(variable);
        if (value != null) {
            envBuilder.put(variable, value);
        }
    }
    envBuilder.putAll(environmentOverrides);
    ImmutableMap<String, String> sanizitedEnv = ImmutableMap.copyOf(envBuilder);
    Main main = new Main(stdout, stderr, stdin);
    int exitCode;
    try {
        exitCode = main.runMainWithExitCode(new BuildId(), repoRoot, context, sanizitedEnv, CommandMode.TEST, WatchmanWatcher.FreshInstanceAction.NONE, System.nanoTime(), args);
    } catch (InterruptedException e) {
        e.printStackTrace(stderr);
        exitCode = Main.FAIL_EXIT_CODE;
        Thread.currentThread().interrupt();
    }
    return new ProcessResult(exitCode, stdout.getContentsAsString(Charsets.UTF_8), stderr.getContentsAsString(Charsets.UTF_8));
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CapturingPrintStream(com.facebook.buck.util.CapturingPrintStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BuildId(com.facebook.buck.model.BuildId) Main(com.facebook.buck.cli.Main)

Aggregations

Main (com.facebook.buck.cli.Main)1 BuildId (com.facebook.buck.model.BuildId)1 CapturingPrintStream (com.facebook.buck.util.CapturingPrintStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1