use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class CxxGenruleDescriptionTest method cxxGenruleInLocationMacro.
@Test
public void cxxGenruleInLocationMacro() throws Exception {
CxxGenruleBuilder depBuilder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out");
CxxGenruleBuilder builder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setCmd("$(location //:dep)").setOut("out");
TargetGraph targetGraph = TargetGraphFactory.newInstance(depBuilder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
CxxGenrule dep = (CxxGenrule) resolver.requireRule(depBuilder.getTarget());
CxxGenrule rule = (CxxGenrule) resolver.requireRule(builder.getTarget());
Genrule genrule = (Genrule) ruleFinder.getRule(rule.getGenrule(CxxPlatformUtils.DEFAULT_PLATFORM)).orElseThrow(AssertionError::new);
assertThat(Arg.stringify(OptionalCompat.asSet(genrule.getCmd()), pathResolver), Matchers.contains(pathResolver.getAbsolutePath(dep.getGenrule(CxxPlatformUtils.DEFAULT_PLATFORM)).toString()));
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class CxxLibraryDescriptionTest method nativeLinkTargetMode.
@Test
public void nativeLinkTargetMode() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
CxxLibrary rule = (CxxLibrary) new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule"), cxxBuckConfig).setSoname("libsoname.so").build(resolver);
assertThat(rule.getNativeLinkTargetMode(CxxPlatformUtils.DEFAULT_PLATFORM), equalTo(NativeLinkTargetMode.library("libsoname.so")));
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class CxxLibraryDescriptionTest method forceStatic.
@Test
public void forceStatic() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule"), cxxBuckConfig).setPreferredLinkage(NativeLinkable.Linkage.STATIC);
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(cxxLibraryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
CxxLibrary rule = (CxxLibrary) cxxLibraryBuilder.build(resolver, filesystem);
assertThat(rule.getPreferredLinkage(CxxPlatformUtils.DEFAULT_PLATFORM), equalTo(NativeLinkable.Linkage.STATIC));
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class CxxLibraryDescriptionTest method exportedDepsArePropagatedToRuntimeDeps.
@Test
public void exportedDepsArePropagatedToRuntimeDeps() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:dep"));
CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:lib"), cxxBuckConfig).setExportedDeps(ImmutableSortedSet.of(cxxBinaryBuilder.getTarget()));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(cxxLibraryBuilder.build(), cxxBinaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
cxxBinaryBuilder.build(resolver, filesystem);
CxxLibrary cxxLibrary = (CxxLibrary) cxxLibraryBuilder.build(resolver, filesystem);
assertThat(cxxLibrary.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), hasItem(cxxBinaryBuilder.getTarget()));
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class CxxLibraryDescriptionTest method linkerFlagsLocationMacro.
@Test
public void linkerFlagsLocationMacro() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget target = BuildTargetFactory.newInstance("//:rule").withFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR, CxxPlatformUtils.DEFAULT_PLATFORM.getFlavor());
GenruleBuilder depBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out");
CxxLibraryBuilder builder = new CxxLibraryBuilder(target, cxxBuckConfig).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(depBuilder.getTarget())))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.c"))));
TargetGraph targetGraph = TargetGraphFactory.newInstance(depBuilder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Genrule dep = depBuilder.build(resolver, filesystem, targetGraph);
assertThat(builder.build().getExtraDeps(), hasItem(dep.getBuildTarget()));
BuildRule binary = builder.build(resolver, filesystem, targetGraph);
assertThat(binary, instanceOf(CxxLink.class));
assertThat(Arg.stringify(((CxxLink) binary).getArgs(), pathResolver), hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
assertThat(binary.getDeps(), hasItem(dep));
}
Aggregations