use of com.facebook.buck.rules.ProjectConfig in project buck by facebook.
the class ProjectTest method testSrcRoots.
/**
* A project_config()'s src_roots argument can be {@code []}, or a non-empty array.
* Each of these should be treated differently.
*/
@Test
public void testSrcRoots() throws Exception {
// Create a project_config() with src_roots=[].
BuildRuleResolver ruleResolver2 = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule baseBuildRule = AndroidLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:base")).build(ruleResolver2);
ProjectConfig inPackageProjectConfig = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:project_config")).setSrcRule(baseBuildRule.getBuildTarget()).setSrcRoots(ImmutableList.of()).build(ruleResolver2);
// Verify that the correct source folders are created.
JavaPackageFinder javaPackageFinder = EasyMock.createMock(JavaPackageFinder.class);
EasyMock.expect(javaPackageFinder.findJavaPackage(Paths.get("java/com/example/base/module_java_com_example_base.iml"))).andReturn("com.example.base");
EasyMock.replay(javaPackageFinder);
ProjectWithModules projectWithModules2 = getModulesForActionGraph(ruleResolver2, ImmutableSortedSet.of(inPackageProjectConfig), javaPackageFinder, null);
EasyMock.verify(javaPackageFinder);
assertEquals(1, projectWithModules2.modules.size());
SerializableModule moduleWithPackagePrefix = projectWithModules2.modules.get(0);
assertListEquals("The current directory should be a source tmp with a package prefix " + "as well as the gen/ directory.", ImmutableList.of(new SourceFolder("file://$MODULE_DIR$", false, /* isTestSource */
"com.example.base"), SerializableModule.SourceFolder.GEN), moduleWithPackagePrefix.sourceFolders);
// Create a project_config() with src_roots=['src'].
BuildRuleResolver ruleResolver3 = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule baseBuildRule3 = AndroidLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:base")).build(ruleResolver3);
ProjectConfig hasSrcFolderProjectConfig = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:project_config")).setSrcRule(baseBuildRule3.getBuildTarget()).setSrcRoots(ImmutableList.of("src")).build(ruleResolver3);
ProjectWithModules projectWithModules3 = getModulesForActionGraph(ruleResolver3, ImmutableSortedSet.of(hasSrcFolderProjectConfig), null, /* javaPackageFinder */
null);
// Verify that the correct source folders are created.
assertEquals(1, projectWithModules3.modules.size());
SerializableModule moduleHasSrcFolder = projectWithModules3.modules.get(0);
assertListEquals("Both src/ and gen/ should be source folders.", ImmutableList.of(new SourceFolder("file://$MODULE_DIR$/src", false), SerializableModule.SourceFolder.GEN), moduleHasSrcFolder.sourceFolders);
}
use of com.facebook.buck.rules.ProjectConfig in project buck by facebook.
the class ProjectTest method createActionGraphForTesting.
/**
* Creates an ActionGraph with two android_binary rules, each of which depends on the same
* android_library. The difference between the two is that one lists Guava in its no_dx list and
* the other does not.
* <p>
* The ActionGraph also includes three project_config rules: one for the android_library, and one
* for each of the android_binary rules.
*/
public Pair<ProjectWithModules, BuildRuleResolver> createActionGraphForTesting(@Nullable JavaPackageFinder javaPackageFinder) throws Exception {
ImmutableSet.Builder<TargetNode<?, ?>> nodes = ImmutableSet.builder();
// prebuilt_jar //third_party/guava:guava
TargetNode<?, ?> guavaNode = PrebuiltJarBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/guava:guava")).setBinaryJar(PATH_TO_GUAVA_JAR).build();
nodes.add(guavaNode);
// android_resouce android_res/base:res
TargetNode<?, ?> androidResNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//android_res/base:res")).setRes(new FakeSourcePath("android_res/base/res")).setRDotJavaPackage("com.facebook").build();
nodes.add(androidResNode);
// project_config android_res/base:res
TargetNode<?, ?> projectConfigForResourceNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//android_res/base:project_config")).setSrcRule(androidResNode.getBuildTarget()).setSrcRoots(ImmutableList.of("res")).build();
nodes.add(projectConfigForResourceNode);
// java_library //java/src/com/facebook/grandchild:grandchild
BuildTarget grandchildTarget = BuildTargetFactory.newInstance("//java/src/com/facebook/grandchild:grandchild");
TargetNode<?, ?> grandchildNode = JavaLibraryBuilder.createBuilder(grandchildTarget).addSrc(Paths.get("Grandchild.java")).build();
nodes.add(grandchildNode);
// java_library //java/src/com/facebook/child:child
TargetNode<?, ?> childNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/src/com/facebook/child:child")).addSrc(Paths.get("Child.java")).addDep(grandchildNode.getBuildTarget()).build();
nodes.add(childNode);
// java_library //java/src/com/facebook/exportlib:exportlib
TargetNode<?, ?> exportLibNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/src/com/facebook/exportlib:exportlib")).addSrc(Paths.get("ExportLib.java")).addDep(guavaNode.getBuildTarget()).addExportedDep(guavaNode.getBuildTarget()).build();
nodes.add(exportLibNode);
// android_library //java/src/com/facebook/base:base
TargetNode<?, ?> baseNode = AndroidLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/src/com/facebook/base:base")).addSrc(Paths.get("Base.java")).addDep(exportLibNode.getBuildTarget()).addDep(childNode.getBuildTarget()).addDep(androidResNode.getBuildTarget()).build();
nodes.add(baseNode);
// project_config //java/src/com/facebook/base:project_config
TargetNode<?, ?> projectConfigForLibraryNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//java/src/com/facebook/base:project_config")).setSrcRule(baseNode.getBuildTarget()).setSrcRoots(ImmutableList.of("src", "src-gen")).build();
nodes.add(projectConfigForLibraryNode);
TargetNode<?, ?> projectConfigForExportLibraryNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//java/src/com/facebook/exportlib:project_config")).setSrcRule(exportLibNode.getBuildTarget()).setSrcRoots(ImmutableList.of("src")).build();
nodes.add(projectConfigForExportLibraryNode);
// keystore //keystore:debug
BuildTarget keystoreTarget = BuildTargetFactory.newInstance("//keystore:debug");
TargetNode<?, ?> keystoreNode = KeystoreBuilder.createBuilder(keystoreTarget).setStore(new FakeSourcePath("keystore/debug.keystore")).setProperties(new FakeSourcePath("keystore/debug.keystore.properties")).build();
nodes.add(keystoreNode);
// android_binary //foo:app
ImmutableSortedSet<BuildTarget> androidBinaryRuleDepsTarget = ImmutableSortedSet.of(baseNode.getBuildTarget());
TargetNode<?, ?> androidBinaryNode = AndroidBinaryBuilder.createBuilder(BuildTargetFactory.newInstance("//foo:app")).setOriginalDeps(androidBinaryRuleDepsTarget).setManifest(new FakeSourcePath("foo/AndroidManifest.xml")).setKeystore(keystoreNode.getBuildTarget()).setBuildTargetsToExcludeFromDex(ImmutableSet.of(BuildTargetFactory.newInstance("//third_party/guava:guava"))).build();
nodes.add(androidBinaryNode);
// project_config //foo:project_config
TargetNode<?, ?> projectConfigUsingNoDxNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//foo:project_config")).setSrcRule(androidBinaryNode.getBuildTarget()).build();
nodes.add(projectConfigUsingNoDxNode);
// android_binary //bar:app
ImmutableSortedSet<BuildTarget> barAppBuildRuleDepsTarget = ImmutableSortedSet.of(baseNode.getBuildTarget());
TargetNode<?, ?> barAppBuildNode = AndroidBinaryBuilder.createBuilder(BuildTargetFactory.newInstance("//bar:app")).setOriginalDeps(barAppBuildRuleDepsTarget).setManifest(new FakeSourcePath("foo/AndroidManifest.xml")).setKeystore(keystoreNode.getBuildTarget()).build();
nodes.add(barAppBuildNode);
// project_config //bar:project_config
TargetNode<?, ?> projectConfigNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//bar:project_config")).setSrcRule(barAppBuildNode.getBuildTarget()).build();
nodes.add(projectConfigNode);
TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes.build());
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
guava = ruleResolver.requireRule(guavaNode.getBuildTarget());
ProjectConfig projectConfigForExportLibrary = (ProjectConfig) ruleResolver.requireRule(projectConfigForExportLibraryNode.getBuildTarget());
ProjectConfig projectConfigForLibrary = (ProjectConfig) ruleResolver.requireRule(projectConfigForLibraryNode.getBuildTarget());
ProjectConfig projectConfigForResource = (ProjectConfig) ruleResolver.requireRule(projectConfigForResourceNode.getBuildTarget());
ProjectConfig projectConfigUsingNoDx = (ProjectConfig) ruleResolver.requireRule(projectConfigUsingNoDxNode.getBuildTarget());
ProjectConfig projectConfig = (ProjectConfig) ruleResolver.requireRule(projectConfigNode.getBuildTarget());
return new Pair<>(getModulesForActionGraph(ruleResolver, ImmutableSortedSet.of(projectConfigForExportLibrary, projectConfigForLibrary, projectConfigForResource, projectConfigUsingNoDx, projectConfig), javaPackageFinder, null), ruleResolver);
}
use of com.facebook.buck.rules.ProjectConfig 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.ProjectConfig 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.ProjectConfig in project buck by facebook.
the class ProjectTest method testNdkLibraryHasCorrectPath.
@Test
public void testNdkLibraryHasCorrectPath() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
// Build up a the graph that corresponds to:
//
// ndk_library(
// name = 'foo-jni'
// )
//
// project_config(
// src_target = ':foo-jni',
// )
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuildTarget fooJni = BuildTargetFactory.newInstance("//third_party/java/foo/jni:foo-jni");
NdkLibrary ndkLibrary = new NdkLibraryBuilder(fooJni).build(ruleResolver, projectFilesystem);
ProjectConfig ndkProjectConfig = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/java/foo/jni:project_config")).setSrcRule(ndkLibrary.getBuildTarget()).build(ruleResolver);
ProjectWithModules projectWithModules = getModulesForActionGraph(ruleResolver, ImmutableSortedSet.of(ndkProjectConfig), null, /* javaPackageFinder */
null);
List<SerializableModule> modules = projectWithModules.modules;
assertEquals("Should be one module for the ndk_library.", 1, modules.size());
SerializableModule androidLibraryModule = Iterables.getOnlyElement(modules);
assertListEquals(ImmutableList.of(SerializableDependentModule.newSourceFolder(), SerializableDependentModule.newInheritedJdk()), androidLibraryModule.getDependencies());
assertEquals(Paths.get(String.format("../../../../%s", ndkLibrary.getLibraryPath())), androidLibraryModule.nativeLibs);
}
Aggregations