Search in sources :

Example 36 with FakeBuildRuleParamsBuilder

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());
}
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) Genrule(com.facebook.buck.shell.Genrule) 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 37 with FakeBuildRuleParamsBuilder

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()));
    }
}
Also used : 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) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 38 with FakeBuildRuleParamsBuilder

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));
}
Also used : 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)

Example 39 with FakeBuildRuleParamsBuilder

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));
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) 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)

Example 40 with FakeBuildRuleParamsBuilder

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));
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) 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