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);
}
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);
}
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);
}
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);
}
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();
}
Aggregations