Search in sources :

Example 26 with Genrule

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

the class CxxGenruleDescriptionTest method ldFlagsFilter.

@Test
public void ldFlagsFilter() throws Exception {
    for (Linker.LinkableDepType style : Linker.LinkableDepType.values()) {
        CxxLibraryBuilder bBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:b")).setExportedLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("-b")));
        CxxLibraryBuilder aBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:a")).setExportedDeps(ImmutableSortedSet.of(bBuilder.getTarget())).setExportedLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("-a")));
        CxxGenruleBuilder builder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:rule#" + CxxPlatformUtils.DEFAULT_PLATFORM.getFlavor())).setOut("out").setCmd(String.format("$(ldflags-%s-filter //:a //:a)", CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, style.toString())));
        TargetGraph targetGraph = TargetGraphFactory.newInstance(bBuilder.build(), aBuilder.build(), builder.build());
        BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
        SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
        bBuilder.build(resolver);
        aBuilder.build(resolver);
        Genrule genrule = (Genrule) builder.build(resolver);
        assertThat(Joiner.on(' ').join(Arg.stringify(ImmutableList.of(genrule.getCmd().get()), pathResolver)), Matchers.containsString("-a"));
        assertThat(Joiner.on(' ').join(Arg.stringify(ImmutableList.of(genrule.getCmd().get()), pathResolver)), Matchers.not(Matchers.containsString("-b")));
    }
}
Also used : TargetGraph(com.facebook.buck.rules.TargetGraph) 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)

Example 27 with Genrule

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

the class CxxGenruleDescriptionTest method cppflagsNoArgs.

@Test
public void cppflagsNoArgs() throws Exception {
    CxxPlatform cxxPlatform = CxxPlatformUtils.DEFAULT_PLATFORM.withCppflags("-cppflag").withCxxppflags("-cxxppflag");
    CxxGenruleBuilder builder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:rule#" + cxxPlatform.getFlavor()), new FlavorDomain<>("C/C++ Platform", ImmutableMap.of(cxxPlatform.getFlavor(), cxxPlatform))).setOut("out").setCmd("$(cppflags) $(cxxppflags)");
    TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Genrule genrule = (Genrule) builder.build(resolver);
    assertThat(Joiner.on(' ').join(Arg.stringify(ImmutableList.of(genrule.getCmd().get()), pathResolver)), Matchers.containsString("-cppflag -cxxppflag"));
}
Also used : TargetGraph(com.facebook.buck.rules.TargetGraph) 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)

Example 28 with Genrule

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

the class CxxGenruleDescriptionTest method cflagsNoArgs.

@Test
public void cflagsNoArgs() throws Exception {
    CxxPlatform cxxPlatform = CxxPlatformUtils.DEFAULT_PLATFORM.withAsflags("-asflag").withCflags("-cflag").withCxxflags("-cxxflag");
    CxxGenruleBuilder builder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:rule#" + cxxPlatform.getFlavor()), new FlavorDomain<>("C/C++ Platform", ImmutableMap.of(cxxPlatform.getFlavor(), cxxPlatform))).setOut("out").setCmd("$(cflags) $(cxxflags)");
    TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Genrule genrule = (Genrule) builder.build(resolver);
    for (String expected : ImmutableList.of("-asflag", "-cflag", "-cxxflag")) {
        assertThat(Joiner.on(' ').join(Arg.stringify(ImmutableList.of(genrule.getCmd().get()), pathResolver)), Matchers.containsString(expected));
    }
}
Also used : TargetGraph(com.facebook.buck.rules.TargetGraph) 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)

Example 29 with Genrule

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

the class FrameworkPathArgTest method testGetDeps.

@Test
public void testGetDeps() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    BuildTarget genruleTarget = BuildTargetFactory.newInstance("//:genrule");
    Genrule genrule = GenruleBuilder.newGenruleBuilder(genruleTarget).setOut("foo/bar.o").build(ruleResolver, filesystem);
    FrameworkPath sourcePathFrameworkPath = FrameworkPath.ofSourcePath(genrule.getSourcePathToOutput());
    FrameworkPathArg sourcePathFrameworkPathArg = new TestFrameworkPathArg(sourcePathFrameworkPath);
    assertThat(sourcePathFrameworkPathArg.getDeps(ruleFinder), Matchers.contains(genrule));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Genrule(com.facebook.buck.shell.Genrule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) Test(org.junit.Test)

Example 30 with Genrule

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

the class CxxTestDescriptionTest method platformLinkerFlagsLocationMacroWithMatch.

@Test
public void platformLinkerFlagsLocationMacroWithMatch() throws Exception {
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    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().setPlatformLinkerFlags(new PatternMatchedCollection.Builder<ImmutableList<StringWithMacros>>().add(Pattern.compile(Pattern.quote(CxxPlatformUtils.DEFAULT_PLATFORM.getFlavor().toString())), ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget())))).build());
    addFramework(resolver, filesystem);
    addSandbox(resolver, filesystem, builder.getTarget());
    assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
    CxxTest test = builder.build(resolver);
    CxxLink binary = (CxxLink) resolver.getRule(CxxDescriptionEnhancer.createCxxLinkTarget(test.getBuildTarget(), Optional.empty()));
    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) PatternMatchedCollection(com.facebook.buck.rules.coercer.PatternMatchedCollection) ImmutableList(com.google.common.collect.ImmutableList) 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