use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class MacroArgTest method getDeps.
@Test
public void getDeps() throws Exception {
MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("loc", new LocationMacroExpander()));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
ProjectFilesystem filesystem = new FakeProjectFilesystem();
Genrule rule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("output").build(resolver);
MacroArg arg = new MacroArg(macroHandler, rule.getBuildTarget(), TestCellBuilder.createCellRoots(filesystem), resolver, "$(loc //:rule)");
assertThat(arg.getDeps(ruleFinder), Matchers.contains(rule));
}
use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class SourcePathArgTest method getDeps.
@Test
public void getDeps() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
Genrule rule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("output").build(resolver);
SourcePathArg arg = SourcePathArg.of(rule.getSourcePathToOutput());
assertThat(arg.getDeps(ruleFinder), Matchers.contains(rule));
}
use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class SourcePathResolverTest method getSourcePathNameOnForwardingBuildTargetSourcePath.
@Test
public void getSourcePathNameOnForwardingBuildTargetSourcePath() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
FakeBuildRule rule = new FakeBuildRule(BuildTargetFactory.newInstance("//package:baz"), pathResolver);
resolver.addToIndex(rule);
// Verify that wrapping a genrule in a ForwardingBuildTargetSourcePath resolves to the output
// name of that genrule.
String out = "test/blah.txt";
Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setOut(out).build(resolver);
ForwardingBuildTargetSourcePath buildTargetSourcePath1 = new ForwardingBuildTargetSourcePath(rule.getBuildTarget(), genrule.getSourcePathToOutput());
String actual1 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath1);
assertEquals(out, actual1);
ForwardingBuildTargetSourcePath buildTargetSourcePath2 = new ForwardingBuildTargetSourcePath(rule.getBuildTarget(), new FakeSourcePath("foo/bar"));
String actual2 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath2);
assertEquals(Paths.get("foo", "bar").toString(), actual2);
BuildTarget otherFakeBuildTarget = BuildTargetFactory.newInstance("//package2:fake2");
FakeBuildRule otherFakeBuildRule = new FakeBuildRule(new FakeBuildRuleParamsBuilder(otherFakeBuildTarget).build(), pathResolver);
resolver.addToIndex(otherFakeBuildRule);
ForwardingBuildTargetSourcePath buildTargetSourcePath3 = new ForwardingBuildTargetSourcePath(otherFakeBuildRule.getBuildTarget(), buildTargetSourcePath2);
String actual3 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath3);
assertEquals(Paths.get("foo", "bar").toString(), actual3);
}
use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class SourcePathResolverTest method getSourcePathNameOnDefaultBuildTargetSourcePath.
@Test
public void getSourcePathNameOnDefaultBuildTargetSourcePath() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
// Verify that wrapping a genrule in a BuildTargetSourcePath resolves to the output name of
// that genrule.
String out = "test/blah.txt";
Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setOut(out).build(resolver);
DefaultBuildTargetSourcePath buildTargetSourcePath1 = new DefaultBuildTargetSourcePath(genrule.getBuildTarget());
String actual1 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath1);
assertEquals(out, actual1);
// Test that using other BuildRule types resolves to the short name.
BuildTarget fakeBuildTarget = BuildTargetFactory.newInstance("//:fake");
FakeBuildRule fakeBuildRule = new FakeBuildRule(new FakeBuildRuleParamsBuilder(fakeBuildTarget).build(), pathResolver);
resolver.addToIndex(fakeBuildRule);
DefaultBuildTargetSourcePath buildTargetSourcePath2 = new DefaultBuildTargetSourcePath(fakeBuildRule.getBuildTarget());
String actual2 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath2);
assertEquals(fakeBuildTarget.getShortName(), actual2);
}
use of com.facebook.buck.shell.Genrule in project buck by facebook.
the class SymlinkTreeTest method testSymlinkTreeDependentRuleKeyChangesWhenLinkSourceContentChanges.
@Test
public void testSymlinkTreeDependentRuleKeyChangesWhenLinkSourceContentChanges() throws Exception {
// If a dependent of a symlink tree uses the symlink tree's output as an input, that dependent's
// rulekey must change when the link contents change.
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleResolver.addToIndex(symlinkTreeBuildRule);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableList.of(symlinkTreeBuildRule.getSourcePathToOutput())).setOut("out").build(ruleResolver);
DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
RuleKey ruleKey1 = new DefaultRuleKeyFactory(0, hashLoader, pathResolver, ruleFinder).build(genrule);
Path existingFile = pathResolver.getAbsolutePath(links.values().asList().get(0));
Files.write(existingFile, "something new".getBytes(Charsets.UTF_8));
hashCache.invalidateAll();
RuleKey ruleKey2 = new DefaultRuleKeyFactory(0, hashLoader, pathResolver, ruleFinder).build(genrule);
// Verify that the rules keys are different.
assertNotEquals(ruleKey1, ruleKey2);
}
Aggregations