Search in sources :

Example 1 with JavaLibraryBuilder

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);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) Test(org.junit.Test)

Example 2 with JavaLibraryBuilder

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)));
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) Test(org.junit.Test)

Example 3 with JavaLibraryBuilder

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();
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder)

Example 4 with JavaLibraryBuilder

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);
}
Also used : ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Before(org.junit.Before)

Example 5 with JavaLibraryBuilder

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);
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) File(java.io.File) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

JavaLibraryBuilder (com.facebook.buck.jvm.java.JavaLibraryBuilder)8 BuildTarget (com.facebook.buck.model.BuildTarget)6 Test (org.junit.Test)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2 Path (java.nio.file.Path)2 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)1 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)1 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)1 FileHashCache (com.facebook.buck.util.cache.FileHashCache)1 NullFileHashCache (com.facebook.buck.util.cache.NullFileHashCache)1 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)1 File (java.io.File)1 Before (org.junit.Before)1