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")));
}
}
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"));
}
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));
}
}
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));
}
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));
}
Aggregations