Search in sources :

Example 41 with DefaultBuildTargetSourcePath

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

the class ExportFileTest method shouldSetInputsFromSourcePaths.

@Test
public void shouldSetInputsFromSourcePaths() throws Exception {
    ExportFileBuilder builder = ExportFileBuilder.newExportFileBuilder(target).setSrc(new FakeSourcePath("chips")).setOut("cake");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    ExportFile exportFile = builder.build(resolver, projectFilesystem);
    assertIterablesEquals(singleton(Paths.get("chips")), pathResolver.filterInputsToCompareToOutput(exportFile.getSource()));
    resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule rule = resolver.addToIndex(new FakeBuildRule(BuildTargetFactory.newInstance("//example:one"), pathResolver));
    builder.setSrc(new DefaultBuildTargetSourcePath(rule.getBuildTarget()));
    exportFile = builder.build(resolver, projectFilesystem);
    assertThat(pathResolver.filterInputsToCompareToOutput(exportFile.getSource()), Matchers.empty());
    resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    builder.setSrc(null);
    exportFile = builder.build(resolver, projectFilesystem);
    assertIterablesEquals(singleton(projectFilesystem.getPath("example.html")), pathResolver.filterInputsToCompareToOutput(exportFile.getSource()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 42 with DefaultBuildTargetSourcePath

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

the class RustLibraryDescriptionTest method testGeneratedSourceFromCxxGenrule.

@Test
public void testGeneratedSourceFromCxxGenrule() throws NoSuchBuildTargetException {
    CxxGenruleBuilder srcBuilder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:src")).setOut("lib.rs");
    RustLibraryBuilder libraryBuilder = RustLibraryBuilder.from("//:lib").setSrcs(ImmutableSortedSet.of(new DefaultBuildTargetSourcePath(srcBuilder.getTarget())));
    RustBinaryBuilder binaryBuilder = RustBinaryBuilder.from("//:bin").setSrcs(ImmutableSortedSet.of(new FakeSourcePath("main.rs"))).setDeps(ImmutableSortedSet.of(libraryBuilder.getTarget()));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(srcBuilder.build(), libraryBuilder.build(), binaryBuilder.build());
    BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    ruleResolver.requireRule(binaryBuilder.getTarget());
}
Also used : CxxGenruleBuilder(com.facebook.buck.cxx.CxxGenruleBuilder) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 43 with DefaultBuildTargetSourcePath

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

the class TargetNodeTranslator method translateBuildTargetSourcePath.

public Optional<DefaultBuildTargetSourcePath> translateBuildTargetSourcePath(CellPathResolver cellPathResolver, BuildTargetPatternParser<BuildTargetPattern> pattern, DefaultBuildTargetSourcePath val) {
    BuildTarget target = val.getTarget();
    Optional<BuildTarget> translatedTarget = translate(cellPathResolver, pattern, target);
    return translatedTarget.isPresent() ? Optional.of(new DefaultBuildTargetSourcePath(translatedTarget.get())) : Optional.empty();
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath)

Example 44 with DefaultBuildTargetSourcePath

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

the class ProjectGeneratorTest method resourceDirectoriesDontHaveFolderTypeIfTheyCanHaveAMoreSpecificType.

@Test
public void resourceDirectoriesDontHaveFolderTypeIfTheyCanHaveAMoreSpecificType() throws IOException {
    BuildTarget directoryTarget = BuildTarget.builder(rootPath, "//foo", "dir.iconset").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.iconset"));
    assertThat(resource.getExplicitFileType(), not(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 45 with DefaultBuildTargetSourcePath

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

the class ProjectGeneratorTest method testCxxLibraryHeaderGroupsWithMapsOfHeaders.

@Test
public void testCxxLibraryHeaderGroupsWithMapsOfHeaders() 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()).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("foo/yet/another/name.h", "foo/dir1/bar.h", "foo/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("foo/any/name.h", "foo/dir1/foo.h", "foo/different/name.h", "foo/dir2/baz.h", "foo/one/more/name.h", "foo/generated1.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) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) 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