use of com.facebook.buck.jvm.java.JavaLibraryBuilder in project buck by facebook.
the class BuildRuleResolverTest method getRuleWithTypeWrongType.
@Test
public void getRuleWithTypeWrongType() throws Exception {
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
JavaLibraryBuilder builder = JavaLibraryBuilder.createBuilder(target);
TargetNode<?, ?> library = builder.build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(library);
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
builder.build(resolver);
expectedException.expect(HumanReadableException.class);
expectedException.expectMessage(Matchers.containsString("not of expected type"));
resolver.getRuleWithType(BuildTargetFactory.newInstance("//foo:bar"), JavaBinary.class);
}
use of com.facebook.buck.jvm.java.JavaLibraryBuilder in project buck by facebook.
the class RuleKeyTest method testRuleKeyDependsOnDeps.
/**
* Ensure that build rules with the same inputs but different deps have unique RuleKeys.
*/
@Test
public void testRuleKeyDependsOnDeps() throws Exception {
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
BuildRuleResolver ruleResolver1 = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildRuleResolver ruleResolver2 = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder1 = new SourcePathRuleFinder(ruleResolver1);
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, new SourcePathResolver(ruleFinder1), ruleFinder1);
SourcePathRuleFinder ruleFinder2 = new SourcePathRuleFinder(ruleResolver2);
DefaultRuleKeyFactory ruleKeyFactory2 = new DefaultRuleKeyFactory(0, hashCache, new SourcePathResolver(ruleFinder2), ruleFinder2);
// Create a dependent build rule, //src/com/facebook/buck/cli:common.
JavaLibraryBuilder builder = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//src/com/facebook/buck/cli:common"));
BuildRule commonJavaLibrary = builder.build(ruleResolver1);
builder.build(ruleResolver2);
// Create a java_library() rule with no deps.
Path mainSrc = Paths.get("src/com/facebook/buck/cli/Main.java");
filesystem.mkdirs(mainSrc.getParent());
filesystem.writeContentsToPath("hello", mainSrc);
JavaLibraryBuilder javaLibraryBuilder = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//src/com/facebook/buck/cli:cli")).addSrc(mainSrc);
BuildRule libraryNoCommon = javaLibraryBuilder.build(ruleResolver1, filesystem);
// Create the same java_library() rule, but with a dep on //src/com/facebook/buck/cli:common.
javaLibraryBuilder.addDep(commonJavaLibrary.getBuildTarget());
BuildRule libraryWithCommon = javaLibraryBuilder.build(ruleResolver2, filesystem);
// Assert that the RuleKeys are distinct.
RuleKey r1 = ruleKeyFactory.build(libraryNoCommon);
RuleKey r2 = ruleKeyFactory2.build(libraryWithCommon);
assertThat("Rule keys should be distinct because the deps of the rules are different.", r1, not(equalTo(r2)));
}
use of com.facebook.buck.jvm.java.JavaLibraryBuilder in project buck by facebook.
the class TargetGraphTest method createTargetNode.
private TargetNode<?, ?> createTargetNode(String name, TargetNode<?, ?>... deps) {
BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo: " + name);
JavaLibraryBuilder targetNodeBuilder = JavaLibraryBuilder.createBuilder(buildTarget);
for (TargetNode<?, ?> dep : deps) {
targetNodeBuilder.addDep(dep.getBuildTarget());
}
return targetNodeBuilder.build();
}
use of com.facebook.buck.jvm.java.JavaLibraryBuilder in project buck by facebook.
the class MacroHandlerTest method before.
@Before
public void before() throws Exception {
filesystem = new ProjectFilesystem(tmp.newFolder().toPath());
target = BuildTargetFactory.newInstance("//:test");
JavaLibraryBuilder builder = JavaLibraryBuilder.createBuilder(target);
resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(builder.build()), new DefaultTargetNodeToBuildRuleTransformer());
builder.build(resolver, filesystem);
}
use of com.facebook.buck.jvm.java.JavaLibraryBuilder in project buck by facebook.
the class OutputToFileExpanderTest method shouldTakeOutputFromOtherMacroAndOutputItToAFile.
@Test
public void shouldTakeOutputFromOtherMacroAndOutputItToAFile() throws Exception {
File root = tmp.newFolder();
ProjectFilesystem filesystem = new ProjectFilesystem(root.toPath());
String text = "cheese" + File.pathSeparator + "peas";
StringExpander source = new StringExpander(text);
OutputToFileExpander expander = new OutputToFileExpander(source);
BuildTarget target = BuildTargetFactory.newInstance("//some:example");
JavaLibraryBuilder builder = JavaLibraryBuilder.createBuilder(target);
TargetNode<?, ?> node = builder.build();
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(node), new DefaultTargetNodeToBuildRuleTransformer());
builder.build(resolver, filesystem);
String result = expander.expand(target, createCellRoots(filesystem), resolver, ImmutableList.of("totally ignored"));
assertTrue(result, result.startsWith("@"));
Path output = Paths.get(result.substring(1));
// Because we're going to shovel this into a genrule
assertTrue(output.isAbsolute());
List<String> seen = Files.readAllLines(output, UTF_8);
List<String> expected = ImmutableList.of(text);
assertEquals(expected, seen);
}
Aggregations