use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CxxLibraryTest method cxxLibraryInterfaces.
@Test
public void cxxLibraryInterfaces() {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
CxxPlatform cxxPlatform = CxxPlatformUtils.build(new CxxBuckConfig(FakeBuckConfig.builder().build()));
// Setup some dummy values for the header info.
final BuildTarget publicHeaderTarget = BuildTargetFactory.newInstance("//:header");
final BuildTarget publicHeaderSymlinkTreeTarget = BuildTargetFactory.newInstance("//:symlink");
final BuildTarget privateHeaderTarget = BuildTargetFactory.newInstance("//:privateheader");
final BuildTarget privateHeaderSymlinkTreeTarget = BuildTargetFactory.newInstance("//:privatesymlink");
// Setup some dummy values for the library archive info.
final BuildRule archive = new FakeBuildRule("//:archive", pathResolver).setOutputFile("libarchive.a");
// Setup some dummy values for the library archive info.
final BuildRule sharedLibrary = new FakeBuildRule("//:shared", pathResolver).setOutputFile("libshared.so");
final Path sharedLibraryOutput = Paths.get("output/path/lib.so");
final String sharedLibrarySoname = "lib.so";
// Construct a CxxLibrary object to test.
FakeCxxLibrary cxxLibrary = new FakeCxxLibrary(params, publicHeaderTarget, publicHeaderSymlinkTreeTarget, privateHeaderTarget, privateHeaderSymlinkTreeTarget, archive, sharedLibrary, sharedLibraryOutput, sharedLibrarySoname, ImmutableSortedSet.of());
// Verify that we get the header/symlink targets and root via the CxxPreprocessorDep
// interface.
CxxPreprocessorInput expectedPublicCxxPreprocessorInput = CxxPreprocessorInput.builder().addIncludes(CxxSymlinkTreeHeaders.builder().setIncludeType(CxxPreprocessables.IncludeType.LOCAL).putNameToPathMap(Paths.get("header.h"), new DefaultBuildTargetSourcePath(publicHeaderTarget)).setRoot(new DefaultBuildTargetSourcePath(publicHeaderSymlinkTreeTarget)).build()).build();
assertEquals(expectedPublicCxxPreprocessorInput, cxxLibrary.getCxxPreprocessorInput(cxxPlatform, HeaderVisibility.PUBLIC));
CxxPreprocessorInput expectedPrivateCxxPreprocessorInput = CxxPreprocessorInput.builder().addIncludes(CxxSymlinkTreeHeaders.builder().setIncludeType(CxxPreprocessables.IncludeType.LOCAL).setRoot(new DefaultBuildTargetSourcePath(privateHeaderSymlinkTreeTarget)).putNameToPathMap(Paths.get("header.h"), new DefaultBuildTargetSourcePath(privateHeaderTarget)).build()).build();
assertEquals(expectedPrivateCxxPreprocessorInput, cxxLibrary.getCxxPreprocessorInput(cxxPlatform, HeaderVisibility.PRIVATE));
// Verify that we get the static archive and its build target via the NativeLinkable
// interface.
NativeLinkableInput expectedStaticNativeLinkableInput = NativeLinkableInput.of(ImmutableList.of(SourcePathArg.of(archive.getSourcePathToOutput())), ImmutableSet.of(), ImmutableSet.of());
assertEquals(expectedStaticNativeLinkableInput, cxxLibrary.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.STATIC));
// Verify that we get the static archive and its build target via the NativeLinkable
// interface.
NativeLinkableInput expectedSharedNativeLinkableInput = NativeLinkableInput.of(ImmutableList.of(SourcePathArg.of(sharedLibrary.getSourcePathToOutput())), ImmutableSet.of(), ImmutableSet.of());
assertEquals(expectedSharedNativeLinkableInput, cxxLibrary.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.SHARED));
// Verify that the implemented BuildRule methods are effectively unused.
assertEquals(ImmutableList.<Step>of(), cxxLibrary.getBuildSteps(null, null));
assertNull(cxxLibrary.getSourcePathToOutput());
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CxxLinkTest method sanitizedPathsInFlagsDoNotAffectRuleKey.
@Test
public void sanitizedPathsInFlagsDoNotAffectRuleKey() {
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();
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.of("ld", Strings.repeat("0", 40), "a.o", Strings.repeat("a", 40), "b.o", Strings.repeat("b", 40), "libc.a", Strings.repeat("c", 40), "different", Strings.repeat("d", 40))), pathResolver, ruleFinder);
// Set up a map to sanitize the differences in the flags.
int pathSize = 10;
DebugPathSanitizer sanitizer1 = new MungingDebugPathSanitizer(pathSize, File.separatorChar, Paths.get("PWD"), ImmutableBiMap.of(Paths.get("something"), Paths.get("A")));
DebugPathSanitizer sanitizer2 = new MungingDebugPathSanitizer(pathSize, File.separatorChar, Paths.get("PWD"), ImmutableBiMap.of(Paths.get("different"), Paths.get("A")));
// Generate a rule with a path we need to sanitize to a consistent value.
ImmutableList<Arg> args1 = ImmutableList.of(new SanitizedArg(sanitizer1.sanitize(Optional.empty()), "-Lsomething/foo"));
RuleKey ruleKey1 = ruleKeyFactory.build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, args1, Optional.empty(), /* cacheable */
true));
// Generate another rule with a different path we need to sanitize to the
// same consistent value as above.
ImmutableList<Arg> args2 = ImmutableList.of(new SanitizedArg(sanitizer2.sanitize(Optional.empty()), "-Ldifferent/foo"));
RuleKey ruleKey2 = ruleKeyFactory.build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, args2, Optional.empty(), /* cacheable */
true));
assertEquals(ruleKey1, ruleKey2);
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CxxLinkTest method testThatInputChangesCauseRuleKeyChanges.
@Test
public void testThatInputChangesCauseRuleKeyChanges() {
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();
FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.of("ld", Strings.repeat("0", 40), "a.o", Strings.repeat("a", 40), "b.o", Strings.repeat("b", 40), "libc.a", Strings.repeat("c", 40), "different", Strings.repeat("d", 40)));
// Generate a rule key for the defaults.
RuleKey defaultRuleKey = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, DEFAULT_ARGS, Optional.empty(), /* cacheable */
true));
// Verify that changing the archiver causes a rulekey change.
RuleKey linkerChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(new CxxLink(params, new GnuLinker(new HashedFileTool(Paths.get("different"))), DEFAULT_OUTPUT, DEFAULT_ARGS, Optional.empty(), /* cacheable */
true));
assertNotEquals(defaultRuleKey, linkerChange);
// Verify that changing the output path causes a rulekey change.
RuleKey outputChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(new CxxLink(params, DEFAULT_LINKER, Paths.get("different"), DEFAULT_ARGS, Optional.empty(), /* cacheable */
true));
assertNotEquals(defaultRuleKey, outputChange);
// Verify that changing the flags causes a rulekey change.
RuleKey flagsChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, ImmutableList.of(SourcePathArg.of(new FakeSourcePath("different"))), Optional.empty(), /* cacheable */
true));
assertNotEquals(defaultRuleKey, flagsChange);
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CxxLinkableEnhancerTest method machOBundleWithBundleLoaderHasExpectedArgs.
@Test
public void machOBundleWithBundleLoaderHasExpectedArgs() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
ProjectFilesystem filesystem = params.getProjectFilesystem();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
CxxLink cxxLink = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, CXX_PLATFORM, params, resolver, new SourcePathResolver(ruleFinder), ruleFinder, target, Linker.LinkType.MACH_O_BUNDLE, Optional.empty(), DEFAULT_OUTPUT, Linker.LinkableDepType.STATIC, EMPTY_DEPS, Optional.empty(), Optional.of(new FakeSourcePath(filesystem, "path/to/MyBundleLoader")), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(SourcePathArg.from(new FakeSourcePath("simple.o"))).build());
assertThat(Arg.stringify(cxxLink.getArgs(), pathResolver), hasItem("-bundle"));
assertThat(Arg.stringify(cxxLink.getArgs(), pathResolver), hasConsecutiveItems("-bundle_loader", filesystem.resolve("path/to/MyBundleLoader").toString()));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CxxLinkableEnhancerTest method machOBundleSourcePathIsInDepsOfRule.
@Test
public void machOBundleSourcePathIsInDepsOfRule() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildTarget bundleLoaderTarget = BuildTargetFactory.newInstance("//foo:bundleLoader");
BuildRuleParams bundleLoaderParams = new FakeBuildRuleParamsBuilder(bundleLoaderTarget).build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
CxxLink bundleLoaderRule = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, CXX_PLATFORM, bundleLoaderParams, resolver, new SourcePathResolver(ruleFinder), ruleFinder, bundleLoaderTarget, 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"))).build());
resolver.addToIndex(bundleLoaderRule);
BuildTarget bundleTarget = BuildTargetFactory.newInstance("//foo:bundle");
BuildRuleParams bundleParams = new FakeBuildRuleParamsBuilder(bundleTarget).build();
CxxLink bundleRule = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, CXX_PLATFORM, bundleParams, resolver, new SourcePathResolver(ruleFinder), ruleFinder, bundleTarget, Linker.LinkType.MACH_O_BUNDLE, Optional.empty(), DEFAULT_OUTPUT, Linker.LinkableDepType.STATIC, EMPTY_DEPS, Optional.empty(), Optional.of(bundleLoaderRule.getSourcePathToOutput()), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(SourcePathArg.from(new FakeSourcePath("another.o"))).build());
// Ensure the bundle depends on the bundle loader rule.
assertThat(bundleRule.getDeps(), hasItem(bundleLoaderRule));
}
Aggregations