Search in sources :

Example 6 with ProcessExecutor

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

the class OcamlRuleBuilder method executeProcessAndGetStdout.

private static Optional<String> executeProcessAndGetStdout(Path baseDir, ImmutableList<String> cmd) throws IOException, InterruptedException {
    ImmutableSet.Builder<ProcessExecutor.Option> options = ImmutableSet.builder();
    options.add(ProcessExecutor.Option.EXPECTING_STD_OUT);
    ProcessExecutor exe = new DefaultProcessExecutor(Console.createNullConsole());
    ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(cmd).setDirectory(baseDir).build();
    ProcessExecutor.Result result = exe.launchAndExecute(params, options.build(), /* stdin */
    Optional.empty(), /* timeOutMs */
    Optional.empty(), /* timeOutHandler */
    Optional.empty());
    if (result.getExitCode() != 0) {
        throw new HumanReadableException(result.getStderr().get());
    }
    return result.getStdout();
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ImmutableSet(com.google.common.collect.ImmutableSet) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) HumanReadableException(com.facebook.buck.util.HumanReadableException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor)

Example 7 with ProcessExecutor

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

the class CodeSignIdentityStoreTest method testCodeSignIdentitiesCommandOverride.

@Test
public void testCodeSignIdentitiesCommandOverride() throws Exception {
    ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
    Path testdataDir = TestDataHelper.getTestDataDirectory(this).resolve("code_sign_identity_store");
    CodeSignIdentityStore store = CodeSignIdentityStore.fromSystem(executor, ImmutableList.of(testdataDir.resolve("fake_identities.sh").toString()));
    ImmutableList<CodeSignIdentity> expected = ImmutableList.of(CodeSignIdentity.builder().setFingerprint(CodeSignIdentity.toFingerprint("0000000000000000000000000000000000000000")).setSubjectCommonName("iPhone Developer: Fake").build());
    assertThat(store.getIdentities(), is(equalTo(expected)));
}
Also used : Path(java.nio.file.Path) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 8 with ProcessExecutor

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

the class ProvisioningProfileMetadataTest method testParseProvisioningProfileFile.

@Test
public void testParseProvisioningProfileFile() throws Exception {
    assumeTrue(Platform.detect() == Platform.MACOS);
    ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
    Path testdataDir = TestDataHelper.getTestDataDirectory(this).resolve("provisioning_profiles");
    Path testFile = testdataDir.resolve("sample.mobileprovision");
    ProvisioningProfileMetadata data = ProvisioningProfileMetadata.fromProvisioningProfilePath(executor, ProvisioningProfileStore.DEFAULT_READ_COMMAND, testFile);
    assertThat(data.getExpirationDate(), is(equalTo(new NSDate("9999-03-05T01:33:40Z").getDate())));
    assertThat(data.getAppID(), is(equalTo(new Pair<>("ABCDE12345", "com.example.TestApp"))));
    assertThat(data.getUUID(), is(equalTo("00000000-0000-0000-0000-000000000000")));
    assertThat(data.getProfilePath(), is(equalTo(testFile)));
    assertThat(data.getDeveloperCertificateFingerprints(), equalTo(ImmutableSet.of(HashCode.fromString("be16fc419bfb6b59a86bc08755ba0f332ec574fb"))));
    // Test old-style provisioning profile without "Platforms" field
    data = ProvisioningProfileMetadata.fromProvisioningProfilePath(executor, ProvisioningProfileStore.DEFAULT_READ_COMMAND, testdataDir.resolve("sample_without_platforms.mobileprovision"));
    assertThat(data.getDeveloperCertificateFingerprints(), equalTo(ImmutableSet.of(HashCode.fromString("be16fc419bfb6b59a86bc08755ba0f332ec574fb"))));
    thrown.expect(IOException.class);
    ProvisioningProfileMetadata.fromProvisioningProfilePath(executor, ProvisioningProfileStore.DEFAULT_READ_COMMAND, testdataDir.resolve("invalid.mobileprovision"));
}
Also used : Path(java.nio.file.Path) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) NSDate(com.dd.plist.NSDate) Test(org.junit.Test)

Example 9 with ProcessExecutor

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

the class ProvisioningProfileMetadataTest method testFilteredEntitlementsStripOut.

@Test
public void testFilteredEntitlementsStripOut() throws Exception {
    assumeTrue(Platform.detect() == Platform.MACOS);
    ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
    Path testdataDir = TestDataHelper.getTestDataDirectory(this).resolve("provisioning_profiles");
    Path testFile = testdataDir.resolve("sample.mobileprovision");
    ProvisioningProfileMetadata data = ProvisioningProfileMetadata.fromProvisioningProfilePath(executor, ProvisioningProfileStore.DEFAULT_READ_COMMAND, testFile);
    assertTrue(data.getEntitlements().containsKey("com.apple.developer.icloud-container-development-container-identifiers"));
    assertFalse(data.getMergeableEntitlements().containsKey("com.apple.developer.icloud-container-development-container-identifiers"));
}
Also used : Path(java.nio.file.Path) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 10 with ProcessExecutor

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

the class InstallCommandIntegrationTest method appleBundleInstallsAndRunsInIphoneSimulatorWithDwarfDebugging.

@Test
public void appleBundleInstallsAndRunsInIphoneSimulatorWithDwarfDebugging() throws IOException, InterruptedException {
    assumeThat(Platform.detect(), is(Platform.MACOS));
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "apple_app_bundle", tmp);
    workspace.setUp();
    workspace.enableDirCache();
    // build locally
    ProcessResult result = workspace.runBuckCommand("install", "--config", "apple.default_debug_info_format_for_binaries=DWARF", "--config", "apple.default_debug_info_format_for_libraries=DWARF", "--config", "apple.default_debug_info_format_for_tests=DWARF", "-r", "//:DemoApp");
    assumeFalse(result.getStderr().contains("no appropriate simulator found"));
    result.assertSuccess();
    // find port to connect lldb to
    // "lldb -p 12345"
    Pattern p = Pattern.compile("lldb -p \\d{1,6}");
    Matcher matcher = p.matcher(result.getStderr());
    assertThat(matcher.find(), equalTo(true));
    String[] lldbCommand = matcher.group().split(" ");
    ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
    // run lldb session
    ProcessExecutor.Result lldbResult = executor.launchAndExecute(ProcessExecutorParams.builder().addCommand(lldbCommand).build(), ImmutableSet.of(), Optional.of("b application:didFinishLaunchingWithOptions:\nb\nexit\nY\n"), Optional.empty(), Optional.empty());
    assertThat(lldbResult.getExitCode(), equalTo(0));
    // check that lldb resolved breakpoint locations
    String lldbOutput = lldbResult.getStdout().orElse("");
    assertThat(lldbOutput, containsString("Current breakpoints:"));
    assertThat(lldbOutput, containsString("name = 'application:didFinishLaunchingWithOptions:', " + "locations = 1, resolved = 1, hit count = 0"));
    // clean buck out
    workspace.runBuckCommand("clean");
    // build again - get everything from cache now
    result = workspace.runBuckCommand("install", "--config", "apple.default_debug_info_format_for_binaries=DWARF", "--config", "apple.default_debug_info_format_for_libraries=DWARF", "--config", "apple.default_debug_info_format_for_tests=DWARF", "-r", "//:DemoApp");
    result.assertSuccess();
    matcher = p.matcher(result.getStderr());
    assertThat(matcher.find(), equalTo(true));
    String[] lldbCommand2 = matcher.group().split(" ");
    // run lldb session again - now on top of files fetched from cache
    lldbResult = executor.launchAndExecute(ProcessExecutorParams.builder().addCommand(lldbCommand2).build(), ImmutableSet.of(), Optional.of("b application:didFinishLaunchingWithOptions:\nb\nexit\nY\n"), Optional.empty(), Optional.empty());
    assertThat(lldbResult.getExitCode(), equalTo(0));
    // check that lldb resolved breakpoint locations with files from cache
    lldbOutput = lldbResult.getStdout().orElse("");
    assertThat(lldbOutput, containsString("Current breakpoints:"));
    assertThat(lldbOutput, containsString("name = 'application:didFinishLaunchingWithOptions:', " + "locations = 1, resolved = 1, hit count = 0"));
}
Also used : Pattern(java.util.regex.Pattern) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) Matcher(java.util.regex.Matcher) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Matchers.containsString(org.hamcrest.Matchers.containsString) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

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