use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class ProjectGeneratorTest method testAppleBundleRuleWithCustomXcodeProductType.
@Test
public void testAppleBundleRuleWithCustomXcodeProductType() 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())).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).setXcodeProductType(Optional.of("com.facebook.buck.niftyProductType")).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(sharedLibraryNode, node), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXProject project = projectGenerator.getGeneratedProject();
PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:custombundle");
assertEquals(target.getProductType(), ProductType.of("com.facebook.buck.niftyProductType"));
assertThat(target.isa(), equalTo("PBXNativeTarget"));
PBXFileReference productReference = target.getProductReference();
assertEquals("custombundle.framework", productReference.getName());
assertEquals(Optional.of("wrapper.framework"), productReference.getExplicitFileType());
ImmutableMap<String, String> settings = getBuildSettings(buildTarget, target, "Debug");
assertEquals("framework", settings.get("WRAPPER_EXTENSION"));
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class RuleUtilsTest method creatingGroupsFromEntryMapsKeepsLongestCommonPrefix.
@Test
public void creatingGroupsFromEntryMapsKeepsLongestCommonPrefix() {
ImmutableMultimap<Path, String> subgroups = ImmutableMultimap.<Path, String>builder().put(Paths.get("root"), "Lib").put(Paths.get("root/Lib"), "Bar").put(Paths.get("root/Lib"), "Foo").build();
ImmutableMultimap<Path, GroupedSource> entries = ImmutableMultimap.<Path, GroupedSource>builder().put(Paths.get("root/Lib/Foo"), GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File2.h"))).put(Paths.get("root/Lib/Bar"), GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Bar/File1.h"))).put(Paths.get("root/Lib/Foo"), GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File1.h"))).build();
ImmutableList<GroupedSource> expected = ImmutableList.of(GroupedSource.ofSourceGroup("Lib", Paths.get("Lib"), ImmutableList.of(GroupedSource.ofSourceGroup("Bar", Paths.get("Lib/Bar"), ImmutableList.of(GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Bar/File1.h")))), GroupedSource.ofSourceGroup("Foo", Paths.get("Lib/Foo"), ImmutableList.of(GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File1.h")), GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File2.h")))))));
SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
ImmutableList<GroupedSource> actual = RuleUtils.createGroupsFromEntryMaps(subgroups, entries, new RuleUtils.GroupedSourceNameComparator(resolver::getRelativePath), Paths.get("root"), Paths.get("root"));
assertEquals(expected, actual);
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class ProjectGeneratorTest method testCxxLibraryHeaderGroupsWithMapsOfHeadersAndCustomNamespace.
@Test
public void testCxxLibraryHeaderGroupsWithMapsOfHeadersAndCustomNamespace() throws IOException {
BuildTarget privateGeneratedTarget = BuildTarget.builder(rootPath, "//foo", "generated1.h").build();
BuildTarget publicGeneratedTarget = BuildTarget.builder(rootPath, "//foo", "generated2.h").build();
TargetNode<?, ?> privateGeneratedNode = ExportFileBuilder.newExportFileBuilder(privateGeneratedTarget).build();
TargetNode<?, ?> publicGeneratedNode = ExportFileBuilder.newExportFileBuilder(publicGeneratedTarget).build();
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = new CxxLibraryBuilder(buildTarget).setExportedHeaders(ImmutableSortedMap.of("yet/another/name.h", new FakeSourcePath("foo/dir1/bar.h"), "and/one/more.h", new DefaultBuildTargetSourcePath(publicGeneratedTarget))).setHeaders(ImmutableSortedMap.of("any/name.h", new FakeSourcePath("foo/dir1/foo.h"), "different/name.h", new FakeSourcePath("foo/dir2/baz.h"), "one/more/name.h", new DefaultBuildTargetSourcePath(privateGeneratedTarget))).setSrcs(ImmutableSortedSet.of()).setHeaderNamespace("name/space").build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node, privateGeneratedNode, publicGeneratedNode));
projectGenerator.createXcodeProjects();
List<Path> headerSymlinkTrees = projectGenerator.getGeneratedHeaderSymlinkTrees();
assertThat(headerSymlinkTrees, hasSize(2));
assertThat(headerSymlinkTrees.get(0).toString(), is(equalTo("buck-out/gen/_p/CwkbTNOBmb-pub")));
assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-pub"), ImmutableMap.of("name/space/yet/another/name.h", "foo/dir1/bar.h", "name/space/and/one/more.h", "foo/generated2.h"));
assertThat(headerSymlinkTrees.get(1).toString(), is(equalTo("buck-out/gen/_p/CwkbTNOBmb-priv")));
assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-priv"), ImmutableMap.of("name/space/any/name.h", "foo/dir1/foo.h", "name/space/different/name.h", "foo/dir2/baz.h", "name/space/one/more/name.h", "foo/generated1.h"));
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class ProjectGeneratorTest method testAppleLibraryHeaderGroupsWithHeaderSymlinkTrees.
@Test
public void testAppleLibraryHeaderGroupsWithHeaderSymlinkTrees() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setSrcs(ImmutableSortedSet.of()).setHeaders(ImmutableSortedSet.of(new FakeSourcePath("HeaderGroup1/foo.h"), new FakeSourcePath("HeaderGroup2/baz.h"))).setExportedHeaders(ImmutableSortedSet.of(new FakeSourcePath("HeaderGroup1/bar.h"))).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node));
projectGenerator.createXcodeProjects();
PBXProject project = projectGenerator.getGeneratedProject();
PBXGroup targetGroup = project.getMainGroup().getOrCreateChildGroupByName(buildTarget.getFullyQualifiedName());
PBXGroup sourcesGroup = targetGroup.getOrCreateChildGroupByName("Sources");
assertThat(sourcesGroup.getChildren(), hasSize(2));
PBXGroup group1 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 0);
assertEquals("HeaderGroup1", group1.getName());
assertThat(group1.getChildren(), hasSize(2));
PBXFileReference fileRefFoo = (PBXFileReference) Iterables.get(group1.getChildren(), 0);
assertEquals("bar.h", fileRefFoo.getName());
PBXFileReference fileRefBar = (PBXFileReference) Iterables.get(group1.getChildren(), 1);
assertEquals("foo.h", fileRefBar.getName());
PBXGroup group2 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 1);
assertEquals("HeaderGroup2", group2.getName());
assertThat(group2.getChildren(), hasSize(1));
PBXFileReference fileRefBaz = (PBXFileReference) Iterables.get(group2.getChildren(), 0);
assertEquals("baz.h", fileRefBaz.getName());
// There should be no PBXHeadersBuildPhase in the 'Buck header map mode'.
PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:lib");
assertEquals(0, target.getBuildPhases().stream().filter(input -> input instanceof PBXHeadersBuildPhase).count());
List<Path> headerSymlinkTrees = projectGenerator.getGeneratedHeaderSymlinkTrees();
assertThat(headerSymlinkTrees, hasSize(2));
assertEquals("buck-out/gen/_p/CwkbTNOBmb-pub", headerSymlinkTrees.get(0).toString());
assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-pub"), ImmutableMap.of("lib/bar.h", "HeaderGroup1/bar.h"));
assertEquals("buck-out/gen/_p/CwkbTNOBmb-priv", headerSymlinkTrees.get(1).toString());
assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-priv"), ImmutableMap.<String, String>builder().put("lib/foo.h", "HeaderGroup1/foo.h").put("lib/baz.h", "HeaderGroup2/baz.h").put("foo.h", "HeaderGroup1/foo.h").put("bar.h", "HeaderGroup1/bar.h").put("baz.h", "HeaderGroup2/baz.h").build());
}
use of com.facebook.buck.rules.FakeSourcePath 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