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()));
}
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 <orderEntry scope="TEST"/> or an
* <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());
}
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"))));
}
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"))));
}
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"));
}
Aggregations