Search in sources :

Example 91 with TargetGraph

use of com.facebook.buck.rules.TargetGraph in project buck by facebook.

the class ProjectTest method testPrebuiltJarIncludesDeps.

@Test
public void testPrebuiltJarIncludesDeps() throws Exception {
    // Build up a the graph that corresponds to:
    //
    // android_library(
    //   name = 'example',
    //   deps = [
    //     ':easymock',
    //   ],
    // )
    //
    // prebuilt_jar(
    //   name = 'easymock',
    //   binary_jar = 'easymock.jar',
    //   deps = [
    //     ':cglib',
    //     ':objenesis',
    //   ],
    // )
    //
    // prebuilt_jar(
    //   name = 'cglib',
    //   binary_jar = 'cglib.jar',
    // )
    //
    // prebuilt_jar(
    //   name = 'objenesis',
    //   binary_jar = 'objenesis.jar',
    // )
    //
    // project_config(
    //   src_target = ':example',
    // )
    TargetNode<?, ?> cglibNode = PrebuiltJarBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/java/easymock:cglib")).setBinaryJar(Paths.get("third_party/java/easymock/cglib.jar")).build();
    TargetNode<?, ?> objenesisNode = PrebuiltJarBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/java/easymock:objenesis")).setBinaryJar(Paths.get("third_party/java/easymock/objenesis.jar")).build();
    TargetNode<?, ?> easymockNode = PrebuiltJarBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/java/easymock:easymock")).setBinaryJar(Paths.get("third_party/java/easymock/easymock.jar")).addDep(cglibNode.getBuildTarget()).addDep(objenesisNode.getBuildTarget()).build();
    BuildTarget easyMockExampleTarget = BuildTargetFactory.newInstance("//third_party/java/easymock:example");
    TargetNode<?, ?> mockNode = AndroidLibraryBuilder.createBuilder(easyMockExampleTarget).addDep(easymockNode.getBuildTarget()).build();
    TargetNode<?, ?> projectConfigNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/java/easymock:project_config")).setSrcRule(mockNode.getBuildTarget()).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(cglibNode, objenesisNode, easymockNode, mockNode, projectConfigNode);
    BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    ProjectConfig projectConfig = (ProjectConfig) ruleResolver.requireRule(projectConfigNode.getBuildTarget());
    ProjectWithModules projectWithModules = getModulesForActionGraph(ruleResolver, ImmutableSortedSet.of(projectConfig), null, /* javaPackageFinder */
    null);
    List<SerializableModule> modules = projectWithModules.modules;
    // Verify that the single Module that is created transitively includes all JAR files.
    assertEquals("Should be one module for the android_library", 1, modules.size());
    SerializableModule androidLibraryModule = Iterables.getOnlyElement(modules);
    assertThat(androidLibraryModule.getDependencies(), Matchers.containsInAnyOrder(SerializableDependentModule.newSourceFolder(), SerializableDependentModule.newLibrary(easymockNode.getBuildTarget(), "buck_out_gen_third_party_java_easymock___easymock___easymock_jar"), SerializableDependentModule.newLibrary(cglibNode.getBuildTarget(), "buck_out_gen_third_party_java_easymock___cglib___cglib_jar"), SerializableDependentModule.newLibrary(objenesisNode.getBuildTarget(), "buck_out_gen_third_party_java_easymock___objenesis___objenesis_jar"), SerializableDependentModule.newInheritedJdk()));
}
Also used : ProjectConfig(com.facebook.buck.rules.ProjectConfig) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 92 with TargetGraph

use of com.facebook.buck.rules.TargetGraph in project buck by facebook.

the class ProjectTest method testThatJarsAreListedBeforeModules.

/**
   * In the context of Robolectric, httpcore-4.0.1.jar needs to be loaded before the android.jar
   * associated with the Android SDK. Both httpcore-4.0.1.jar and android.jar define
   * org.apache.http.params.BasicHttpParams; however, only httpcore-4.0.1.jar contains a real
   * implementation of BasicHttpParams whereas android.jar contains a stub implementation of
   * BasicHttpParams.
   * <p>
   * One way to fix this problem would be to "tag" httpcore-4.0.1.jar to indicate that it must
   * appear before the Android SDK (or anything that transitively depends on the Android SDK) when
   * listing dependencies for IntelliJ. This would be a giant kludge to the prebuilt_jar rule, so
   * instead we just list jars before modules within an &lt;orderEntry scope="TEST"/> or an
   * &lt;orderEntry scope="COMPILE"/> group.
   */
@Test
public void testThatJarsAreListedBeforeModules() throws Exception {
    TargetNode<?, ?> supportV4Node = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/android/support/v4:v4")).build();
    TargetNode<?, ?> httpCoreNode = PrebuiltJarBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/java/httpcore:httpcore")).setBinaryJar(Paths.get("httpcore-4.0.1.jar")).build();
    // The support-v4 library is loaded as a java_library() rather than a prebuilt_jar() because it
    // contains our local changes to the library.
    BuildTarget robolectricTarget = BuildTargetFactory.newInstance("//third_party/java/robolectric:robolectric");
    TargetNode<?, ?> robolectricNode = JavaLibraryBuilder.createBuilder(robolectricTarget).addDep(supportV4Node.getBuildTarget()).addDep(httpCoreNode.getBuildTarget()).build();
    TargetNode<?, ?> projectConfigNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/java/robolectric:project_config")).setSrcRule(robolectricNode.getBuildTarget()).setSrcRoots(ImmutableList.of("src/main/java")).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(supportV4Node, httpCoreNode, robolectricNode, projectConfigNode);
    BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    ProjectConfig projectConfig = (ProjectConfig) ruleResolver.requireRule(projectConfigNode.getBuildTarget());
    ProjectWithModules projectWithModules = getModulesForActionGraph(ruleResolver, ImmutableSortedSet.of(projectConfig), null, /* javaPackageFinder */
    null);
    List<SerializableModule> modules = projectWithModules.modules;
    assertEquals("Should be one module for the android_library", 1, modules.size());
    SerializableModule robolectricModule = Iterables.getOnlyElement(modules);
    assertListEquals("It is imperative that httpcore-4.0.1.jar be listed before the support v4 library, " + "or else when robolectric is listed as a dependency, " + "org.apache.http.params.BasicHttpParams will be loaded from android.jar instead of " + "httpcore-4.0.1.jar.", ImmutableList.of(SerializableDependentModule.newSourceFolder(), SerializableDependentModule.newLibrary(httpCoreNode.getBuildTarget(), "buck_out_gen_third_party_java_httpcore___httpcore___httpcore_4_0_1_jar"), SerializableDependentModule.newModule(supportV4Node.getBuildTarget(), "module_java_com_android_support_v4"), SerializableDependentModule.newStandardJdk(Optional.empty(), Optional.empty())), robolectricModule.getDependencies());
}
Also used : ProjectConfig(com.facebook.buck.rules.ProjectConfig) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 93 with TargetGraph

use of com.facebook.buck.rules.TargetGraph in project buck by facebook.

the class LuaLibraryDescriptionTest method baseModuleSource.

@Test
public void baseModuleSource() throws Exception {
    LuaLibraryBuilder builder = new LuaLibraryBuilder(BuildTargetFactory.newInstance("//some:rule")).setSrcs(ImmutableSortedSet.of(new FakeSourcePath("some/foo.lua"))).setBaseModule("blah");
    TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    LuaLibrary library = builder.build(resolver, filesystem, targetGraph);
    assertThat(library.getLuaPackageComponents().getModules(), Matchers.equalTo(ImmutableSortedMap.<String, SourcePath>of("blah/foo.lua", new FakeSourcePath("some/foo.lua"))));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 94 with TargetGraph

use of com.facebook.buck.rules.TargetGraph in project buck by facebook.

the class LuaLibraryDescriptionTest method namedSource.

@Test
public void namedSource() throws Exception {
    LuaLibraryBuilder builder = new LuaLibraryBuilder(BuildTargetFactory.newInstance("//some:rule")).setSrcs(ImmutableSortedMap.of("bar.lua", new FakeSourcePath("foo.lua")));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    LuaLibrary library = builder.build(resolver, filesystem, targetGraph);
    assertThat(library.getLuaPackageComponents().getModules(), Matchers.equalTo(ImmutableSortedMap.<String, SourcePath>of("some/bar.lua", new FakeSourcePath("foo.lua"))));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 95 with TargetGraph

use of com.facebook.buck.rules.TargetGraph in project buck by facebook.

the class LuaBinaryDescriptionTest method pythonDeps.

@Test
public void pythonDeps() throws Exception {
    PythonLibraryBuilder pythonLibraryBuilder = new PythonLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(SourceList.ofUnnamedSources(ImmutableSortedSet.of(new FakeSourcePath("foo.py"))));
    LuaBinaryBuilder luaBinaryBuilder = new LuaBinaryBuilder(BuildTargetFactory.newInstance("//:rule")).setMainModule("hello.world").setDeps(ImmutableSortedSet.of(pythonLibraryBuilder.getTarget()));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(pythonLibraryBuilder.build(), luaBinaryBuilder.build());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    pythonLibraryBuilder.build(resolver, filesystem, targetGraph);
    LuaBinary luaBinary = luaBinaryBuilder.build(resolver, filesystem, targetGraph);
    assertThat(luaBinary.getComponents().getPythonModules().keySet(), Matchers.hasItem("foo.py"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PythonLibraryBuilder(com.facebook.buck.python.PythonLibraryBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

TargetGraph (com.facebook.buck.rules.TargetGraph)267 Test (org.junit.Test)230 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)195 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)179 BuildTarget (com.facebook.buck.model.BuildTarget)157 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)126 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)119 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)96 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)88 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)75 BuildRule (com.facebook.buck.rules.BuildRule)60 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)58 Path (java.nio.file.Path)48 PathSourcePath (com.facebook.buck.rules.PathSourcePath)45 TargetNode (com.facebook.buck.rules.TargetNode)44 SourcePath (com.facebook.buck.rules.SourcePath)37 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)36 ImmutableSet (com.google.common.collect.ImmutableSet)29 Optional (java.util.Optional)25 ImmutableList (com.google.common.collect.ImmutableList)24