use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CxxLinkableEnhancerTest method testThatBuildTargetSourcePathDepsAndPathsArePropagated.
@Test
public void testThatBuildTargetSourcePathDepsAndPathsArePropagated() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
// Create a couple of genrules to generate inputs for an archive rule.
Genrule genrule1 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setOut("foo/bar.o").build(resolver);
Genrule genrule2 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule2")).setOut("foo/test.o").build(resolver);
// Build the archive using a normal input the outputs of the genrules above.
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
CxxLink cxxLink = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, CXX_PLATFORM, params, resolver, new SourcePathResolver(ruleFinder), ruleFinder, target, Linker.LinkType.EXECUTABLE, Optional.empty(), DEFAULT_OUTPUT, Linker.LinkableDepType.STATIC, EMPTY_DEPS, Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(SourcePathArg.from(new FakeSourcePath("simple.o"), genrule1.getSourcePathToOutput(), genrule2.getSourcePathToOutput())).build());
// Verify that the archive dependencies include the genrules providing the
// SourcePath inputs.
assertEquals(ImmutableSortedSet.<BuildRule>of(genrule1, genrule2), cxxLink.getDeps());
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CxxLinkableEnhancerTest method platformLdFlags.
@Test
public void platformLdFlags() throws Exception {
ImmutableMap<Linker.LinkableDepType, String> runtimes = ImmutableMap.of(Linker.LinkableDepType.SHARED, "-ldummy-shared-libc", Linker.LinkableDepType.STATIC, "-ldummy-static-libc", Linker.LinkableDepType.STATIC_PIC, "-ldummy-static-pic-libc");
CxxPlatform cxxPlatform = CxxPlatform.builder().from(CXX_PLATFORM).putAllRuntimeLdflags(runtimes.asMultimap()).build();
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
for (Map.Entry<Linker.LinkableDepType, String> ent : runtimes.entrySet()) {
CxxLink lib = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, cxxPlatform, params, ruleResolver, pathResolver, ruleFinder, target, Linker.LinkType.SHARED, Optional.empty(), DEFAULT_OUTPUT, ent.getKey(), EMPTY_DEPS, Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(DEFAULT_INPUTS).build());
assertThat(Arg.stringify(lib.getArgs(), pathResolver), hasItem(ent.getValue()));
}
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CxxLinkableEnhancerTest method createCxxLinkableBuildRuleStaticVsSharedDeps.
@Test
public void createCxxLinkableBuildRuleStaticVsSharedDeps() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
// Create a native linkable dep and have it list the fake build rule above as a link
// time dependency
String staticArg = "static";
NativeLinkableInput staticInput = NativeLinkableInput.of(ImmutableList.of(StringArg.of(staticArg)), ImmutableSet.of(), ImmutableSet.of());
String sharedArg = "shared";
NativeLinkableInput sharedInput = NativeLinkableInput.of(ImmutableList.of(StringArg.of(sharedArg)), ImmutableSet.of(), ImmutableSet.of());
FakeNativeLinkable nativeLinkable = createNativeLinkable("//:dep", pathResolver, staticInput, sharedInput);
// Construct a CxxLink object which links using static dependencies.
CxxLink staticLink = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, CXX_PLATFORM, params, ruleResolver, pathResolver, ruleFinder, target, Linker.LinkType.EXECUTABLE, Optional.empty(), DEFAULT_OUTPUT, Linker.LinkableDepType.STATIC, ImmutableList.<NativeLinkable>of(nativeLinkable), Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(DEFAULT_INPUTS).build());
ImmutableList<String> args = Arg.stringify(staticLink.getArgs(), pathResolver);
assertTrue(args.contains(staticArg) || args.contains("-Wl," + staticArg));
assertFalse(args.contains(sharedArg));
assertFalse(args.contains("-Wl," + sharedArg));
// Construct a CxxLink object which links using shared dependencies.
CxxLink sharedLink = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, CXX_PLATFORM, params, ruleResolver, pathResolver, ruleFinder, target, Linker.LinkType.EXECUTABLE, Optional.empty(), DEFAULT_OUTPUT, Linker.LinkableDepType.SHARED, ImmutableList.<NativeLinkable>of(nativeLinkable), Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(DEFAULT_INPUTS).build());
args = Arg.stringify(sharedLink.getArgs(), pathResolver);
assertFalse(args.contains(staticArg));
assertFalse(args.contains("-Wl," + staticArg));
assertTrue(args.contains(sharedArg) || args.contains("-Wl," + sharedArg));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CxxLinkableEnhancerTest method testThatBuildTargetsFromNativeLinkableDepsContributeToActualDeps.
@Test
public void testThatBuildTargetsFromNativeLinkableDepsContributeToActualDeps() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
// Create a dummy build rule and add it to the resolver.
BuildTarget fakeBuildTarget = BuildTargetFactory.newInstance("//:fake");
FakeBuildRule fakeBuildRule = new FakeBuildRule(new FakeBuildRuleParamsBuilder(fakeBuildTarget).build(), pathResolver);
fakeBuildRule.setOutputFile("foo");
resolver.addToIndex(fakeBuildRule);
// Create a native linkable dep and have it list the fake build rule above as a link
// time dependency.
NativeLinkableInput nativeLinkableInput = NativeLinkableInput.of(ImmutableList.of(SourcePathArg.of(fakeBuildRule.getSourcePathToOutput())), ImmutableSet.of(), ImmutableSet.of());
FakeNativeLinkable nativeLinkable = createNativeLinkable("//:dep", pathResolver, nativeLinkableInput, nativeLinkableInput);
// Construct a CxxLink object and pass the native linkable above as the dep.
CxxLink cxxLink = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, CXX_PLATFORM, params, resolver, pathResolver, ruleFinder, target, Linker.LinkType.EXECUTABLE, Optional.empty(), DEFAULT_OUTPUT, Linker.LinkableDepType.STATIC, ImmutableList.<NativeLinkable>of(nativeLinkable), Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(DEFAULT_INPUTS).build());
// Verify that the fake build rule made it in as a dep.
assertTrue(cxxLink.getDeps().contains(fakeBuildRule));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class OmnibusTest method includedDeps.
@Test
public void includedDeps() throws NoSuchBuildTargetException {
NativeLinkable a = new OmnibusNode("//:a");
NativeLinkable b = new OmnibusNode("//:b");
NativeLinkTarget root = new OmnibusRootNode("//:root", ImmutableList.of(a, b));
// Verify the spec.
Omnibus.OmnibusSpec spec = Omnibus.buildSpec(CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(root), ImmutableList.of());
assertThat(spec.getGraph().getNodes(), Matchers.containsInAnyOrder(a.getBuildTarget(), b.getBuildTarget()));
assertThat(spec.getBody().keySet(), Matchers.containsInAnyOrder(a.getBuildTarget(), b.getBuildTarget()));
assertThat(spec.getRoots().keySet(), Matchers.containsInAnyOrder(root.getBuildTarget()));
assertThat(spec.getDeps().keySet(), Matchers.empty());
assertThat(spec.getExcluded().keySet(), Matchers.empty());
// Verify the libs.
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableMap<String, SourcePath> libs = toSonameMap(Omnibus.getSharedLibraries(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:rule")).build(), resolver, ruleFinder, CxxPlatformUtils.DEFAULT_CONFIG, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(), ImmutableList.of(root), ImmutableList.of()));
assertThat(libs.keySet(), Matchers.containsInAnyOrder(root.getBuildTarget().toString(), "libomnibus.so"));
assertCxxLinkContainsNativeLinkableInput(getCxxLinkRule(ruleFinder, libs.get(root.getBuildTarget().toString())), pathResolver, root.getNativeLinkTargetInput(CxxPlatformUtils.DEFAULT_PLATFORM));
assertCxxLinkContainsNativeLinkableInput(getCxxLinkRule(ruleFinder, libs.get("libomnibus.so")), pathResolver, a.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC_PIC), b.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC_PIC));
}
Aggregations