use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method applicationTestUsesHostAppAsTestHostAndBundleLoader.
@Test
public void applicationTestUsesHostAppAsTestHostAndBundleLoader() throws IOException {
BuildTarget hostAppBinaryTarget = BuildTarget.builder(rootPath, "//foo", "HostAppBinary").build();
TargetNode<?, ?> hostAppBinaryNode = AppleBinaryBuilder.createBuilder(hostAppBinaryTarget).build();
BuildTarget hostAppTarget = BuildTarget.builder(rootPath, "//foo", "HostApp").build();
TargetNode<?, ?> hostAppNode = AppleBundleBuilder.createBuilder(hostAppTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(hostAppBinaryTarget).build();
BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "AppTest").build();
TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setInfoPlist(new FakeSourcePath("Info.plist")).setTestHostApp(Optional.of(hostAppTarget)).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(hostAppBinaryNode, hostAppNode, testNode), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget testPBXTarget = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:AppTest");
ImmutableMap<String, String> settings = getBuildSettings(testTarget, testPBXTarget, "Debug");
// Check starts with as the remainder depends on the bundle style at build time.
assertTrue(settings.get("BUNDLE_LOADER").startsWith("$BUILT_PRODUCTS_DIR/./HostApp.app/"));
assertEquals("$(BUNDLE_LOADER)", settings.get("TEST_HOST"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testAppleLibraryCompilerAndPreprocessorFlags.
@Test
public void testAppleLibraryCompilerAndPreprocessorFlags() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setCompilerFlags(ImmutableList.of("-fhello")).setPreprocessorFlags(ImmutableList.of("-fworld")).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
ImmutableMap<String, String> settings = getBuildSettings(buildTarget, target, "Debug");
assertEquals("$(inherited) -Wno-deprecated -Wno-conversion -fhello -fworld", settings.get("OTHER_CFLAGS"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget 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.PBXTarget 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.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testAppleBinaryRule.
@Test
public void testAppleBinaryRule() throws IOException {
BuildTarget depTarget = BuildTarget.builder(rootPath, "//dep", "dep").build();
TargetNode<?, ?> depNode = AppleLibraryBuilder.createBuilder(depTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("e.m")))).build();
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")))).setExtraXcodeSources(ImmutableList.of(new FakeSourcePath("libsomething.a"))).setHeaders(ImmutableSortedSet.of(new FakeSourcePath("foo.h"))).setFrameworks(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Foo.framework"), Optional.empty())))).setDeps(ImmutableSortedSet.of(depTarget)).setHeaderPathPrefix(Optional.empty()).setPrefixHeader(Optional.empty()).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(depNode, binaryNode));
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:binary");
assertHasConfigurations(target, "Debug");
assertEquals(target.getProductType(), ProductType.TOOL);
assertEquals("Should have exact number of build phases", 2, target.getBuildPhases().size());
assertHasSingletonSourcesPhaseWithSourcesAndFlags(target, ImmutableMap.of("foo.m", Optional.of("-foo"), "libsomething.a", Optional.empty()));
ProjectGeneratorTestUtils.assertHasSingletonFrameworksPhaseWithFrameworkEntries(target, ImmutableList.of("$SDKROOT/Foo.framework", // Propagated library from deps.
"$BUILT_PRODUCTS_DIR/libdep.a"));
// this test does not have a dependency on any asset catalogs, so verify no build phase for them
// exists.
assertTrue(FluentIterable.from(target.getBuildPhases()).filter(PBXResourcesBuildPhase.class).isEmpty());
}
Aggregations