use of com.facebook.buck.apple.AppleDependenciesCache 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"));
}
use of com.facebook.buck.apple.AppleDependenciesCache 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")));
}
use of com.facebook.buck.apple.AppleDependenciesCache 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()));
}
use of com.facebook.buck.apple.AppleDependenciesCache 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.AppleDependenciesCache in project buck by facebook.
the class ProjectGeneratorTest method createProjectGeneratorForCombinedProject.
private ProjectGenerator createProjectGeneratorForCombinedProject(Collection<TargetNode<?, ?>> nodes, ImmutableSet<ProjectGenerator.Option> projectGeneratorOptions, Function<? super TargetNode<?, ?>, BuildRuleResolver> buildRuleResolverForNode) {
ImmutableSet<BuildTarget> initialBuildTargets = nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet());
final TargetGraph targetGraph = TargetGraphFactory.newInstance(ImmutableSet.copyOf(nodes));
final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
return new ProjectGenerator(targetGraph, cache, initialBuildTargets, projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", projectGeneratorOptions, Optional.empty(), ImmutableList.of(), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, buildRuleResolverForNode, getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
}
Aggregations