use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class CxxLinkableEnhancerTest method testThatOriginalBuildParamsDepsDoNotPropagateToArchive.
@Test
public void testThatOriginalBuildParamsDepsDoNotPropagateToArchive() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
// Create an `Archive` rule using build params with an existing dependency,
// as if coming from a `TargetNode` which had declared deps. These should *not*
// propagate to the `Archive` rule, since it only cares about dependencies generating
// it's immediate inputs.
BuildRule dep = new FakeBuildRule(new FakeBuildRuleParamsBuilder("//:fake").build(), pathResolver);
BuildTarget target = BuildTargetFactory.newInstance("//:archive");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:dummy")).setDeclaredDeps(ImmutableSortedSet.of(dep)).build();
CxxLink cxxLink = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, CXX_PLATFORM, params, ruleResolver, pathResolver, ruleFinder, target, Linker.LinkType.EXECUTABLE, Optional.empty(), DEFAULT_OUTPUT, Linker.LinkableDepType.STATIC, EMPTY_DEPS, Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(DEFAULT_INPUTS).build());
// Verify that the archive rules dependencies are empty.
assertEquals(cxxLink.getDeps(), ImmutableSortedSet.<BuildRule>of());
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class CxxLinkableEnhancerTest method createCxxLinkableBuildRuleExecutableVsShared.
@Test
public void createCxxLinkableBuildRuleExecutableVsShared() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
String soname = "soname";
ImmutableList<String> sonameArgs = ImmutableList.copyOf(CXX_PLATFORM.getLd().resolve(ruleResolver).soname(soname));
// Construct a CxxLink object which links as an executable.
CxxLink executable = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, CXX_PLATFORM, params, ruleResolver, pathResolver, ruleFinder, target, Linker.LinkType.EXECUTABLE, Optional.empty(), DEFAULT_OUTPUT, Linker.LinkableDepType.STATIC, EMPTY_DEPS, Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(DEFAULT_INPUTS).build());
assertFalse(executable.getArgs().contains(StringArg.of("-shared")));
assertEquals(Collections.indexOfSubList(executable.getArgs(), sonameArgs), -1);
// Construct a CxxLink object which links as a shared lib.
CxxLink shared = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, CXX_PLATFORM, params, ruleResolver, pathResolver, ruleFinder, target, Linker.LinkType.SHARED, Optional.empty(), DEFAULT_OUTPUT, Linker.LinkableDepType.STATIC, EMPTY_DEPS, Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(DEFAULT_INPUTS).build());
assertTrue(Arg.stringify(shared.getArgs(), pathResolver).contains("-shared"));
assertEquals(Collections.indexOfSubList(shared.getArgs(), sonameArgs), -1);
// Construct a CxxLink object which links as a shared lib with a SONAME.
CxxLink sharedWithSoname = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, CXX_PLATFORM, params, ruleResolver, pathResolver, ruleFinder, target, Linker.LinkType.SHARED, Optional.of("soname"), DEFAULT_OUTPUT, Linker.LinkableDepType.STATIC, EMPTY_DEPS, Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(DEFAULT_INPUTS).build());
ImmutableList<String> args = Arg.stringify(sharedWithSoname.getArgs(), pathResolver);
assertTrue(args.contains("-shared"));
assertNotEquals(Collections.indexOfSubList(args, sonameArgs), -1);
}
use of com.facebook.buck.rules.BuildRuleParams 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.BuildRuleParams 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.BuildRuleParams 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));
}
Aggregations