Search in sources :

Example 11 with DefaultBuildTargetSourcePath

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

the class ProjectGeneratorTest method resourceDirectoriesHaveFolderType.

@Test
public void resourceDirectoriesHaveFolderType() throws IOException {
    BuildTarget directoryTarget = BuildTarget.builder(rootPath, "//foo", "dir").build();
    BuildTarget resourceTarget = BuildTarget.builder(rootPath, "//foo", "res").build();
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> directoryNode = ExportFileBuilder.newExportFileBuilder(directoryTarget).build();
    TargetNode<?, ?> resourceNode = AppleResourceBuilder.createBuilder(resourceTarget).setDirs(ImmutableSet.of(new DefaultBuildTargetSourcePath(directoryTarget))).setFiles(ImmutableSet.of()).build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setDeps(ImmutableSortedSet.of(resourceTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(directoryNode, resourceNode, libraryNode));
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXGroup mainGroup = project.getMainGroup();
    PBXGroup resourcesGroup = mainGroup.getOrCreateDescendantGroupByPath(ImmutableList.of("//foo:lib", "Resources"));
    PBXFileReference resource = (PBXFileReference) Iterables.get(resourcesGroup.getChildren(), 0);
    assertThat(resource.getName(), equalTo("dir"));
    assertThat(resource.getExplicitFileType(), equalTo(Optional.of("folder")));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) 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 12 with DefaultBuildTargetSourcePath

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

the class WorkspaceAndProjectGeneratorTest method requiredBuildTargetsForCombinedProject.

@Test
public void requiredBuildTargetsForCombinedProject() throws IOException, InterruptedException {
    BuildTarget genruleTarget = BuildTarget.builder(rootCell.getRoot(), "//foo", "gen").build();
    TargetNode<GenruleDescription.Arg, ?> genrule = GenruleBuilder.newGenruleBuilder(genruleTarget).setOut("source.m").build();
    BuildTarget libraryTarget = BuildTarget.builder(rootCell.getRoot(), "//foo", "lib").build();
    TargetNode<AppleLibraryDescription.Arg, ?> library = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new DefaultBuildTargetSourcePath(genruleTarget)))).build();
    TargetNode<XcodeWorkspaceConfigDescription.Arg, ?> workspaceNode = XcodeWorkspaceConfigBuilder.createBuilder(BuildTarget.builder(rootCell.getRoot(), "//foo", "workspace").build()).setSrcTarget(Optional.of(libraryTarget)).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(genrule, library, workspaceNode);
    WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(), true, /* combinedProject */
    false, /* buildWithBuck */
    ImmutableList.of(), Optional.empty(), false, /* parallelizeBuild */
    new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, "BUCK", getBuildRuleResolverForNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
    Map<Path, ProjectGenerator> projectGenerators = new HashMap<>();
    generator.generateWorkspaceAndDependentProjects(projectGenerators, MoreExecutors.newDirectExecutorService());
    assertEquals(generator.getRequiredBuildTargets(), ImmutableSet.of(genruleTarget));
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) HashMap(java.util.HashMap) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Example 13 with DefaultBuildTargetSourcePath

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

the class WorkspaceAndProjectGeneratorTest method requiredBuildTargets.

@Test
public void requiredBuildTargets() throws IOException, InterruptedException {
    BuildTarget genruleTarget = BuildTarget.builder(rootCell.getRoot(), "//foo", "gen").build();
    TargetNode<GenruleDescription.Arg, ?> genrule = GenruleBuilder.newGenruleBuilder(genruleTarget).setOut("source.m").build();
    BuildTarget libraryTarget = BuildTarget.builder(rootCell.getRoot(), "//foo", "lib").build();
    TargetNode<AppleLibraryDescription.Arg, ?> library = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new DefaultBuildTargetSourcePath(genruleTarget)))).build();
    TargetNode<XcodeWorkspaceConfigDescription.Arg, ?> workspaceNode = XcodeWorkspaceConfigBuilder.createBuilder(BuildTarget.builder(rootCell.getRoot(), "//foo", "workspace").build()).setSrcTarget(Optional.of(libraryTarget)).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(genrule, library, workspaceNode);
    WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(), false, /* combinedProject */
    false, /* buildWithBuck */
    ImmutableList.of(), Optional.empty(), false, /* parallelizeBuild */
    new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, "BUCK", getBuildRuleResolverForNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
    Map<Path, ProjectGenerator> projectGenerators = new HashMap<>();
    generator.generateWorkspaceAndDependentProjects(projectGenerators, MoreExecutors.newDirectExecutorService());
    assertEquals(generator.getRequiredBuildTargets(), ImmutableSet.of(genruleTarget));
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) HashMap(java.util.HashMap) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Example 14 with DefaultBuildTargetSourcePath

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

the class CxxDescriptionEnhancerTest method nonTestLibraryDepDoesNotIncludePrivateHeadersOfLibrary.

@Test
public void nonTestLibraryDepDoesNotIncludePrivateHeadersOfLibrary() throws Exception {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    BuildTarget libTarget = BuildTargetFactory.newInstance("//:lib");
    BuildRuleParams libParams = new FakeBuildRuleParamsBuilder(libTarget).build();
    FakeCxxLibrary libRule = new FakeCxxLibrary(libParams, BuildTargetFactory.newInstance("//:header"), BuildTargetFactory.newInstance("//:symlink"), BuildTargetFactory.newInstance("//:privateheader"), BuildTargetFactory.newInstance("//:privatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // This library has no tests.
    ImmutableSortedSet.of());
    BuildTarget otherLibDepTarget = BuildTargetFactory.newInstance("//:other");
    BuildRuleParams otherLibDepParams = new FakeBuildRuleParamsBuilder(otherLibDepTarget).setDeclaredDeps(ImmutableSortedSet.of(libRule)).build();
    ImmutableList<CxxPreprocessorInput> otherInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(otherLibDepParams, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMultimap.of(), ImmutableList.of(), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, FluentIterable.from(otherLibDepParams.getDeps()).filter(CxxPreprocessorDep.class::isInstance)), ImmutableList.of(), Optional.empty());
    Set<SourcePath> roots = new HashSet<>();
    for (CxxHeaders headers : CxxPreprocessorInput.concat(otherInput).getIncludes()) {
        roots.add(headers.getRoot());
    }
    assertThat("Non-test rule with library dep should include public and not private headers", roots, allOf(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:symlink"))), not(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:privatesymlink"))))));
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with DefaultBuildTargetSourcePath

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

the class CxxDescriptionEnhancerTest method libraryTestIncludesPublicHeadersOfDependenciesOfLibraryUnderTest.

@Test
public void libraryTestIncludesPublicHeadersOfDependenciesOfLibraryUnderTest() throws Exception {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    BuildTarget libTarget = BuildTargetFactory.newInstance("//:lib");
    BuildTarget otherlibTarget = BuildTargetFactory.newInstance("//:otherlib");
    BuildTarget testTarget = BuildTargetFactory.newInstance("//:test");
    BuildRuleParams otherlibParams = new FakeBuildRuleParamsBuilder(otherlibTarget).build();
    FakeCxxLibrary otherlibRule = new FakeCxxLibrary(otherlibParams, BuildTargetFactory.newInstance("//:otherheader"), BuildTargetFactory.newInstance("//:othersymlink"), BuildTargetFactory.newInstance("//:otherprivateheader"), BuildTargetFactory.newInstance("//:otherprivatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // This library has no tests.
    ImmutableSortedSet.of());
    BuildRuleParams libParams = new FakeBuildRuleParamsBuilder(libTarget).setDeclaredDeps(ImmutableSortedSet.of(otherlibRule)).build();
    FakeCxxLibrary libRule = new FakeCxxLibrary(libParams, BuildTargetFactory.newInstance("//:header"), BuildTargetFactory.newInstance("//:symlink"), BuildTargetFactory.newInstance("//:privateheader"), BuildTargetFactory.newInstance("//:privatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // Ensure the test is listed as a dep of the lib.
    ImmutableSortedSet.of(testTarget));
    BuildRuleParams testParams = new FakeBuildRuleParamsBuilder(testTarget).setDeclaredDeps(ImmutableSortedSet.of(libRule)).build();
    ImmutableList<CxxPreprocessorInput> combinedInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(testParams, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMultimap.of(), ImmutableList.of(), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, FluentIterable.from(testParams.getDeps()).filter(CxxPreprocessorDep.class::isInstance)), ImmutableList.of(), Optional.empty());
    Set<SourcePath> roots = new HashSet<>();
    for (CxxHeaders headers : CxxPreprocessorInput.concat(combinedInput).getIncludes()) {
        roots.add(headers.getRoot());
    }
    assertThat("Test of library should include public dependency headers", Iterables.transform(CxxPreprocessorInput.concat(combinedInput).getIncludes(), CxxHeaders::getRoot), allOf(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:othersymlink"))), not(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:otherprivatesymlink"))))));
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)71 Test (org.junit.Test)64 BuildTarget (com.facebook.buck.model.BuildTarget)53 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)26 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)25 SourcePath (com.facebook.buck.rules.SourcePath)25 PathSourcePath (com.facebook.buck.rules.PathSourcePath)22 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)21 TargetGraph (com.facebook.buck.rules.TargetGraph)19 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)18 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)18 Path (java.nio.file.Path)16 BuildRule (com.facebook.buck.rules.BuildRule)11 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)10 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)9 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)8 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)7 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)6 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)5