use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class HalideLibraryDescriptionTest method testCreateBuildRule.
@Test
public void testCreateBuildRule() throws Exception {
// Set up a #halide-compiler rule, then set up a halide_library rule, and
// check that the library rule depends on the compiler rule.
BuildTarget compilerTarget = BuildTargetFactory.newInstance("//:rule").withFlavors(HalideLibraryDescription.HALIDE_COMPILER_FLAVOR);
BuildTarget libTarget = BuildTargetFactory.newInstance("//:rule");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
HalideLibraryBuilder compilerBuilder = new HalideLibraryBuilder(compilerTarget);
compilerBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("main.cpp"))));
HalideLibraryBuilder libBuilder = new HalideLibraryBuilder(libTarget);
TargetGraph targetGraph = TargetGraphFactory.newInstance(compilerBuilder.build(), libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
HalideLibrary lib = (HalideLibrary) libBuilder.build(resolver, filesystem, targetGraph);
// Check that the library rule has the correct preprocessor input.
CxxPlatform cxxPlatform = CxxLibraryBuilder.createDefaultPlatform();
String headerName = "rule.h";
BuildTarget flavoredLibTarget = libTarget.withFlavors(HalideLibraryDescription.HALIDE_COMPILE_FLAVOR, cxxPlatform.getFlavor());
Path headerPath = HalideCompile.headerOutputPath(flavoredLibTarget, lib.getProjectFilesystem(), Optional.empty());
CxxSymlinkTreeHeaders publicHeaders = (CxxSymlinkTreeHeaders) lib.getCxxPreprocessorInput(cxxPlatform, HeaderVisibility.PUBLIC).getIncludes().get(0);
assertThat(publicHeaders.getIncludeType(), Matchers.equalTo(CxxPreprocessables.IncludeType.SYSTEM));
assertThat(publicHeaders.getNameToPathMap(), Matchers.equalTo(ImmutableMap.<Path, SourcePath>of(Paths.get(headerName), new ExplicitBuildTargetSourcePath(flavoredLibTarget, headerPath))));
// Check that the library rule has the correct native linkable input.
NativeLinkableInput input = lib.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.STATIC);
BuildRule buildRule = FluentIterable.from(input.getArgs()).transformAndConcat(arg -> arg.getDeps(new SourcePathRuleFinder(resolver))).get(0);
assertThat(buildRule, is(instanceOf(Archive.class)));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class HaskellPrebuiltLibraryDescriptionTest method staticLibraries.
@Test
public void staticLibraries() throws Exception {
PathSourcePath lib = new FakeSourcePath("libfoo.a");
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
PrebuiltHaskellLibraryBuilder builder = new PrebuiltHaskellLibraryBuilder(target).setVersion("1.0.0").setDb(new FakeSourcePath("package.conf.d")).setStaticLibs(ImmutableList.of(lib));
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltHaskellLibrary library = builder.build(resolver, filesystem, targetGraph);
NativeLinkableInput input = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC);
assertThat(RichStream.from(input.getArgs()).flatMap(a -> a.getInputs().stream()).toImmutableSet(), Matchers.contains(lib));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class HaskellPrebuiltLibraryDescriptionTest method cxxHeaderDirs.
@Test
public void cxxHeaderDirs() throws Exception {
PathSourcePath interfaces = new FakeSourcePath("interfaces");
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
PathSourcePath path = new FakeSourcePath("include_dir");
PrebuiltHaskellLibraryBuilder builder = new PrebuiltHaskellLibraryBuilder(target).setVersion("1.0.0").setDb(new FakeSourcePath("package.conf.d")).setImportDirs(ImmutableList.of(interfaces)).setCxxHeaderDirs(ImmutableSortedSet.of(path));
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltHaskellLibrary library = builder.build(resolver, filesystem, targetGraph);
assertThat(library.getCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, HeaderVisibility.PUBLIC), Matchers.equalTo(CxxPreprocessorInput.builder().addIncludes(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, path)).build()));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class HaskellPrebuiltLibraryDescriptionTest method exportedLinkerFlags.
@Test
public void exportedLinkerFlags() throws Exception {
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
String flag = "-exported-linker-flags";
PrebuiltHaskellLibraryBuilder builder = new PrebuiltHaskellLibraryBuilder(target).setVersion("1.0.0").setDb(new FakeSourcePath("package.conf.d")).setExportedLinkerFlags(ImmutableList.of(flag));
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
PrebuiltHaskellLibrary library = builder.build(resolver, filesystem, targetGraph);
NativeLinkableInput staticInput = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC);
assertThat(Arg.stringify(staticInput.getArgs(), pathResolver), Matchers.contains(flag));
NativeLinkableInput sharedInput = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.SHARED);
assertThat(Arg.stringify(sharedInput.getArgs(), pathResolver), Matchers.contains(flag));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class HaskellPrebuiltLibraryDescriptionTest method interfaces.
@Test
public void interfaces() throws Exception {
PathSourcePath interfaces = new FakeSourcePath("interfaces");
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
PrebuiltHaskellLibraryBuilder builder = new PrebuiltHaskellLibraryBuilder(target).setVersion("1.0.0").setDb(new FakeSourcePath("package.conf.d")).setImportDirs(ImmutableList.of(interfaces));
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltHaskellLibrary library = builder.build(resolver, filesystem, targetGraph);
HaskellCompileInput input = library.getCompileInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC);
assertThat(input.getPackages().get(0).getInterfaces(), Matchers.contains(interfaces));
}
Aggregations