Search in sources :

Example 11 with ProcessExecutor

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

the class GoAssumptions method assumeGoCompilerAvailable.

public static void assumeGoCompilerAvailable() throws InterruptedException, IOException {
    Throwable exception = null;
    try {
        ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
        FakeBuckConfig.Builder baseConfig = FakeBuckConfig.builder();
        String goRoot = System.getenv("GOROOT");
        if (goRoot != null) {
            baseConfig.setSections("[go]", "  root = " + goRoot);
            // This should really act like some kind of readonly bind-mount onto the real filesystem.
            // But this is currently enough to check whether Go seems to be installed, so we'll live...
            FakeProjectFilesystem fs = new FakeProjectFilesystem();
            fs.mkdirs(fs.getPath(goRoot));
            baseConfig.setFilesystem(fs);
        }
        new GoBuckConfig(baseConfig.build(), executor, FlavorDomain.from("Cxx", ImmutableSet.of())).getCompiler();
    } catch (HumanReadableException e) {
        exception = e;
    }
    assumeNoException(exception);
}
Also used : DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) HumanReadableException(com.facebook.buck.util.HumanReadableException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig)

Example 12 with ProcessExecutor

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

the class ObjectPathsAbsolutifierIntegrationTest method checkCodeSignatureMatchesBetweenFiles.

private boolean checkCodeSignatureMatchesBetweenFiles(Path file1, Path file2) throws IOException, InterruptedException {
    if (!Files.exists(file1)) {
        throw new NoSuchFileException(file1.toString());
    }
    if (!Files.exists(file2)) {
        throw new NoSuchFileException(file2.toString());
    }
    ProcessExecutor processExecutor = new DefaultProcessExecutor(new TestConsole());
    ProcessExecutor.Result result1 = processExecutor.launchAndExecute(ProcessExecutorParams.builder().setCommand(ImmutableList.of("codesign", "-vvvv", "-d", file1.toString())).build(), EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT, ProcessExecutor.Option.IS_SILENT), /* stdin */
    Optional.empty(), /* timeOutMs */
    Optional.empty(), /* timeOutHandler */
    Optional.empty());
    ProcessExecutor.Result result2 = processExecutor.launchAndExecute(ProcessExecutorParams.builder().setCommand(ImmutableList.of("codesign", "-vvvv", "-d", file1.toString())).build(), EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT, ProcessExecutor.Option.IS_SILENT), /* stdin */
    Optional.empty(), /* timeOutMs */
    Optional.empty(), /* timeOutHandler */
    Optional.empty());
    String stderr1 = result1.getStderr().orElse("");
    String stderr2 = result2.getStderr().orElse("");
    // skip first line as it has a path to the binary
    Assert.assertThat(stderr1, startsWith("Executable="));
    Assert.assertThat(stderr2, startsWith("Executable="));
    stderr1 = stderr1.substring(stderr1.indexOf("\n"));
    stderr2 = stderr2.substring(stderr2.indexOf("\n"));
    return stderr1.equals(stderr2);
}
Also used : DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) NoSuchFileException(java.nio.file.NoSuchFileException) Matchers.containsString(org.hamcrest.Matchers.containsString) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole)

Example 13 with ProcessExecutor

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

the class KnownBuildRuleTypesTest method whenJavacIsSetInBuckConfigConfiguredRulesCreateJavaLibraryRuleWithDifferentRuleKey.

@Test
public void whenJavacIsSetInBuckConfigConfiguredRulesCreateJavaLibraryRuleWithDifferentRuleKey() throws Exception {
    final Path javac;
    if (Platform.detect() == Platform.WINDOWS) {
        javac = Paths.get("C:/Windows/system32/rundll32.exe");
    } else {
        javac = temporaryFolder.newExecutableFile();
    }
    ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("tools", ImmutableMap.of("javac", javac.toString()));
    BuckConfig buckConfig = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(sections).build();
    KnownBuildRuleTypes buildRuleTypes = KnownBuildRuleTypesTestUtil.getDefaultKnownBuildRuleTypes(filesystem, environment);
    DefaultJavaLibrary libraryRule = createJavaLibrary(buildRuleTypes);
    ProcessExecutor processExecutor = createExecutor(javac.toString(), "fakeVersion 0.1");
    KnownBuildRuleTypes configuredBuildRuleTypes = KnownBuildRuleTypes.createBuilder(buckConfig, filesystem, processExecutor, new FakeAndroidDirectoryResolver()).build();
    DefaultJavaLibrary configuredRule = createJavaLibrary(configuredBuildRuleTypes);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(javac, MorePaths.asByteSource(javac).hash(Hashing.sha1())));
    RuleKey configuredKey = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(configuredRule);
    RuleKey libraryKey = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(libraryRule);
    assertNotEquals(libraryKey, configuredKey);
}
Also used : Path(java.nio.file.Path) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 14 with ProcessExecutor

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

the class KnownBuildRuleTypesTest method createInstanceShouldReturnDifferentInstancesIfCalledWithDifferentParameters.

@Test
public void createInstanceShouldReturnDifferentInstancesIfCalledWithDifferentParameters() throws Exception {
    ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    KnownBuildRuleTypes knownBuildRuleTypes1 = KnownBuildRuleTypes.createInstance(FakeBuckConfig.builder().build(), filesystem, createExecutor(), new FakeAndroidDirectoryResolver());
    final Path javac = temporaryFolder.newExecutableFile();
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("tools", ImmutableMap.of("javac", javac.toString()));
    BuckConfig buckConfig = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(sections).build();
    ProcessExecutor processExecutor = createExecutor(javac.toString(), "");
    KnownBuildRuleTypes knownBuildRuleTypes2 = KnownBuildRuleTypes.createInstance(buckConfig, filesystem, processExecutor, new FakeAndroidDirectoryResolver());
    assertNotEquals(knownBuildRuleTypes1, knownBuildRuleTypes2);
}
Also used : Path(java.nio.file.Path) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 15 with ProcessExecutor

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

the class TestCellBuilder method build.

public Cell build() throws IOException, InterruptedException {
    ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
    BuckConfig config = buckConfig == null ? FakeBuckConfig.builder().setFilesystem(filesystem).build() : buckConfig;
    KnownBuildRuleTypesFactory typesFactory = new KnownBuildRuleTypesFactory(executor, androidDirectoryResolver);
    if (parserFactory == null) {
        return CellProvider.createForLocalBuild(filesystem, watchman, config, cellConfig, typesFactory).getCellByPath(filesystem.getRootPath());
    }
    // The constructor for `Cell` is private, and it's in such a central location I don't really
    // want to make it public. Brace yourselves.
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(Cell.class);
    enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> {
        if ("createBuildFileParserFactory".equals(method.getName())) {
            return parserFactory;
        }
        return proxy.invokeSuper(obj, args);
    });
    return (Cell) enhancer.create();
}
Also used : MethodInterceptor(net.sf.cglib.proxy.MethodInterceptor) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) IOException(java.io.IOException) ProjectBuildFileParserFactory(com.facebook.buck.json.ProjectBuildFileParserFactory) Watchman(com.facebook.buck.io.Watchman) NULL_WATCHMAN(com.facebook.buck.io.Watchman.NULL_WATCHMAN) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuckConfig(com.facebook.buck.cli.BuckConfig) CellConfig(com.facebook.buck.config.CellConfig) TestConsole(com.facebook.buck.testutil.TestConsole) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) AndroidDirectoryResolver(com.facebook.buck.android.AndroidDirectoryResolver) Enhancer(net.sf.cglib.proxy.Enhancer) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) Nullable(javax.annotation.Nullable) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) Enhancer(net.sf.cglib.proxy.Enhancer) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole)

Aggregations

ProcessExecutor (com.facebook.buck.util.ProcessExecutor)38 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)20 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)18 TestConsole (com.facebook.buck.testutil.TestConsole)13 IOException (java.io.IOException)13 Path (java.nio.file.Path)12 Test (org.junit.Test)11 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)8 HumanReadableException (com.facebook.buck.util.HumanReadableException)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)4 Verbosity (com.facebook.buck.util.Verbosity)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)3 BuckConfig (com.facebook.buck.cli.BuckConfig)3 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStreamReader (java.io.InputStreamReader)3 PrintStream (java.io.PrintStream)3 NSDate (com.dd.plist.NSDate)2