Search in sources :

Example 71 with TargetGraph

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

the class PrebuiltCxxLibraryDescriptionTest method findDepsFromParamsWithLocation.

@Test
public void findDepsFromParamsWithLocation() throws NoSuchBuildTargetException {
    BuildTarget genTarget = BuildTargetFactory.newInstance("//other:gen_lib");
    GenruleBuilder genruleBuilder = GenruleBuilder.newGenruleBuilder(genTarget).setOut("lib_dir");
    PrebuiltCxxLibraryBuilder builder = new PrebuiltCxxLibraryBuilder(TARGET);
    builder.setSoname("test");
    builder.setLibDir("$(location //other:gen_lib)");
    TargetGraph targetGraph = TargetGraphFactory.newInstance(genruleBuilder.build(), builder.build());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule genrule = genruleBuilder.build(resolver, filesystem, targetGraph);
    PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) builder.build(resolver, filesystem, targetGraph);
    Iterable<BuildTarget> implicit = builder.findImplicitDeps();
    assertEquals(1, Iterables.size(implicit));
    assertTrue(Iterables.contains(implicit, genTarget));
    assertThat(lib.getDeps(), Matchers.contains(genrule));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 72 with TargetGraph

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

the class PrebuiltCxxLibraryDescriptionTest method includesDirs.

@Test
public void includesDirs() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:r")).setIncludeDirs(ImmutableList.of("include"));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
    assertThat(rule.getCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, HeaderVisibility.PUBLIC).getIncludes(), Matchers.contains(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new PathSourcePath(filesystem, rule.getBuildTarget().getBasePath().resolve("include")))));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 73 with TargetGraph

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

the class PrebuiltCxxLibraryDescriptionTest method nativeLinkTargetDeps.

@Test
public void nativeLinkTargetDeps() throws Exception {
    PrebuiltCxxLibraryBuilder depBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep"));
    PrebuiltCxxLibraryBuilder exportedDepBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:exported_dep"));
    PrebuiltCxxLibraryBuilder ruleBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule")).setExportedDeps(ImmutableSortedSet.of(depBuilder.getTarget(), exportedDepBuilder.getTarget()));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(depBuilder.build(), exportedDepBuilder.build(), ruleBuilder.build());
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PrebuiltCxxLibrary dep = (PrebuiltCxxLibrary) depBuilder.build(resolver, filesystem, targetGraph);
    PrebuiltCxxLibrary exportedDep = (PrebuiltCxxLibrary) exportedDepBuilder.build(resolver, filesystem, targetGraph);
    PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) ruleBuilder.build(resolver, filesystem, targetGraph);
    assertThat(ImmutableList.copyOf(rule.getNativeLinkTarget(CXX_PLATFORM).get().getNativeLinkTargetDeps(CXX_PLATFORM)), Matchers.hasItems(dep, exportedDep));
}
Also used : TargetGraph(com.facebook.buck.rules.TargetGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 74 with TargetGraph

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

the class PrebuiltCxxLibraryDescriptionTest method nativeLinkTargetMode.

@Test
public void nativeLinkTargetMode() throws Exception {
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule")).setSoname("libsoname.so");
    TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
    assertThat(rule.getNativeLinkTarget(CXX_PLATFORM).get().getNativeLinkTargetMode(CXX_PLATFORM), Matchers.equalTo(NativeLinkTargetMode.library("libsoname.so")));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 75 with TargetGraph

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

the class PrebuiltCxxLibraryDescriptionTest method headerOnly.

@Test
public void headerOnly() throws Exception {
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET).setHeaderOnly(true);
    TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
    // Verify static native linkable input.
    NativeLinkableInput expectedStaticLinkableInput = NativeLinkableInput.of(ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of());
    assertEquals(expectedStaticLinkableInput, lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.STATIC));
    // Verify shared native linkable input.
    NativeLinkableInput expectedSharedLinkableInput = NativeLinkableInput.of(ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of());
    assertEquals(expectedSharedLinkableInput, lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.SHARED));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Aggregations

TargetGraph (com.facebook.buck.rules.TargetGraph)267 Test (org.junit.Test)230 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)195 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)179 BuildTarget (com.facebook.buck.model.BuildTarget)157 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)126 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)119 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)96 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)88 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)75 BuildRule (com.facebook.buck.rules.BuildRule)60 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)58 Path (java.nio.file.Path)48 PathSourcePath (com.facebook.buck.rules.PathSourcePath)45 TargetNode (com.facebook.buck.rules.TargetNode)44 SourcePath (com.facebook.buck.rules.SourcePath)37 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)36 ImmutableSet (com.google.common.collect.ImmutableSet)29 Optional (java.util.Optional)25 ImmutableList (com.google.common.collect.ImmutableList)24