use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class CxxGenruleDescription method fixupSourcePath.
/**
* @return a new {@link BuildTargetSourcePath} for an existing {@link BuildTargetSourcePath} which
* refers to a {@link CxxGenrule} with the given {@code platform} flavor applied.
*/
public static SourcePath fixupSourcePath(BuildRuleResolver ruleResolver, SourcePathRuleFinder ruleFinder, CxxPlatform platform, SourcePath path) throws NoSuchBuildTargetException {
Optional<BuildRule> rule = ruleFinder.getRule(path);
if (rule.isPresent() && rule.get() instanceof CxxGenrule) {
Genrule platformRule = (Genrule) ruleResolver.requireRule(rule.get().getBuildTarget().withAppendedFlavors(platform.getFlavor()));
path = platformRule.getSourcePathToOutput();
}
return path;
}
use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class AppleBinaryDescriptionTest method linkerFlagsLocationMacro.
@Test
public void linkerFlagsLocationMacro() throws Exception {
assumeThat(Platform.detect(), is(Platform.MACOS));
BuildTarget sandboxTarget = BuildTargetFactory.newInstance("//:rule#sandbox," + FakeAppleRuleDescriptions.DEFAULT_IPHONEOS_I386_PLATFORM.getFlavor());
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new AppleBinaryBuilder(sandboxTarget).build()), new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
AppleBinaryBuilder builder = new AppleBinaryBuilder(BuildTargetFactory.newInstance("//:rule")).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget()))));
assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
BuildRule binary = ((CxxBinary) builder.build(resolver)).getLinkRule();
assertThat(binary, Matchers.instanceOf(CxxLink.class));
assertThat(Arg.stringify(((CxxLink) 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 ArchiveTest 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);
Archive archive = Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("simple.o"), genrule1.getSourcePathToOutput(), genrule2.getSourcePathToOutput()));
// Verify that the archive dependencies include the genrules providing the
// SourcePath inputs.
assertEquals(ImmutableSortedSet.<BuildRule>of(genrule1, genrule2), archive.getDeps());
}
use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class CxxBinaryDescriptionTest method platformLinkerFlagsLocationMacroWithoutMatch.
@Test
public void platformLinkerFlagsLocationMacroWithoutMatch() throws Exception {
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
BuildRuleResolver resolver = new BuildRuleResolver(prepopulateWithSandbox(target), new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
CxxBinaryBuilder builder = new CxxBinaryBuilder(target, cxxBuckConfig).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()));
BuildRule binary = builder.build(resolver).getLinkRule();
assertThat(binary, Matchers.instanceOf(CxxLink.class));
assertThat(Arg.stringify(((CxxLink) 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 CxxPreprocessablesTest method createHeaderSymlinkTreeBuildRuleHasNoDeps.
@Test
public void createHeaderSymlinkTreeBuildRuleHasNoDeps() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
// Setup up the main build target and build params, which some random dep. We'll make
// sure the dep doesn't get propagated to the symlink rule below.
FakeBuildRule dep = createFakeBuildRule(BuildTargetFactory.newInstance(filesystem, "//random:dep"), pathResolver);
BuildTarget target = BuildTargetFactory.newInstance(filesystem, "//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(dep)).setProjectFilesystem(filesystem).build();
Path root = Paths.get("root");
// Setup a simple genrule we can wrap in a ExplicitBuildTargetSourcePath to model a input source
// that is built by another rule.
Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance(filesystem, "//:genrule")).setOut("foo/bar.o").build(resolver);
// Setup the link map with both a regular path-based source path and one provided by
// another build rule.
ImmutableMap<Path, SourcePath> links = ImmutableMap.of(Paths.get("link1"), new FakeSourcePath("hello"), Paths.get("link2"), genrule.getSourcePathToOutput());
// Build our symlink tree rule using the helper method.
HeaderSymlinkTree symlinkTree = CxxPreprocessables.createHeaderSymlinkTreeBuildRule(target, params.getProjectFilesystem(), root, links, CxxPreprocessables.HeaderMode.SYMLINK_TREE_ONLY, ruleFinder);
// Verify that the symlink tree has no deps. This is by design, since setting symlinks can
// be done completely independently from building the source that the links point to and
// independently from the original deps attached to the input build rule params.
assertTrue(symlinkTree.getDeps().isEmpty());
}
Aggregations