Search in sources :

Example 31 with Genrule

use of com.facebook.buck.shell.Genrule in project buck by facebook.

the class CxxTestDescriptionTest method linkerFlagsLocationMacro.

@Test
public void linkerFlagsLocationMacro() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
    CxxTestBuilder builder = createTestBuilder("//:rule").setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget()))));
    assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    addFramework(resolver, filesystem);
    addSandbox(resolver, filesystem, builder.getTarget());
    CxxTest test = builder.build(resolver);
    CxxLink binary = (CxxLink) resolver.getRule(CxxDescriptionEnhancer.createCxxLinkTarget(test.getBuildTarget(), Optional.empty()));
    assertThat(binary, Matchers.instanceOf(CxxLink.class));
    assertThat(Arg.stringify(binary.getArgs(), pathResolver), Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
    assertThat(binary.getDeps(), Matchers.hasItem(dep));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Genrule(com.facebook.buck.shell.Genrule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

Genrule (com.facebook.buck.shell.Genrule)31 Test (org.junit.Test)30 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)24 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)24 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)21 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)17 BuildTarget (com.facebook.buck.model.BuildTarget)14 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 BuildRule (com.facebook.buck.rules.BuildRule)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 TargetGraph (com.facebook.buck.rules.TargetGraph)7 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)6 PatternMatchedCollection (com.facebook.buck.rules.coercer.PatternMatchedCollection)4 GenruleBuilder (com.facebook.buck.shell.GenruleBuilder)4 ImmutableList (com.google.common.collect.ImmutableList)4 CxxLink (com.facebook.buck.cxx.CxxLink)3 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)3 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)3 Path (java.nio.file.Path)2 CxxBinary (com.facebook.buck.cxx.CxxBinary)1