use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testCxxLibraryExportedPreprocessorFlags.
@Test
public void testCxxLibraryExportedPreprocessorFlags() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = new CxxLibraryBuilder(buildTarget).setExportedPreprocessorFlags(ImmutableList.of("-DHELLO")).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
assertHasConfigurations(target, "Debug", "Release", "Profile");
ImmutableMap<String, String> settings = ProjectGeneratorTestUtils.getBuildSettings(projectFilesystem, buildTarget, target, "Debug");
assertEquals("-Wno-deprecated -Wno-conversion -DHELLO -Wno-deprecated -Wno-conversion -DHELLO", settings.get("OTHER_CFLAGS"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testAppleLibraryTransitiveDependentsSearchHeadersAndLibraries.
@Test
public void testAppleLibraryTransitiveDependentsSearchHeadersAndLibraries() throws IOException {
ImmutableSortedMap<String, ImmutableMap<String, String>> configs = ImmutableSortedMap.of("Debug", ImmutableMap.<String, String>of());
BuildTarget libraryDepTarget = BuildTarget.builder(rootPath, "//bar", "lib").build();
TargetNode<?, ?> libraryDepNode = AppleLibraryBuilder.createBuilder(libraryDepTarget).setConfigs(configs).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m")))).setFrameworks(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Library.framework"), Optional.empty())))).build();
BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setConfigs(configs).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m")))).setFrameworks(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Library.framework"), Optional.empty())))).setDeps(ImmutableSortedSet.of(libraryDepTarget)).build();
BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "xctest").build();
TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setConfigs(configs).setInfoPlist(new FakeSourcePath("Info.plist")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("fooTest.m")))).setFrameworks(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Test.framework"), Optional.empty())))).setDeps(ImmutableSortedSet.of(libraryTarget)).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(libraryDepNode, libraryNode, testNode), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:xctest");
ImmutableMap<String, String> settings = getBuildSettings(testTarget, target, "Debug");
assertEquals("$(inherited) " + "../buck-out/gen/_p/ptQfVNNRRE-priv/.hmap " + "../buck-out/gen/_p/ptQfVNNRRE-pub/.hmap " + "../buck-out/gen/_p/zAW4E7kxsV-pub/.hmap " + "../buck-out/gen/_p/CwkbTNOBmb-pub/.hmap " + "../buck-out", settings.get("HEADER_SEARCH_PATHS"));
assertEquals(null, settings.get("USER_HEADER_SEARCH_PATHS"));
assertEquals("$(inherited) " + "$BUILT_PRODUCTS_DIR", settings.get("LIBRARY_SEARCH_PATHS"));
assertEquals("$(inherited) " + "$BUILT_PRODUCTS_DIR $SDKROOT", settings.get("FRAMEWORK_SEARCH_PATHS"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testMergedHeaderMap.
@Test
public void testMergedHeaderMap() throws IOException {
BuildTarget lib1Target = BuildTarget.builder(rootPath, "//foo", "lib1").build();
BuildTarget lib2Target = BuildTarget.builder(rootPath, "//bar", "lib2").build();
BuildTarget lib3Target = BuildTarget.builder(rootPath, "//foo", "lib3").build();
BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "test").build();
BuildTarget lib4Target = BuildTarget.builder(rootPath, "//foo", "lib4").build();
TargetNode<?, ?> lib1Node = AppleLibraryBuilder.createBuilder(lib1Target).setConfigs(ImmutableSortedMap.of("Default", ImmutableMap.of())).setExportedHeaders(ImmutableSortedSet.of(new FakeSourcePath("lib1.h"))).setDeps(ImmutableSortedSet.of(lib2Target)).setTests(ImmutableSortedSet.of(testTarget)).build();
TargetNode<?, ?> lib2Node = AppleLibraryBuilder.createBuilder(lib2Target).setConfigs(ImmutableSortedMap.of("Default", ImmutableMap.of())).setExportedHeaders(ImmutableSortedSet.of(new FakeSourcePath("lib2.h"))).build();
TargetNode<?, ?> lib3Node = AppleLibraryBuilder.createBuilder(lib3Target).setConfigs(ImmutableSortedMap.of("Default", ImmutableMap.of())).setExportedHeaders(ImmutableSortedSet.of(new FakeSourcePath("lib3.h"))).build();
TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setConfigs(ImmutableSortedMap.of("Default", ImmutableMap.of())).setInfoPlist(new FakeSourcePath("Info.plist")).setDeps(ImmutableSortedSet.of(lib1Target, lib4Target)).build();
TargetNode<?, ?> lib4Node = AppleLibraryBuilder.createBuilder(lib4Target).setConfigs(ImmutableSortedMap.of("Default", ImmutableMap.of())).setExportedHeaders(ImmutableSortedSet.of(new FakeSourcePath("lib4.h"))).build();
final TargetGraph targetGraph = TargetGraphFactory.newInstance(ImmutableSet.of(lib1Node, lib2Node, lib3Node, testNode, lib4Node));
final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
ProjectGenerator projectGeneratorLib2 = new ProjectGenerator(targetGraph, cache, ImmutableSet.of(lib2Target), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(ProjectGenerator.Option.MERGE_HEADER_MAPS), Optional.empty(), ImmutableList.of(), false, /* isMainProject */
Optional.of(lib1Target), ImmutableSet.of(lib1Target, lib4Target), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
projectGeneratorLib2.createXcodeProjects();
// The merged header map should not generated at this point.
Path hmapPath = Paths.get("buck-out/gen/_p/pub-hmap/.hmap");
assertFalse(hmapPath.toString() + " should NOT exist.", projectFilesystem.isFile(hmapPath));
// Checks the content of the header search paths.
PBXProject project2 = projectGeneratorLib2.getGeneratedProject();
PBXTarget testPBXTarget2 = assertTargetExistsAndReturnTarget(project2, "//bar:lib2");
ImmutableMap<String, String> buildSettings2 = getBuildSettings(lib2Target, testPBXTarget2, "Default");
assertEquals("test binary should use header symlink trees for both public and non-public headers " + "of the tested library in HEADER_SEARCH_PATHS", "$(inherited) " + "../buck-out/gen/_p/YAYFR3hXIb-priv/.hmap " + "../buck-out/gen/_p/pub-hmap/.hmap " + "../buck-out", buildSettings2.get("HEADER_SEARCH_PATHS"));
ProjectGenerator projectGeneratorLib1 = new ProjectGenerator(targetGraph, cache, ImmutableSet.of(lib1Target, testTarget), /* lib3Target not included on purpose */
projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(ProjectGenerator.Option.MERGE_HEADER_MAPS), Optional.empty(), ImmutableList.of(), true, /* isMainProject */
Optional.of(lib1Target), ImmutableSet.of(lib1Target, lib4Target), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
projectGeneratorLib1.createXcodeProjects();
// The merged header map should not generated at this point.
assertTrue(hmapPath.toString() + " should exist.", projectFilesystem.isFile(hmapPath));
assertThatHeaderMapWithoutSymLinksContains(Paths.get("buck-out/gen/_p/pub-hmap"), ImmutableMap.of("lib1/lib1.h", "buck-out/gen/_p/WNl0jZWMBk-pub/lib1/lib1.h", "lib2/lib2.h", "buck-out/gen/_p/YAYFR3hXIb-pub/lib2/lib2.h", "lib4/lib4.h", "buck-out/gen/_p/nmnbF8ID6C-pub/lib4/lib4.h"));
// Checks the content of the header search paths.
PBXProject project1 = projectGeneratorLib1.getGeneratedProject();
// For //foo:lib1
PBXTarget testPBXTarget1 = assertTargetExistsAndReturnTarget(project1, "//foo:lib1");
ImmutableMap<String, String> buildSettings1 = getBuildSettings(lib1Target, testPBXTarget1, "Default");
assertEquals("test binary should use header symlink trees for both public and non-public headers " + "of the tested library in HEADER_SEARCH_PATHS", "$(inherited) " + "../buck-out/gen/_p/WNl0jZWMBk-priv/.hmap " + "../buck-out/gen/_p/pub-hmap/.hmap " + "../buck-out", buildSettings1.get("HEADER_SEARCH_PATHS"));
// For //foo:test
PBXTarget testPBXTargetTest = assertTargetExistsAndReturnTarget(project1, "//foo:test");
ImmutableMap<String, String> buildSettingsTest = getBuildSettings(testTarget, testPBXTargetTest, "Default");
assertEquals("test binary should use header symlink trees for both public and non-public headers " + "of the tested library in HEADER_SEARCH_PATHS", "$(inherited) " + "../buck-out/gen/_p/LpygK8zq5F-priv/.hmap " + "../buck-out/gen/_p/pub-hmap/.hmap " + "../buck-out/gen/_p/WNl0jZWMBk-priv/.hmap " + "../buck-out", buildSettingsTest.get("HEADER_SEARCH_PATHS"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testAppleLibraryCxxCFlags.
@Test
public void testAppleLibraryCxxCFlags() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).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", settings.get("OTHER_CFLAGS"));
assertEquals("$(inherited) -Wundeclared-selector -Wno-objc-designated-initializers", settings.get("OTHER_CPLUSPLUSFLAGS"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method stopsLinkingRecursiveDependenciesAtSharedLibraries.
@Test
public void stopsLinkingRecursiveDependenciesAtSharedLibraries() throws IOException {
BuildTarget dependentStaticLibraryTarget = BuildTarget.builder(rootPath, "//dep", "static").build();
TargetNode<?, ?> dependentStaticLibraryNode = AppleLibraryBuilder.createBuilder(dependentStaticLibraryTarget).build();
BuildTarget dependentSharedLibraryTarget = BuildTarget.builder(rootPath, "//dep", "shared").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> dependentSharedLibraryNode = AppleLibraryBuilder.createBuilder(dependentSharedLibraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("empty.m")))).setDeps(ImmutableSortedSet.of(dependentStaticLibraryTarget)).build();
BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "library").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setDeps(ImmutableSortedSet.of(dependentSharedLibraryTarget)).build();
BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "final").build();
TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.BUNDLE)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(libraryTarget).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(dependentStaticLibraryNode, dependentSharedLibraryNode, libraryNode, bundleNode));
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:final");
assertEquals(target.getProductType(), ProductType.BUNDLE);
assertEquals("Should have exact number of build phases ", 2, target.getBuildPhases().size());
ProjectGeneratorTestUtils.assertHasSingletonFrameworksPhaseWithFrameworkEntries(target, ImmutableList.of("$BUILT_PRODUCTS_DIR/libshared.dylib"));
}
Aggregations