Search in sources :

Example 6 with PBXBuildPhase

use of com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase in project buck by facebook.

the class ProjectGeneratorTest method testAggregateTargetForBundleForBuildWithBuck.

@Test
public void testAggregateTargetForBundleForBuildWithBuck() throws IOException {
    BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "binary").build();
    TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).build();
    BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "bundle").build();
    TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(binaryTarget).build();
    ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(bundleNode, binaryNode);
    final TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
    final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
    ProjectGenerator projectGenerator = new ProjectGenerator(targetGraph, cache, nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(), Optional.of(bundleTarget), ImmutableList.of("--flag", "value with spaces"), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
    projectGenerator.createXcodeProjects();
    PBXTarget buildWithBuckTarget = null;
    for (PBXTarget target : projectGenerator.getGeneratedProject().getTargets()) {
        if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
            buildWithBuckTarget = target;
        }
    }
    assertThat(buildWithBuckTarget, is(notNullValue()));
    assertHasConfigurations(buildWithBuckTarget, "Debug");
    assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), buildWithBuckTarget);
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    assertEquals("Should have exact number of build phases", 2, buildWithBuckTarget.getBuildPhases().size());
    PBXBuildPhase buildPhase = Iterables.get(buildWithBuckTarget.getBuildPhases(), 0);
    assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
    PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("-- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + bundleTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
    Path fixUUIDScriptPath = ProjectGenerator.getFixUUIDScriptPath(filesystem);
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("python " + fixUUIDScriptPath + " --verbose " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app") + " " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.dSYM") + " " + bundleTarget.getShortName()));
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("machoutils absolutify_object_paths --binary $BUCK_BUNDLE_OUTPUT_PATH/bundle " + "--output " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app/bundle") + " --old_compdir " + "\"./////////////////////"));
    // skipping some slashes: ".//////////// ..... ///////"
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("////////\" --new_compdir \"" + filesystem.getRootPath().toString() + "\""));
    PBXBuildPhase codesignPhase = buildWithBuckTarget.getBuildPhases().get(1);
    assertThat(codesignPhase, instanceOf(PBXShellScriptBuildPhase.class));
    PBXShellScriptBuildPhase codesignShellScriptPhase = (PBXShellScriptBuildPhase) codesignPhase;
    Path codesignScriptPath = ProjectGenerator.getCodesignScriptPath(filesystem);
    assertThat(codesignShellScriptPhase.getShellScript(), containsString("python " + codesignScriptPath + " /usr/bin/codesign " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app")));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) AppleDependenciesCache(com.facebook.buck.apple.AppleDependenciesCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 7 with PBXBuildPhase

use of com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase in project buck by facebook.

the class ProjectGeneratorTestUtils method assertHasSingletonPhaseWithEntries.

public static <T extends PBXBuildPhase> void assertHasSingletonPhaseWithEntries(PBXTarget target, final Class<T> cls, ImmutableList<String> entries) {
    PBXBuildPhase buildPhase = getSingletonPhaseByType(target, cls);
    assertThat("Phase should have right number of entries", buildPhase.getFiles(), hasSize(entries.size()));
    for (PBXBuildFile file : buildPhase.getFiles()) {
        PBXReference.SourceTree sourceTree = file.getFileRef().getSourceTree();
        switch(sourceTree) {
            case GROUP:
                fail("Should not emit entries with sourceTree <group>");
                break;
            case ABSOLUTE:
                fail("Should not emit entries with sourceTree <absolute>");
                break;
            // $CASES-OMITTED$
            default:
                String serialized = "$" + sourceTree + "/" + file.getFileRef().getPath();
                assertThat("Source tree prefixed file references should exist in list of expected entries.", entries, hasItem(serialized));
                break;
        }
    }
}
Also used : PBXReference(com.facebook.buck.apple.xcode.xcodeproj.PBXReference) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase)

Example 8 with PBXBuildPhase

use of com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase in project buck by facebook.

the class NewNativeTargetProjectMutatorTest method testCopyFilesBuildPhase.

@Test
public void testCopyFilesBuildPhase() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    CopyFilePhaseDestinationSpec.Builder specBuilder = CopyFilePhaseDestinationSpec.builder();
    specBuilder.setDestination(PBXCopyFilesBuildPhase.Destination.FRAMEWORKS);
    specBuilder.setPath("foo.png");
    PBXBuildPhase copyPhase = new PBXCopyFilesBuildPhase(specBuilder.build());
    mutator.setCopyFilesPhases(ImmutableList.of(copyPhase));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    PBXBuildPhase buildPhaseToTest = getSingletonPhaseByType(result.target, PBXCopyFilesBuildPhase.class);
    assertThat(copyPhase, equalTo(buildPhaseToTest));
}
Also used : CopyFilePhaseDestinationSpec(com.facebook.buck.apple.xcode.xcodeproj.CopyFilePhaseDestinationSpec) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) PBXCopyFilesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXCopyFilesBuildPhase) Test(org.junit.Test)

Example 9 with PBXBuildPhase

use of com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase in project buck by facebook.

the class NewNativeTargetProjectMutatorTest method testCopyFilesBuildPhaseIsBeforePostBuildScriptBuildPhase.

@Test
public void testCopyFilesBuildPhaseIsBeforePostBuildScriptBuildPhase() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    CopyFilePhaseDestinationSpec.Builder specBuilder = CopyFilePhaseDestinationSpec.builder();
    specBuilder.setDestination(PBXCopyFilesBuildPhase.Destination.FRAMEWORKS);
    specBuilder.setPath("script/input.png");
    PBXBuildPhase copyFilesPhase = new PBXCopyFilesBuildPhase(specBuilder.build());
    mutator.setCopyFilesPhases(ImmutableList.of(copyFilesPhase));
    TargetNode<?, ?> postbuildNode = XcodePostbuildScriptBuilder.createBuilder(BuildTargetFactory.newInstance("//foo:script")).setCmd("echo \"hello world!\"").build();
    mutator.setPostBuildRunScriptPhasesFromTargetNodes(ImmutableList.of(postbuildNode));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    PBXNativeTarget target = result.target;
    List<PBXBuildPhase> buildPhases = target.getBuildPhases();
    PBXBuildPhase copyBuildPhaseToTest = getSingletonPhaseByType(target, PBXCopyFilesBuildPhase.class);
    PBXBuildPhase postBuildScriptPhase = getSingletonPhaseByType(target, PBXShellScriptBuildPhase.class);
    assertThat(buildPhases.indexOf(copyBuildPhaseToTest), lessThan(buildPhases.indexOf(postBuildScriptPhase)));
}
Also used : CopyFilePhaseDestinationSpec(com.facebook.buck.apple.xcode.xcodeproj.CopyFilePhaseDestinationSpec) PBXNativeTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) PBXCopyFilesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXCopyFilesBuildPhase) Test(org.junit.Test)

Example 10 with PBXBuildPhase

use of com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase in project buck by facebook.

the class ProjectGeneratorTest method testAggregateTargetForBinaryForBuildWithBuck.

@Test
public void testAggregateTargetForBinaryForBuildWithBuck() throws IOException {
    BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "binary").build();
    TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m"), ImmutableList.of("-foo")))).build();
    ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(binaryNode);
    final TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
    final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
    ProjectGenerator projectGenerator = new ProjectGenerator(targetGraph, cache, nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(), Optional.of(binaryTarget), ImmutableList.of("--flag", "value with spaces"), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
    projectGenerator.createXcodeProjects();
    PBXTarget buildWithBuckTarget = null;
    for (PBXTarget target : projectGenerator.getGeneratedProject().getTargets()) {
        if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
            buildWithBuckTarget = target;
        }
    }
    assertThat(buildWithBuckTarget, is(notNullValue()));
    assertHasConfigurations(buildWithBuckTarget, "Debug");
    assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), buildWithBuckTarget);
    assertEquals("Should have exact number of build phases", 1, buildWithBuckTarget.getBuildPhases().size());
    PBXBuildPhase buildPhase = Iterables.getOnlyElement(buildWithBuckTarget.getBuildPhases());
    assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
    PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("buck -- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + binaryTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    Path fixUUIDScriptPath = ProjectGenerator.getFixUUIDScriptPath(filesystem);
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("python " + fixUUIDScriptPath + " --verbose " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/binary-unsanitised/binary.app") + " " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/binary-unsanitised/binary.dSYM") + " " + binaryTarget.getShortName()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) AppleDependenciesCache(com.facebook.buck.apple.AppleDependenciesCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Aggregations

PBXBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase)12 Test (org.junit.Test)8 TargetNode (com.facebook.buck.rules.TargetNode)7 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)6 BuildTarget (com.facebook.buck.model.BuildTarget)6 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)6 SourcePath (com.facebook.buck.rules.SourcePath)6 PBXCopyFilesBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXCopyFilesBuildPhase)5 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)5 PathSourcePath (com.facebook.buck.rules.PathSourcePath)5 TargetGraph (com.facebook.buck.rules.TargetGraph)5 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)5 Path (java.nio.file.Path)5 AppleDependenciesCache (com.facebook.buck.apple.AppleDependenciesCache)4 PBXShellScriptBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase)4 AlwaysFoundExecutableFinder (com.facebook.buck.io.AlwaysFoundExecutableFinder)4 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)4 CopyFilePhaseDestinationSpec (com.facebook.buck.apple.xcode.xcodeproj.CopyFilePhaseDestinationSpec)3 PBXBuildFile (com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3