Search in sources :

Example 91 with FakeBuildRuleParamsBuilder

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());
}
Also used : FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) Path(java.nio.file.Path) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 92 with FakeBuildRuleParamsBuilder

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);
}
Also used : DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) SanitizedArg(com.facebook.buck.rules.args.SanitizedArg) Arg(com.facebook.buck.rules.args.Arg) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SanitizedArg(com.facebook.buck.rules.args.SanitizedArg) Test(org.junit.Test)

Example 93 with FakeBuildRuleParamsBuilder

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);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) HashedFileTool(com.facebook.buck.rules.HashedFileTool) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 94 with FakeBuildRuleParamsBuilder

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()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 95 with FakeBuildRuleParamsBuilder

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));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)108 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)102 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)102 Test (org.junit.Test)94 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)87 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)78 BuildTarget (com.facebook.buck.model.BuildTarget)77 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)74 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)50 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)32 SourcePath (com.facebook.buck.rules.SourcePath)30 BuildRule (com.facebook.buck.rules.BuildRule)27 Path (java.nio.file.Path)26 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)25 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)22 PathSourcePath (com.facebook.buck.rules.PathSourcePath)18 Step (com.facebook.buck.step.Step)17 RuleKey (com.facebook.buck.rules.RuleKey)16 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)15 ExecutionContext (com.facebook.buck.step.ExecutionContext)14