use of com.facebook.buck.rules.FakeBuildRule in project buck by facebook.
the class CxxDescriptionEnhancerTest method libraryTestIncludesPrivateHeadersOfLibraryUnderTest.
@Test
public void libraryTestIncludesPrivateHeadersOfLibraryUnderTest() throws Exception {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
BuildTarget libTarget = BuildTargetFactory.newInstance("//:lib");
BuildTarget testTarget = BuildTargetFactory.newInstance("//:test");
BuildRuleParams libParams = new FakeBuildRuleParamsBuilder(libTarget).build();
FakeCxxLibrary libRule = new FakeCxxLibrary(libParams, BuildTargetFactory.newInstance("//:header"), BuildTargetFactory.newInstance("//:symlink"), BuildTargetFactory.newInstance("//:privateheader"), BuildTargetFactory.newInstance("//:privatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // Ensure the test is listed as a dep of the lib.
ImmutableSortedSet.of(testTarget));
BuildRuleParams testParams = new FakeBuildRuleParamsBuilder(testTarget).setDeclaredDeps(ImmutableSortedSet.of(libRule)).build();
ImmutableList<CxxPreprocessorInput> combinedInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(testParams, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMultimap.of(), ImmutableList.of(), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, FluentIterable.from(testParams.getDeps()).filter(CxxPreprocessorDep.class::isInstance)), ImmutableList.of(), Optional.empty());
Set<SourcePath> roots = new HashSet<>();
for (CxxHeaders headers : CxxPreprocessorInput.concat(combinedInput).getIncludes()) {
roots.add(headers.getRoot());
}
assertThat("Test of library should include both public and private headers", roots, Matchers.hasItems(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:symlink")), new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:privatesymlink"))));
}
use of com.facebook.buck.rules.FakeBuildRule in project buck by facebook.
the class CxxLibraryTest method headerOnlyExports.
@Test
public void headerOnlyExports() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
CxxPlatform cxxPlatform = CxxPlatformUtils.build(new CxxBuckConfig(FakeBuckConfig.builder().build()));
BuildTarget staticPicLibraryTarget = params.getBuildTarget().withAppendedFlavors(cxxPlatform.getFlavor(), CxxDescriptionEnhancer.STATIC_PIC_FLAVOR);
ruleResolver.addToIndex(new FakeBuildRule(new FakeBuildRuleParamsBuilder(staticPicLibraryTarget).build(), pathResolver));
FrameworkPath frameworkPath = FrameworkPath.ofSourcePath(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//foo:baz")));
// Construct a CxxLibrary object to test.
CxxLibrary cxxLibrary = new CxxLibrary(params, ruleResolver, FluentIterable.from(params.getDeclaredDeps().get()), /* hasExportedHeaders */
x -> true, /* headerOnly */
x -> true, Functions.constant(StringArg.from("-ldl")), /* linkTargetInput */
Functions.constant(NativeLinkableInput.of()), /* supportedPlatformsRegex */
Optional.empty(), ImmutableSet.of(frameworkPath), ImmutableSet.of(), NativeLinkable.Linkage.STATIC, /* linkWhole */
false, Optional.empty(), ImmutableSortedSet.of(), /* isAsset */
false, true);
NativeLinkableInput expectedSharedNativeLinkableInput = NativeLinkableInput.of(StringArg.from("-ldl"), ImmutableSet.of(frameworkPath), ImmutableSet.of());
assertEquals(expectedSharedNativeLinkableInput, cxxLibrary.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.SHARED));
}
use of com.facebook.buck.rules.FakeBuildRule 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.FakeBuildRule 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.FakeBuildRule in project buck by facebook.
the class NativeLinkablesTest method nonNativeLinkableDepsAreIgnored.
@Test
public void nonNativeLinkableDepsAreIgnored() {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
FakeNativeLinkable c = new FakeNativeLinkable("//:c", ImmutableList.of(), ImmutableList.of(), NativeLinkable.Linkage.ANY, NativeLinkableInput.builder().addAllArgs(StringArg.from("c")).build(), ImmutableMap.of());
FakeBuildRule b = new FakeBuildRule("//:b", pathResolver, c);
FakeNativeLinkable a = new FakeNativeLinkable("//:a", ImmutableList.of(), ImmutableList.of(), NativeLinkable.Linkage.ANY, NativeLinkableInput.builder().addAllArgs(StringArg.from("a")).build(), ImmutableMap.of(), b);
assertThat(a.getDeps(), Matchers.hasItem(b));
assertThat(NativeLinkables.getNativeLinkables(CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(a), Linker.LinkableDepType.STATIC).keySet(), Matchers.not(Matchers.hasItem(c.getBuildTarget())));
}
Aggregations