use of com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase in project buck by facebook.
the class ProjectGenerator method generateAppleBundleTarget.
private PBXNativeTarget generateAppleBundleTarget(PBXProject project, TargetNode<? extends HasAppleBundleFields, ?> targetNode, TargetNode<? extends AppleNativeTargetDescriptionArg, ?> binaryNode, Optional<TargetNode<AppleBundleDescription.Arg, ?>> bundleLoaderNode) throws IOException {
Path infoPlistPath = Preconditions.checkNotNull(resolveSourcePath(targetNode.getConstructorArg().getInfoPlist()));
// -- copy any binary and bundle targets into this bundle
Iterable<TargetNode<?, ?>> copiedRules = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, Optional.of(dependenciesCache), AppleBuildRules.RecursiveDependenciesMode.COPYING, targetNode, Optional.of(AppleBuildRules.XCODE_TARGET_DESCRIPTION_CLASSES));
if (bundleRequiresRemovalOfAllTransitiveFrameworks(targetNode)) {
copiedRules = rulesWithoutFrameworkBundles(copiedRules);
} else if (bundleRequiresAllTransitiveFrameworks(binaryNode)) {
copiedRules = ImmutableSet.<TargetNode<?, ?>>builder().addAll(copiedRules).addAll(getTransitiveFrameworkNodes(targetNode)).build();
}
if (bundleLoaderNode.isPresent()) {
copiedRules = rulesWithoutBundleLoader(copiedRules, bundleLoaderNode.get());
}
ImmutableList<PBXBuildPhase> copyFilesBuildPhases = getCopyFilesBuildPhases(copiedRules);
PBXNativeTarget target = generateBinaryTarget(project, Optional.of(targetNode), binaryNode, bundleToTargetProductType(targetNode, binaryNode), "%s." + getExtensionString(targetNode.getConstructorArg().getExtension()), Optional.of(infoPlistPath), /* includeFrameworks */
true, AppleResources.collectRecursiveResources(targetGraph, Optional.of(dependenciesCache), ImmutableList.of(targetNode)), AppleResources.collectDirectResources(targetGraph, targetNode), AppleBuildRules.collectRecursiveAssetCatalogs(targetGraph, Optional.of(dependenciesCache), ImmutableList.of(targetNode)), AppleBuildRules.collectDirectAssetCatalogs(targetGraph, targetNode), AppleBuildRules.collectRecursiveWrapperResources(targetGraph, Optional.of(dependenciesCache), ImmutableList.of(targetNode)), Optional.of(copyFilesBuildPhases), bundleLoaderNode);
LOG.debug("Generated iOS bundle target %s", target);
return target;
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase in project buck by facebook.
the class ProjectGeneratorTest method testFrameworkBundleDepIsNotCopiedToFrameworkBundle.
@Test
public void testFrameworkBundleDepIsNotCopiedToFrameworkBundle() throws IOException {
BuildTarget framework2Target = BuildTarget.builder(rootPath, "//foo", "framework_2").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
BuildTarget framework2BinaryTarget = BuildTarget.builder(rootPath, "//foo", "framework_2_bin").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> framework2BinaryNode = AppleLibraryBuilder.createBuilder(framework2BinaryTarget).build();
TargetNode<?, ?> framework2Node = AppleBundleBuilder.createBuilder(framework2Target).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(framework2BinaryTarget).build();
BuildTarget framework1Target = BuildTarget.builder(rootPath, "//foo", "framework_1").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
BuildTarget framework1BinaryTarget = BuildTarget.builder(rootPath, "//foo", "framework_1_bin").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> framework1BinaryNode = AppleLibraryBuilder.createBuilder(framework1BinaryTarget).build();
TargetNode<?, ?> framework1Node = AppleBundleBuilder.createBuilder(framework1Target).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(framework1BinaryTarget).setDeps(ImmutableSortedSet.of(framework2Target)).build();
BuildTarget sharedLibraryTarget = BuildTarget.builder(rootPath, "//dep", "shared").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> sharedLibraryNode = AppleLibraryBuilder.createBuilder(sharedLibraryTarget).build();
BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "bundle").build();
TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.BUNDLE)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(sharedLibraryTarget).setDeps(ImmutableSortedSet.of(framework1Target)).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(framework1Node, framework2Node, framework1BinaryNode, framework2BinaryNode, sharedLibraryNode, bundleNode), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:framework_1#default,shared");
assertEquals(target.getProductType(), ProductType.FRAMEWORK);
for (PBXBuildPhase buildPhase : target.getBuildPhases()) {
if (buildPhase instanceof PBXCopyFilesBuildPhase) {
PBXCopyFilesBuildPhase copyFilesBuildPhase = (PBXCopyFilesBuildPhase) buildPhase;
assertThat(copyFilesBuildPhase.getDstSubfolderSpec().getDestination(), Matchers.not(PBXCopyFilesBuildPhase.Destination.FRAMEWORKS));
}
}
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase in project buck by facebook.
the class ProjectGeneratorTest method testAppBundleContainsAllTransitiveFrameworkDeps.
@Test
public void testAppBundleContainsAllTransitiveFrameworkDeps() throws IOException {
BuildTarget framework2Target = BuildTarget.builder(rootPath, "//foo", "framework_2").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
BuildTarget framework2BinaryTarget = BuildTarget.builder(rootPath, "//foo", "framework_2_bin").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> framework2BinaryNode = AppleLibraryBuilder.createBuilder(framework2BinaryTarget).build();
TargetNode<?, ?> framework2Node = AppleBundleBuilder.createBuilder(framework2Target).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(framework2BinaryTarget).setProductName(Optional.of("framework_2_override")).build();
BuildTarget framework1Target = BuildTarget.builder(rootPath, "//foo", "framework_1").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
BuildTarget framework1BinaryTarget = BuildTarget.builder(rootPath, "//foo", "framework_1_bin").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> framework1BinaryNode = AppleLibraryBuilder.createBuilder(framework1BinaryTarget).build();
TargetNode<?, ?> framework1Node = AppleBundleBuilder.createBuilder(framework1Target).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(framework1BinaryTarget).setDeps(ImmutableSortedSet.of(framework2Target)).build();
BuildTarget framework1FlavoredTarget = BuildTarget.builder(rootPath, "//foo", "framework_1").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR, InternalFlavor.of("iphoneos-arm64")).build();
TargetNode<?, ?> framework1FlavoredNode = AppleBundleBuilder.createBuilder(framework1FlavoredTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(framework1BinaryTarget).setDeps(ImmutableSortedSet.of(framework2Target)).build();
BuildTarget sharedLibraryTarget = BuildTarget.builder(rootPath, "//dep", "shared").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(sharedLibraryTarget).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(sharedLibraryTarget).setDeps(ImmutableSortedSet.of(framework1Target, framework1FlavoredTarget)).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(framework1Node, framework1FlavoredNode, framework2Node, framework1BinaryNode, framework2BinaryNode, binaryNode, bundleNode), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:bundle");
assertEquals(target.getProductType(), ProductType.APPLICATION);
assertThat(target.getBuildPhases().size(), Matchers.equalTo(1));
PBXBuildPhase buildPhase = target.getBuildPhases().get(0);
assertThat(buildPhase instanceof PBXCopyFilesBuildPhase, Matchers.equalTo(true));
PBXCopyFilesBuildPhase copyFilesBuildPhase = (PBXCopyFilesBuildPhase) buildPhase;
assertThat(copyFilesBuildPhase.getFiles().size(), Matchers.equalTo(2));
ImmutableSet<String> frameworkNames = FluentIterable.from(copyFilesBuildPhase.getFiles()).transform(input -> input.getFileRef().getName()).toSortedSet(Ordering.natural());
assertThat(frameworkNames, Matchers.equalToObject(ImmutableSortedSet.of("framework_1.framework", "framework_2_override.framework")));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase in project buck by facebook.
the class ProjectGeneratorTest method testAppBundleDoesntLinkFrameworkWrappedWithResource.
@Test
public void testAppBundleDoesntLinkFrameworkWrappedWithResource() throws Exception {
BuildTarget frameworkTarget = BuildTarget.builder(rootPath, "//foo", "framework").addFlavors(FakeAppleRuleDescriptions.DEFAULT_MACOSX_X86_64_PLATFORM.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR).build();
BuildTarget frameworkBinaryTarget = BuildTarget.builder(rootPath, "//foo", "framework_bin").addFlavors(FakeAppleRuleDescriptions.DEFAULT_MACOSX_X86_64_PLATFORM.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> frameworkBinaryNode = AppleLibraryBuilder.createBuilder(frameworkBinaryTarget).build();
TargetNode<?, ?> frameworkNode = AppleBundleBuilder.createBuilder(frameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(frameworkBinaryTarget).build();
BuildTarget resourceTarget = BuildTarget.builder(rootPath, "//foo", "res").build();
SourcePath sourcePath = new DefaultBuildTargetSourcePath(frameworkTarget);
TargetNode<?, ?> resourceNode = AppleResourceBuilder.createBuilder(resourceTarget).setFiles(ImmutableSet.of()).setDirs(ImmutableSet.of(sourcePath)).build();
BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "bin").build();
TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setDeps(ImmutableSortedSet.of(resourceTarget)).build();
BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "bundle").addFlavors(FakeAppleRuleDescriptions.DEFAULT_MACOSX_X86_64_PLATFORM.getFlavor()).build();
TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(binaryTarget).build();
ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(frameworkBinaryNode, frameworkNode, resourceNode, binaryNode, bundleNode);
final TargetGraph targetGraph = TargetGraphFactory.newInstance(ImmutableSet.copyOf(nodes));
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(nodes, ImmutableSet.of(), getBuildRuleResolverWithRulesForNodeFunction(targetGraph));
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), bundleTarget.getFullyQualifiedName());
assertEquals(target.getProductType(), ProductType.APPLICATION);
for (PBXBuildPhase buildPhase : target.getBuildPhases()) {
assertFalse(buildPhase instanceof PBXCopyFilesBuildPhase);
}
assertThat(target.getBuildPhases().size(), Matchers.equalTo(1));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase in project buck by facebook.
the class ProjectGeneratorTest method testAggregateTargetForLibraryForBuildWithBuck.
@Test
public void testAggregateTargetForLibraryForBuildWithBuck() throws IOException {
BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "library").build();
TargetNode<?, ?> binaryNode = AppleLibraryBuilder.createBuilder(libraryTarget).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(libraryTarget), 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'\" " + libraryTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
}
Aggregations