use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class ProjectGeneratorTest method usingBuildTargetSourcePathInResourceDirsOrFilesDoesNotThrow.
@Test
public void usingBuildTargetSourcePathInResourceDirsOrFilesDoesNotThrow() throws IOException {
BuildTarget buildTarget = BuildTargetFactory.newInstance("//some:rule");
SourcePath sourcePath = new DefaultBuildTargetSourcePath(buildTarget);
TargetNode<?, ?> generatingTarget = ExportFileBuilder.newExportFileBuilder(buildTarget).build();
ImmutableSet<TargetNode<?, ?>> nodes = FluentIterable.from(setupSimpleLibraryWithResources(ImmutableSet.of(sourcePath), ImmutableSet.of(sourcePath))).append(generatingTarget).toSet();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(nodes);
projectGenerator.createXcodeProjects();
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class ProjectGeneratorTest method testResourcesUnderLibrary.
@Test
public void testResourcesUnderLibrary() throws IOException {
BuildTarget fileTarget = BuildTarget.builder(rootPath, "//foo", "file").build();
BuildTarget resourceTarget = BuildTarget.builder(rootPath, "//foo", "res").build();
BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> fileNode = ExportFileBuilder.newExportFileBuilder(fileTarget).build();
TargetNode<?, ?> resourceNode = AppleResourceBuilder.createBuilder(resourceTarget).setDirs(ImmutableSet.of()).setFiles(ImmutableSet.of(new DefaultBuildTargetSourcePath(fileTarget))).build();
TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setDeps(ImmutableSortedSet.of(resourceTarget)).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(fileNode, 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("file"));
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class DefaultJavaLibraryTest method testWhenJavacJarIsProvidedAJavacInMemoryStepIsAdded.
@Test
public void testWhenJavacJarIsProvidedAJavacInMemoryStepIsAdded() throws Exception {
BuildTarget libraryOneTarget = BuildTargetFactory.newInstance("//:libone");
BuildTarget javacTarget = BuildTargetFactory.newInstance("//langtools:javac");
TargetNode<?, ?> javacNode = PrebuiltJarBuilder.createBuilder(javacTarget).setBinaryJar(Paths.get("java/src/com/libone/JavacJar.jar")).build();
TargetNode<?, ?> ruleNode = JavaLibraryBuilder.createBuilder(libraryOneTarget).addSrc(Paths.get("java/src/com/libone/Bar.java")).setCompiler(new DefaultBuildTargetSourcePath(javacTarget)).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(javacNode, ruleNode);
ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
BuildRule javac = ruleResolver.requireRule(javacTarget);
BuildRule rule = ruleResolver.requireRule(libraryOneTarget);
DefaultJavaLibrary buildable = (DefaultJavaLibrary) rule;
ImmutableList<Step> steps = buildable.getBuildSteps(FakeBuildContext.withSourcePathResolver(new SourcePathResolver(new SourcePathRuleFinder(ruleResolver))), new FakeBuildableContext());
assertEquals(10, steps.size());
Javac javacStep = ((JavacStep) steps.get(6)).getJavac();
assertTrue(javacStep instanceof Jsr199Javac);
JarBackedJavac jsrJavac = ((JarBackedJavac) javacStep);
assertEquals(RichStream.from(jsrJavac.getCompilerClassPath()).map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableSet()), ImmutableSet.of(pathResolver.getRelativePath(javac.getSourcePathToOutput())));
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class DefaultClassUsageFileReader method buildJarToAbiJarMap.
private static ImmutableMap<Path, SourcePath> buildJarToAbiJarMap(SourcePathResolver pathResolver, ImmutableSortedSet<BuildRule> deps) {
ImmutableMap.Builder<Path, SourcePath> jarAbsolutePathToAbiJarSourcePathBuilder = ImmutableMap.builder();
for (BuildRule dep : deps) {
if (!(dep instanceof HasJavaAbi)) {
continue;
}
HasJavaAbi depWithJavaAbi = (HasJavaAbi) dep;
Optional<BuildTarget> depAbiJar = depWithJavaAbi.getAbiJar();
if (!depAbiJar.isPresent()) {
continue;
}
Path jarAbsolutePath = pathResolver.getAbsolutePath(Preconditions.checkNotNull(dep.getSourcePathToOutput()));
jarAbsolutePathToAbiJarSourcePathBuilder.put(jarAbsolutePath, new DefaultBuildTargetSourcePath(depAbiJar.get()));
}
return jarAbsolutePathToAbiJarSourcePathBuilder.build();
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class CxxBinaryDescriptionTest method createBuildRule.
@Test
public void createBuildRule() throws Exception {
Assume.assumeFalse("this test is not for sandboxing", cxxBuckConfig.sandboxSources());
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
CxxPlatform cxxPlatform = CxxBinaryBuilder.createDefaultPlatform();
// Setup a genrule the generates a header we'll list.
String genHeaderName = "test/foo.h";
BuildTarget genHeaderTarget = BuildTargetFactory.newInstance("//:genHeader");
GenruleBuilder genHeaderBuilder = GenruleBuilder.newGenruleBuilder(genHeaderTarget).setOut(genHeaderName);
// Setup a genrule the generates a source we'll list.
String genSourceName = "test/foo.cpp";
BuildTarget genSourceTarget = BuildTargetFactory.newInstance("//:genSource");
GenruleBuilder genSourceBuilder = GenruleBuilder.newGenruleBuilder(genSourceTarget).setOut(genSourceName);
// Setup a C/C++ library that we'll depend on form the C/C++ binary description.
BuildTarget depTarget = BuildTargetFactory.newInstance("//:dep");
CxxLibraryBuilder depBuilder = new CxxLibraryBuilder(depTarget).setExportedHeaders(SourceList.ofUnnamedSources(ImmutableSortedSet.of(new FakeSourcePath("blah.h")))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("test.cpp"))));
BuildTarget archiveTarget = BuildTarget.builder(depTarget).addFlavors(CxxDescriptionEnhancer.STATIC_FLAVOR).addFlavors(cxxPlatform.getFlavor()).build();
BuildTarget headerSymlinkTreeTarget = BuildTarget.builder(depTarget).addFlavors(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR).addFlavors(CxxPreprocessables.HeaderMode.SYMLINK_TREE_ONLY.getFlavor()).build();
// Setup the build params we'll pass to description when generating the build rules.
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(target, cxxBuckConfig).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("test/bar.cpp")), SourceWithFlags.of(new DefaultBuildTargetSourcePath(genSourceTarget)))).setHeaders(ImmutableSortedSet.of(new FakeSourcePath("test/bar.h"), new DefaultBuildTargetSourcePath(genHeaderTarget))).setDeps(ImmutableSortedSet.of(depTarget));
// Create the target graph.
TargetGraph targetGraph = TargetGraphFactory.newInstance(genHeaderBuilder.build(), genSourceBuilder.build(), depBuilder.build(), cxxBinaryBuilder.build());
// Create the build rules.
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
genHeaderBuilder.build(resolver, projectFilesystem, targetGraph);
genSourceBuilder.build(resolver, projectFilesystem, targetGraph);
depBuilder.build(resolver, projectFilesystem, targetGraph);
CxxBinary binRule = cxxBinaryBuilder.build(resolver, projectFilesystem, targetGraph);
assertThat(binRule.getLinkRule(), Matchers.instanceOf(CxxLink.class));
CxxLink rule = (CxxLink) binRule.getLinkRule();
CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactory.builder().setParams(cxxBinaryBuilder.createBuildRuleParams(resolver, projectFilesystem)).setResolver(resolver).setPathResolver(pathResolver).setRuleFinder(ruleFinder).setCxxBuckConfig(CxxPlatformUtils.DEFAULT_CONFIG).setCxxPlatform(cxxPlatform).setPicType(CxxSourceRuleFactory.PicType.PDC).build();
// Check that link rule has the expected deps: the object files for our sources and the
// archive from the dependency.
assertEquals(ImmutableSet.of(cxxSourceRuleFactory.createCompileBuildTarget("test/bar.cpp"), cxxSourceRuleFactory.createCompileBuildTarget(genSourceName), archiveTarget), rule.getDeps().stream().map(BuildRule::getBuildTarget).collect(MoreCollectors.toImmutableSet()));
// Verify that the compile rule for our user-provided source has correct deps setup
// for the various header rules.
BuildRule compileRule1 = resolver.getRule(cxxSourceRuleFactory.createCompileBuildTarget("test/bar.cpp"));
assertNotNull(compileRule1);
assertThat(DependencyAggregationTestUtil.getDisaggregatedDeps(compileRule1).map(BuildRule::getBuildTarget).collect(MoreCollectors.toImmutableSet()), Matchers.containsInAnyOrder(genHeaderTarget, headerSymlinkTreeTarget, CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor())));
// Verify that the compile rule for our genrule-generated source has correct deps setup
// for the various header rules and the generating genrule.
BuildRule compileRule2 = resolver.getRule(cxxSourceRuleFactory.createCompileBuildTarget(genSourceName));
assertNotNull(compileRule2);
assertThat(DependencyAggregationTestUtil.getDisaggregatedDeps(compileRule2).map(BuildRule::getBuildTarget).collect(MoreCollectors.toImmutableList()), Matchers.containsInAnyOrder(genHeaderTarget, genSourceTarget, headerSymlinkTreeTarget, CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor())));
}
Aggregations