use of com.facebook.buck.apple.xcode.xcodeproj.PBXProject in project buck by facebook.
the class ProjectGeneratorTest method resourcesInDependenciesPropagatesToBundles.
@Test
public void resourcesInDependenciesPropagatesToBundles() throws IOException {
BuildTarget resourceTarget = BuildTarget.builder(rootPath, "//foo", "res").build();
TargetNode<?, ?> resourceNode = AppleResourceBuilder.createBuilder(resourceTarget).setFiles(ImmutableSet.of(new FakeSourcePath("bar.png"))).setDirs(ImmutableSet.of(new FakeSourcePath("foodir"))).build();
BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setDeps(ImmutableSortedSet.of(resourceTarget)).build();
BuildTarget bundleLibraryTarget = BuildTarget.builder(rootPath, "//foo", "bundlelib").build();
TargetNode<?, ?> bundleLibraryNode = AppleLibraryBuilder.createBuilder(bundleLibraryTarget).setDeps(ImmutableSortedSet.of(libraryTarget)).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(bundleLibraryTarget).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(resourceNode, libraryNode, bundleLibraryNode, bundleNode));
projectGenerator.createXcodeProjects();
PBXProject generatedProject = projectGenerator.getGeneratedProject();
PBXTarget target = assertTargetExistsAndReturnTarget(generatedProject, "//foo:bundle");
assertHasSingletonResourcesPhaseWithEntries(target, "bar.png", "foodir");
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXProject in project buck by facebook.
the class ProjectGeneratorTest method testAppleBundleRuleWithCustomXcodeProductNameFromConfigs.
@Test
public void testAppleBundleRuleWithCustomXcodeProductNameFromConfigs() throws IOException {
BuildTarget sharedLibraryTarget = BuildTarget.builder(rootPath, "//dep", "shared").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> sharedLibraryNode = AppleLibraryBuilder.createBuilder(sharedLibraryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of("PRODUCT_NAME", "FancyFramework"))).build();
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "custombundle").build();
TargetNode<?, ?> node = AppleBundleBuilder.createBuilder(buildTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(sharedLibraryTarget).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(sharedLibraryNode, node), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXProject project = projectGenerator.getGeneratedProject();
PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:custombundle");
ImmutableMap<String, String> buildSettings = getBuildSettings(buildTarget, target, "Debug");
assertThat(buildSettings.get("PRODUCT_NAME"), Matchers.equalTo("FancyFramework"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXProject 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.PBXProject in project buck by facebook.
the class ProjectGeneratorTest method generatedTargetConfigurationHasRepoRootSet.
@Test
public void generatedTargetConfigurationHasRepoRootSet() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "rule").build();
TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXProject generatedProject = projectGenerator.getGeneratedProject();
ImmutableMap<String, String> settings = getBuildSettings(buildTarget, generatedProject.getTargets().get(0), "Debug");
assertThat(settings, hasKey("REPO_ROOT"));
assertEquals(projectFilesystem.getRootPath().toAbsolutePath().normalize().toString(), settings.get("REPO_ROOT"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXProject in project buck by facebook.
the class ProjectGeneratorTest method testGeneratedProjectStructureAndSettingsWithBridgingHeader.
@Test
public void testGeneratedProjectStructureAndSettingsWithBridgingHeader() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of()).setBridgingHeader(Optional.of(new FakeSourcePath("BridgingHeader/header1.h"))).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node));
projectGenerator.createXcodeProjects();
// check if bridging header file existing in the project structure
PBXProject project = projectGenerator.getGeneratedProject();
PBXGroup targetGroup = project.getMainGroup().getOrCreateChildGroupByName(buildTarget.getFullyQualifiedName());
PBXGroup sourcesGroup = targetGroup.getOrCreateChildGroupByName("Sources");
assertThat(sourcesGroup.getChildren(), hasSize(1));
PBXFileReference fileRefBridgingHeader = (PBXFileReference) Iterables.get(sourcesGroup.getChildren(), 0);
assertEquals("header1.h", fileRefBridgingHeader.getName());
// check for bridging header build setting
PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:lib");
ImmutableMap<String, String> buildSettings = getBuildSettings(buildTarget, target, "Debug");
assertEquals("$(SRCROOT)/../BridgingHeader/header1.h", buildSettings.get("SWIFT_OBJC_BRIDGING_HEADER"));
}
Aggregations