Search in sources :

Example 76 with FakeSourcePath

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

the class ProjectGeneratorTest method stopsCopyingRecursiveDependenciesAtBundles.

@Test
public void stopsCopyingRecursiveDependenciesAtBundles() throws IOException {
    BuildTarget dependentStaticLibraryTarget = BuildTarget.builder(rootPath, "//dep", "static").build();
    TargetNode<?, ?> dependentStaticLibraryNode = AppleLibraryBuilder.createBuilder(dependentStaticLibraryTarget).build();
    BuildTarget dependentStaticFrameworkTarget = BuildTarget.builder(rootPath, "//dep", "static-framework").build();
    TargetNode<?, ?> dependentStaticFrameworkNode = AppleBundleBuilder.createBuilder(dependentStaticFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(dependentStaticLibraryTarget).build();
    BuildTarget dependentSharedLibraryTarget = BuildTarget.builder(rootPath, "//dep", "shared").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
    TargetNode<?, ?> dependentSharedLibraryNode = AppleLibraryBuilder.createBuilder(dependentSharedLibraryTarget).setDeps(ImmutableSortedSet.of(dependentStaticFrameworkTarget)).build();
    BuildTarget dependentFrameworkTarget = BuildTarget.builder(rootPath, "//dep", "framework").build();
    TargetNode<?, ?> dependentFrameworkNode = AppleBundleBuilder.createBuilder(dependentFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(dependentSharedLibraryTarget).build();
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "library").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("e.m")))).setDeps(ImmutableSortedSet.of(dependentFrameworkTarget)).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(// ant needs this to be explicit
    ImmutableSet.of(dependentStaticLibraryNode, dependentStaticFrameworkNode, dependentSharedLibraryNode, dependentFrameworkNode, 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.assertHasSingletonCopyFilesPhaseWithFileEntries(target, ImmutableList.of("$BUILT_PRODUCTS_DIR/framework.framework"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Example 77 with FakeSourcePath

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

the class ProjectGeneratorTest method bundlesDontLinkTheirOwnBinary.

@Test
public void bundlesDontLinkTheirOwnBinary() throws IOException {
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "library").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).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(libraryNode, bundleNode));
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:final");
    assertEquals(target.getProductType(), ProductType.BUNDLE);
    assertEquals("Should have exact number of build phases ", 0, target.getBuildPhases().size());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Example 78 with FakeSourcePath

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

the class ProjectGeneratorTest method applicationTestDoesNotCopyHostAppBundleIntoTestBundle.

@Test
public void applicationTestDoesNotCopyHostAppBundleIntoTestBundle() throws IOException {
    BuildTarget hostAppBinaryTarget = BuildTarget.builder(rootPath, "//foo", "HostAppBinary").build();
    TargetNode<?, ?> hostAppBinaryNode = AppleBinaryBuilder.createBuilder(hostAppBinaryTarget).build();
    BuildTarget hostAppTarget = BuildTarget.builder(rootPath, "//foo", "HostApp").build();
    TargetNode<?, ?> hostAppNode = AppleBundleBuilder.createBuilder(hostAppTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(hostAppBinaryTarget).build();
    BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "AppTest").build();
    TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setInfoPlist(new FakeSourcePath("Info.plist")).setTestHostApp(Optional.of(hostAppTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(hostAppBinaryNode, hostAppNode, testNode), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXTarget testPBXTarget = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:AppTest");
    // for this test phases should be empty - there should be no copy phases in particular
    assertThat(testPBXTarget.getBuildPhases().size(), Matchers.equalTo(0));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Example 79 with FakeSourcePath

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

the class ProjectGeneratorTest method testAppleBundleRuleWithPostBuildScriptDependency.

@Test
public void testAppleBundleRuleWithPostBuildScriptDependency() throws IOException {
    BuildTarget scriptTarget = BuildTarget.builder(rootPath, "//foo", "post_build_script").addFlavors(DEFAULT_FLAVOR).build();
    TargetNode<?, ?> scriptNode = XcodePostbuildScriptBuilder.createBuilder(scriptTarget).setCmd("script.sh").build();
    BuildTarget resourceTarget = BuildTarget.builder(rootPath, "//foo", "resource").build();
    TargetNode<?, ?> resourceNode = AppleResourceBuilder.createBuilder(resourceTarget).setFiles(ImmutableSet.of(new FakeSourcePath("bar.png"))).setDirs(ImmutableSet.of()).build();
    BuildTarget sharedLibraryTarget = BuildTarget.builder(rootPath, "//dep", "shared").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
    TargetNode<?, ?> sharedLibraryNode = AppleLibraryBuilder.createBuilder(sharedLibraryTarget).setDeps(ImmutableSortedSet.of(resourceTarget)).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(sharedLibraryTarget).setDeps(ImmutableSortedSet.of(scriptTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(scriptNode, resourceNode, sharedLibraryNode, bundleNode));
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:bundle");
    assertThat(target.getName(), equalTo("//foo:bundle"));
    assertThat(target.isa(), equalTo("PBXNativeTarget"));
    PBXShellScriptBuildPhase shellScriptBuildPhase = ProjectGeneratorTestUtils.getSingletonPhaseByType(target, PBXShellScriptBuildPhase.class);
    assertThat(shellScriptBuildPhase.getShellScript(), equalTo("script.sh"));
    // Assert that the post-build script phase comes after resources are copied.
    assertThat(target.getBuildPhases().get(0), instanceOf(PBXResourcesBuildPhase.class));
    assertThat(target.getBuildPhases().get(1), instanceOf(PBXShellScriptBuildPhase.class));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) PBXResourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXResourcesBuildPhase) Test(org.junit.Test)

Example 80 with FakeSourcePath

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

the class ProjectCommandXcodeTest method buildGraph.

@Before
public void buildGraph() {
    // Create the following dep tree:
    //
    // FooBin -has-test-> FooBinTest
    // |
    // V
    // FooLib -has-test-> FooLibTest
    // |                  |
    // V                  V
    // BarLib             BazLib -has-test-> BazLibTest
    // ^
    // |
    // QuxBin
    //
    // FooBin and BazLib and FooLibTest use "tests" to specify their tests.
    BuildTarget bazTestTarget = BuildTargetFactory.newInstance("//baz:xctest");
    BuildTarget fooBinTestTarget = BuildTargetFactory.newInstance("//foo:bin-xctest");
    BuildTarget barLibTarget = BuildTargetFactory.newInstance("//bar:lib");
    barLibNode = AppleLibraryBuilder.createBuilder(barLibTarget).build();
    BuildTarget bazLibTarget = BuildTargetFactory.newInstance("//baz:lib");
    bazLibNode = AppleLibraryBuilder.createBuilder(bazLibTarget).setTests(ImmutableSortedSet.of(bazTestTarget)).build();
    BuildTarget fooTestTarget = BuildTargetFactory.newInstance("//foo:lib-xctest");
    fooTestNode = AppleTestBuilder.createBuilder(fooTestTarget).setDeps(ImmutableSortedSet.of(bazLibTarget)).setInfoPlist(new FakeSourcePath("Info.plist")).build();
    BuildTarget fooLibTarget = BuildTargetFactory.newInstance("//foo:lib");
    fooLibNode = AppleLibraryBuilder.createBuilder(fooLibTarget).setDeps(ImmutableSortedSet.of(barLibTarget)).setTests(ImmutableSortedSet.of(fooTestTarget)).build();
    BuildTarget fooBinBinaryTarget = BuildTargetFactory.newInstance("//foo:binbinary");
    fooBinBinaryNode = AppleBinaryBuilder.createBuilder(fooBinBinaryTarget).setDeps(ImmutableSortedSet.of(fooLibTarget)).build();
    BuildTarget fooBinTarget = BuildTargetFactory.newInstance("//foo:bin");
    fooBinNode = AppleBundleBuilder.createBuilder(fooBinTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).setBinary(fooBinBinaryTarget).setTests(ImmutableSortedSet.of(fooBinTestTarget)).setInfoPlist(new FakeSourcePath("Info.plist")).build();
    bazTestNode = AppleTestBuilder.createBuilder(bazTestTarget).setDeps(ImmutableSortedSet.of(bazLibTarget)).setInfoPlist(new FakeSourcePath("Info.plist")).build();
    fooBinTestNode = AppleTestBuilder.createBuilder(fooBinTestTarget).setDeps(ImmutableSortedSet.of(fooBinTarget)).setInfoPlist(new FakeSourcePath("Info.plist")).build();
    BuildTarget quxBinTarget = BuildTargetFactory.newInstance("//qux:bin");
    quxBinNode = AppleBinaryBuilder.createBuilder(quxBinTarget).setDeps(ImmutableSortedSet.of(barLibTarget)).build();
    BuildTarget workspaceExtraTestTarget = BuildTargetFactory.newInstance("//foo:extra-xctest");
    workspaceExtraTestNode = AppleTestBuilder.createBuilder(workspaceExtraTestTarget).setInfoPlist(new FakeSourcePath("Info.plist")).build();
    BuildTarget workspaceTarget = BuildTargetFactory.newInstance("//foo:workspace");
    workspaceNode = XcodeWorkspaceConfigBuilder.createBuilder(workspaceTarget).setWorkspaceName(Optional.of("workspace")).setSrcTarget(Optional.of(fooBinTarget)).setExtraTests(ImmutableSortedSet.of(workspaceExtraTestTarget)).build();
    BuildTarget smallWorkspaceTarget = BuildTargetFactory.newInstance("//baz:small-workspace");
    smallWorkspaceNode = XcodeWorkspaceConfigBuilder.createBuilder(smallWorkspaceTarget).setWorkspaceName(Optional.of("small-workspace")).setSrcTarget(Optional.of(bazLibTarget)).build();
    targetGraph = TargetGraphFactory.newInstance(barLibNode, fooLibNode, fooBinBinaryNode, fooBinNode, bazLibNode, bazTestNode, fooTestNode, fooBinTestNode, quxBinNode, workspaceExtraTestNode, workspaceNode, smallWorkspaceNode);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) Before(org.junit.Before)

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