Search in sources :

Example 61 with TargetGraph

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

the class PrebuiltCxxLibraryDescriptionTest method createBuildRuleDefault.

@Test
public void createBuildRuleDefault() throws Exception {
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET);
    TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
    PrebuiltCxxLibraryDescription.Arg arg = libBuilder.build().getConstructorArg();
    // Verify static native linkable input.
    NativeLinkableInput expectedStaticLinkableInput = NativeLinkableInput.of(ImmutableList.of(FileListableLinkerInputArg.withSourcePathArg(SourcePathArg.of(new PathSourcePath(filesystem, getStaticLibraryPath(arg))))), ImmutableSet.of(), ImmutableSet.of());
    assertEquals(expectedStaticLinkableInput, lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.STATIC));
    // Verify shared native linkable input.
    NativeLinkableInput expectedSharedLinkableInput = NativeLinkableInput.of(ImmutableList.of(SourcePathArg.of(new PathSourcePath(filesystem, getSharedLibraryPath(arg)))), ImmutableSet.of(), ImmutableSet.of());
    assertEquals(expectedSharedLinkableInput, lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.SHARED));
}
Also used : 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) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 62 with TargetGraph

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

the class PrebuiltCxxLibraryDescriptionTest method exportedPlatformHeaders.

@Test
public void exportedPlatformHeaders() throws Exception {
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET).setExportedPlatformHeaders(PatternMatchedCollection.<SourceList>builder().add(Pattern.compile(CXX_PLATFORM.getFlavor().toString()), SourceList.ofNamedSources(ImmutableSortedMap.of("foo.h", new FakeSourcePath("foo.h")))).add(Pattern.compile("DO NOT MATCH ANYTNING"), SourceList.ofNamedSources(ImmutableSortedMap.of("bar.h", new FakeSourcePath("bar.h")))).build());
    TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
    // Verify the preprocessable input is as expected.
    CxxPreprocessorInput input = lib.getCxxPreprocessorInput(CXX_PLATFORM, HeaderVisibility.PUBLIC);
    assertThat(getHeaderNames(input.getIncludes()), Matchers.hasItem(filesystem.getPath("foo.h")));
    assertThat(getHeaderNames(input.getIncludes()), Matchers.not(Matchers.hasItem(filesystem.getPath("bar.h"))));
    assertThat(ImmutableSortedSet.copyOf(input.getDeps(resolver, ruleFinder)), Matchers.equalTo(resolver.getAllRules(getInputRules(lib))));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourceList(com.facebook.buck.rules.coercer.SourceList) 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) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 63 with TargetGraph

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

the class PrebuiltCxxLibraryDescriptionTest method versionSubDir.

@Test
public void versionSubDir() throws Exception {
    BuildTarget dep = BuildTargetFactory.newInstance("//:dep");
    PrebuiltCxxLibraryBuilder depBuilder = new PrebuiltCxxLibraryBuilder(dep);
    PrebuiltCxxLibraryBuilder builder = new PrebuiltCxxLibraryBuilder(TARGET);
    builder.setSelectedVersions(ImmutableMap.of(dep, Version.of("1.0")));
    builder.setVersionedSubDir(VersionMatchedCollection.<String>builder().add(ImmutableMap.of(dep, Version.of("1.0")), "sub-dir").build());
    TargetGraph graph = TargetGraphFactory.newInstance(depBuilder.build(), builder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    depBuilder.build(resolver, filesystem, graph);
    PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) builder.build(resolver, filesystem, graph);
    NativeLinkableInput nativeLinkableInput = lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.STATIC);
    assertThat(Arg.stringify(nativeLinkableInput.getArgs(), pathResolver).get(0), Matchers.equalTo(filesystem.resolve("sub-dir").resolve(getStaticLibraryPath(builder.build().getConstructorArg())).toString()));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) 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) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 64 with TargetGraph

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

the class PrebuiltCxxLibraryDescriptionTest method forceStatic.

@Test
public void forceStatic() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    PrebuiltCxxLibraryBuilder builder = new PrebuiltCxxLibraryBuilder(TARGET).setForceStatic(true);
    TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PrebuiltCxxLibrary prebuiltCxxLibrary = (PrebuiltCxxLibrary) builder.build(resolver, filesystem, targetGraph);
    assertThat(prebuiltCxxLibrary.getPreferredLinkage(CxxPlatformUtils.DEFAULT_PLATFORM), Matchers.equalTo(NativeLinkable.Linkage.STATIC));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) 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 65 with TargetGraph

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

the class PrebuiltCxxLibraryDescriptionTest method nativeLinkableDeps.

@Test
public void nativeLinkableDeps() throws Exception {
    PrebuiltCxxLibraryBuilder depBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep"));
    PrebuiltCxxLibraryBuilder ruleBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:r")).setDeps(ImmutableSortedSet.of(depBuilder.getTarget()));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(depBuilder.build(), ruleBuilder.build());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PrebuiltCxxLibrary dep = (PrebuiltCxxLibrary) depBuilder.build(resolver, filesystem, targetGraph);
    PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) ruleBuilder.build(resolver, filesystem, targetGraph);
    assertThat(rule.getNativeLinkableDepsForPlatform(CxxLibraryBuilder.createDefaultPlatform()), Matchers.contains(dep));
    assertThat(ImmutableList.copyOf(rule.getNativeLinkableExportedDepsForPlatform(CxxLibraryBuilder.createDefaultPlatform())), empty());
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) 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) 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