Search in sources :

Example 46 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath 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));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) TargetGraph(com.facebook.buck.rules.TargetGraph) PBXCopyFilesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXCopyFilesBuildPhase) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 47 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath 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());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Example 48 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class ProjectGeneratorTest method testAppleLibraryHeaderGroupsWithMappedHeaders.

@Test
public void testAppleLibraryHeaderGroupsWithMappedHeaders() 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 = AppleLibraryBuilder.createBuilder(buildTarget).setSrcs(ImmutableSortedSet.of()).setHeaders(ImmutableSortedMap.of("any/name.h", new FakeSourcePath("HeaderGroup1/foo.h"), "different/name.h", new FakeSourcePath("HeaderGroup2/baz.h"), "one/more/name.h", new DefaultBuildTargetSourcePath(privateGeneratedTarget))).setExportedHeaders(ImmutableSortedMap.of("yet/another/name.h", new FakeSourcePath("HeaderGroup1/bar.h"), "and/one/more.h", new DefaultBuildTargetSourcePath(publicGeneratedTarget))).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node, privateGeneratedNode, publicGeneratedNode));
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXGroup targetGroup = project.getMainGroup().getOrCreateChildGroupByName(buildTarget.getFullyQualifiedName());
    PBXGroup sourcesGroup = targetGroup.getOrCreateChildGroupByName("Sources");
    assertThat(sourcesGroup.getChildren(), hasSize(3));
    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());
    PBXGroup group3 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 2);
    assertEquals("foo", group3.getName());
    assertThat(group3.getChildren(), hasSize(2));
    PBXFileReference fileRefGenerated1 = (PBXFileReference) Iterables.get(group3.getChildren(), 0);
    assertEquals("generated1.h", fileRefGenerated1.getName());
    PBXFileReference fileRefGenerated2 = (PBXFileReference) Iterables.get(group3.getChildren(), 1);
    assertEquals("generated2.h", fileRefGenerated2.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("yet/another/name.h", "HeaderGroup1/bar.h", "and/one/more.h", "foo/generated2.h"));
    assertEquals("buck-out/gen/_p/CwkbTNOBmb-priv", headerSymlinkTrees.get(1).toString());
    assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-priv"), ImmutableMap.of("any/name.h", "HeaderGroup1/foo.h", "different/name.h", "HeaderGroup2/baz.h", "one/more/name.h", "foo/generated1.h"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXHeadersBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXHeadersBuildPhase) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 49 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class ProjectGeneratorTest method testHeaderSymlinkTreesAreRegeneratedWhenKeyChanges.

@Test
public void testHeaderSymlinkTreesAreRegeneratedWhenKeyChanges() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setSrcs(ImmutableSortedSet.of()).setHeaders(ImmutableSortedMap.of("key.h", new FakeSourcePath("value.h"))).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node));
    projectGenerator.createXcodeProjects();
    List<Path> headerSymlinkTrees = projectGenerator.getGeneratedHeaderSymlinkTrees();
    assertThat(headerSymlinkTrees, hasSize(2));
    assertEquals("buck-out/gen/_p/CwkbTNOBmb-priv", headerSymlinkTrees.get(1).toString());
    assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-priv"), ImmutableMap.of("key.h", "value.h"));
    node = AppleLibraryBuilder.createBuilder(buildTarget).setSrcs(ImmutableSortedSet.of()).setHeaders(ImmutableSortedMap.of("new-key.h", new FakeSourcePath("value.h"))).build();
    projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node));
    projectGenerator.createXcodeProjects();
    headerSymlinkTrees = projectGenerator.getGeneratedHeaderSymlinkTrees();
    assertThat(headerSymlinkTrees, hasSize(2));
    assertEquals("buck-out/gen/_p/CwkbTNOBmb-priv", headerSymlinkTrees.get(1).toString());
    assertFalse(projectFilesystem.isSymLink(Paths.get("buck-out/gen/foo/lib-private-header-symlink-tree/key.h")));
    assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-priv"), ImmutableMap.of("new-key.h", "value.h"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Example 50 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class ProjectGeneratorTest method testAppleLibraryWithoutSources.

@Test
public void testAppleLibraryWithoutSources() throws IOException {
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setFrameworks(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Library.framework"), Optional.empty())))).build();
    BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "xctest").build();
    TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setInfoPlist(new FakeSourcePath("Info.plist")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("fooTest.m")))).setDeps(ImmutableSortedSet.of(libraryTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(libraryNode, testNode), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:xctest");
    assertEquals("Should have exact number of build phases", 2, target.getBuildPhases().size());
    assertHasSingletonSourcesPhaseWithSourcesAndFlags(target, ImmutableMap.of("fooTest.m", Optional.empty()));
    ProjectGeneratorTestUtils.assertHasSingletonFrameworksPhaseWithFrameworkEntries(target, ImmutableList.of("$SDKROOT/Library.framework"));
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Aggregations

FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)318 Test (org.junit.Test)297 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)188 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)188 BuildTarget (com.facebook.buck.model.BuildTarget)182 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)116 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)104 SourcePath (com.facebook.buck.rules.SourcePath)90 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)85 TargetGraph (com.facebook.buck.rules.TargetGraph)84 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)68 Path (java.nio.file.Path)67 BuildRule (com.facebook.buck.rules.BuildRule)52 PathSourcePath (com.facebook.buck.rules.PathSourcePath)48 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)46 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)45 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)45 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)35 CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)25 NSString (com.dd.plist.NSString)24