Search in sources :

Example 46 with DefaultBuildTargetSourcePath

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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 47 with DefaultBuildTargetSourcePath

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"));
}
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 48 with DefaultBuildTargetSourcePath

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())));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) TargetGraph(com.facebook.buck.rules.TargetGraph) Step(com.facebook.buck.step.Step) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 49 with DefaultBuildTargetSourcePath

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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 50 with DefaultBuildTargetSourcePath

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())));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) 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