use of com.facebook.buck.rules.ProjectConfig in project buck by facebook.
the class Project method createModulesForProjectConfigs.
@VisibleForTesting
List<SerializableModule> createModulesForProjectConfigs() throws IOException {
List<SerializableModule> modules = Lists.newArrayList();
// Convert the project_config() targets into modules and find the union of all jars passed to
// no_dx.
ImmutableSet.Builder<Path> noDxJarsBuilder = ImmutableSet.builder();
for (ProjectConfig projectConfig : rules) {
BuildRule srcRule = projectConfig.getSrcRule();
if (srcRule instanceof AndroidBinary) {
AndroidBinary androidBinary = (AndroidBinary) srcRule;
AndroidPackageableCollection packageableCollection = androidBinary.getAndroidPackageableCollection();
ImmutableSortedSet<Path> dxAbsolutePaths = resolver.getAllAbsolutePaths(packageableCollection.getNoDxClasspathEntries());
noDxJarsBuilder.addAll(dxAbsolutePaths.stream().map(projectFilesystem::relativize).iterator());
}
final Optional<Path> rJava;
if (srcRule instanceof AndroidLibrary) {
AndroidLibrary androidLibrary = (AndroidLibrary) srcRule;
BuildTarget dummyRDotJavaTarget = AndroidLibraryGraphEnhancer.getDummyRDotJavaTarget(androidLibrary.getBuildTarget());
Path src = DummyRDotJava.getRDotJavaSrcFolder(dummyRDotJavaTarget, projectFilesystem);
rJava = Optional.of(src);
} else if (srcRule instanceof AndroidResource) {
AndroidResource androidResource = (AndroidResource) srcRule;
BuildTarget dummyRDotJavaTarget = AndroidLibraryGraphEnhancer.getDummyRDotJavaTarget(androidResource.getBuildTarget());
Path src = DummyRDotJava.getRDotJavaSrcFolder(dummyRDotJavaTarget, projectFilesystem);
rJava = Optional.of(src);
} else {
rJava = Optional.empty();
}
SerializableModule module = createModuleForProjectConfig(projectConfig, rJava);
modules.add(module);
}
ImmutableSet<Path> noDxJars = noDxJarsBuilder.build();
// Update module dependencies to apply scope="PROVIDED", where appropriate.
markNoDxJarsAsProvided(projectFilesystem, modules, noDxJars, resolver);
return modules;
}
use of com.facebook.buck.rules.ProjectConfig in project buck by facebook.
the class ProjectTest method testIntellijJdkConfig.
@Test
public void testIntellijJdkConfig() throws Exception {
IntellijConfig intellijConfig = new IntellijConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("intellij", ImmutableMap.of("jdk_name", "1.8"))).build());
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule baseBuildRule = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:base")).build(ruleResolver);
ProjectConfig packageProjectConfig = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:project_config")).setSrcRule(baseBuildRule.getBuildTarget()).setSrcRoots(ImmutableList.of()).build(ruleResolver);
ProjectWithModules projectWithJdkOverride = getModulesForActionGraph(ruleResolver, ImmutableSortedSet.of(packageProjectConfig), null, /* javaPackageFinder */
intellijConfig);
SerializableModule moduleWithJdkOverride = projectWithJdkOverride.modules.get(0);
assertListEquals(ImmutableList.of(SerializableDependentModule.newSourceFolder(), SerializableDependentModule.newStandardJdk(Optional.of("1.8"), Optional.of("JavaSDK"))), moduleWithJdkOverride.getDependencies());
ProjectWithModules projectWithDefaultJdk = getModulesForActionGraph(ruleResolver, ImmutableSortedSet.of(packageProjectConfig), null, /* javaPackageFinder */
null);
SerializableModule moduleWithDefaultJdk = projectWithDefaultJdk.modules.get(0);
assertListEquals(ImmutableList.of(SerializableDependentModule.newSourceFolder(), SerializableDependentModule.newStandardJdk(Optional.of("1.7"), Optional.of("JavaSDK"))), moduleWithDefaultJdk.getDependencies());
}
use of com.facebook.buck.rules.ProjectConfig in project buck by facebook.
the class ProjectTest method testIfModuleIsBothTestAndCompileDepThenTreatAsCompileDep.
@Test
public void testIfModuleIsBothTestAndCompileDepThenTreatAsCompileDep() throws Exception {
// Create a java_library() and a java_test() that both depend on Guava.
// When they are part of the same project_config() rule, then the resulting module should
// include Guava as scope="COMPILE" in IntelliJ.
TargetNode<?, ?> guavaNode = PrebuiltJarBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/java/guava:guava")).setBinaryJar(Paths.get("third_party/java/guava.jar")).build();
TargetNode<?, ?> baseNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:base")).addDep(guavaNode.getBuildTarget()).build();
TargetNode<?, ?> testNode = JavaTestBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:tests")).addDep(guavaNode.getBuildTarget()).build();
TargetNode<?, ?> projectConfigNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:project_config")).setSrcRule(baseNode.getBuildTarget()).setTestRule(testNode.getBuildTarget()).setTestRoots(ImmutableList.of("tests")).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(guavaNode, baseNode, testNode, 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(1, modules.size());
SerializableModule comExampleBaseModule = Iterables.getOnlyElement(modules);
assertListEquals(ImmutableList.of(SerializableDependentModule.newSourceFolder(), SerializableDependentModule.newLibrary(guavaNode.getBuildTarget(), "buck_out_gen_third_party_java_guava___guava___guava_jar"), SerializableDependentModule.newStandardJdk(Optional.empty(), Optional.empty())), comExampleBaseModule.getDependencies());
}
Aggregations