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()));
}
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());
}
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();
}
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"))));
}
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"));
}
Aggregations