Search in sources :

Example 6 with ProjectConfig

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;
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) AndroidBinary(com.facebook.buck.android.AndroidBinary) AndroidResource(com.facebook.buck.android.AndroidResource) ProjectConfig(com.facebook.buck.rules.ProjectConfig) ImmutableSet(com.google.common.collect.ImmutableSet) AndroidLibrary(com.facebook.buck.android.AndroidLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) AndroidPackageableCollection(com.facebook.buck.android.AndroidPackageableCollection) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with ProjectConfig

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());
}
Also used : ProjectConfig(com.facebook.buck.rules.ProjectConfig) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 8 with ProjectConfig

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());
}
Also used : ProjectConfig(com.facebook.buck.rules.ProjectConfig) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

ProjectConfig (com.facebook.buck.rules.ProjectConfig)8 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)7 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)7 Test (org.junit.Test)6 BuildTarget (com.facebook.buck.model.BuildTarget)5 TargetGraph (com.facebook.buck.rules.TargetGraph)4 BuildRule (com.facebook.buck.rules.BuildRule)3 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 AndroidBinary (com.facebook.buck.android.AndroidBinary)1 AndroidLibrary (com.facebook.buck.android.AndroidLibrary)1 AndroidPackageableCollection (com.facebook.buck.android.AndroidPackageableCollection)1 AndroidResource (com.facebook.buck.android.AndroidResource)1 NdkLibrary (com.facebook.buck.android.NdkLibrary)1 NdkLibraryBuilder (com.facebook.buck.android.NdkLibraryBuilder)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 JavaPackageFinder (com.facebook.buck.jvm.core.JavaPackageFinder)1 FakeJavaPackageFinder (com.facebook.buck.jvm.java.FakeJavaPackageFinder)1 SourceFolder (com.facebook.buck.jvm.java.intellij.SerializableModule.SourceFolder)1 Pair (com.facebook.buck.model.Pair)1