use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class CxxTestDescriptionTest method platformLinkerFlagsLocationMacroWithoutMatch.
@Test
public void platformLinkerFlagsLocationMacroWithoutMatch() throws Exception {
ProjectFilesystem 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);
addFramework(resolver, filesystem);
CxxTestBuilder builder = createTestBuilder().setPlatformLinkerFlags(new PatternMatchedCollection.Builder<ImmutableList<StringWithMacros>>().add(Pattern.compile("nothing matches this string"), ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget())))).build());
assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
addSandbox(resolver, filesystem, builder.getTarget());
CxxTest test = builder.build(resolver);
CxxLink binary = (CxxLink) resolver.getRule(CxxDescriptionEnhancer.createCxxLinkTarget(test.getBuildTarget(), Optional.empty()));
assertThat(Arg.stringify(binary.getArgs(), pathResolver), Matchers.not(Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver)))));
assertThat(binary.getDeps(), Matchers.not(Matchers.hasItem(dep)));
}
use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class CxxTestDescriptionTest method locationMacro.
@Test
public void locationMacro() throws Exception {
ProjectFilesystem 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().setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget()))));
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));
}
use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class CxxGenruleDescriptionTest method cxxGenruleInLocationMacro.
@Test
public void cxxGenruleInLocationMacro() throws Exception {
CxxGenruleBuilder depBuilder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out");
CxxGenruleBuilder builder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setCmd("$(location //:dep)").setOut("out");
TargetGraph targetGraph = TargetGraphFactory.newInstance(depBuilder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
CxxGenrule dep = (CxxGenrule) resolver.requireRule(depBuilder.getTarget());
CxxGenrule rule = (CxxGenrule) resolver.requireRule(builder.getTarget());
Genrule genrule = (Genrule) ruleFinder.getRule(rule.getGenrule(CxxPlatformUtils.DEFAULT_PLATFORM)).orElseThrow(AssertionError::new);
assertThat(Arg.stringify(OptionalCompat.asSet(genrule.getCmd()), pathResolver), Matchers.contains(pathResolver.getAbsolutePath(dep.getGenrule(CxxPlatformUtils.DEFAULT_PLATFORM)).toString()));
}
use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class CxxLibraryDescriptionTest method linkerFlagsLocationMacro.
@Test
public void linkerFlagsLocationMacro() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget target = BuildTargetFactory.newInstance("//:rule").withFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR, CxxPlatformUtils.DEFAULT_PLATFORM.getFlavor());
GenruleBuilder depBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out");
CxxLibraryBuilder builder = new CxxLibraryBuilder(target, cxxBuckConfig).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(depBuilder.getTarget())))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.c"))));
TargetGraph targetGraph = TargetGraphFactory.newInstance(depBuilder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Genrule dep = depBuilder.build(resolver, filesystem, targetGraph);
assertThat(builder.build().getExtraDeps(), hasItem(dep.getBuildTarget()));
BuildRule binary = builder.build(resolver, filesystem, targetGraph);
assertThat(binary, instanceOf(CxxLink.class));
assertThat(Arg.stringify(((CxxLink) binary).getArgs(), pathResolver), hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
assertThat(binary.getDeps(), hasItem(dep));
}
use of com.facebook.buck.shell.Genrule 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());
}
Aggregations