Search in sources :

Example 1 with ClasspathConfiguredFragment

use of com.google.devtools.build.lib.rules.java.ClasspathConfiguredFragment in project bazel by bazelbuild.

the class AndroidCommon method initJava.

private void initJava(JavaSemantics javaSemantics, JavaCompilationHelper helper, JavaCompilationArtifacts.Builder javaArtifactsBuilder, boolean collectJavaCompilationArgs, NestedSetBuilder<Artifact> filesBuilder, boolean isBinary) throws InterruptedException {
    JavaTargetAttributes attributes = helper.getAttributes();
    if (ruleContext.hasErrors()) {
        // Avoid leaving filesToBuild set to null, otherwise we'll get a NullPointerException masking
        // the real error.
        filesToBuild = filesBuilder.build();
        return;
    }
    Artifact jar = null;
    if (attributes.hasSourceFiles() || attributes.hasSourceJars() || attributes.hasResources()) {
        // We only want to add a jar to the classpath of a dependent rule if it has content.
        javaArtifactsBuilder.addRuntimeJar(classJar);
        jar = classJar;
    }
    filesBuilder.add(classJar);
    manifestProtoOutput = helper.createManifestProtoOutput(classJar);
    // it is null, and the source jar action will not depend on the compile action.
    if (helper.usesAnnotationProcessing()) {
        genClassJar = helper.createGenJar(classJar);
        genSourceJar = helper.createGensrcJar(classJar);
        helper.createGenJarAction(classJar, manifestProtoOutput, genClassJar);
    }
    srcJar = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_SOURCE_JAR);
    javaSourceJarsProviderBuilder.addSourceJar(srcJar).addAllTransitiveSourceJars(javaCommon.collectTransitiveSourceJars(srcJar));
    helper.createSourceJarAction(srcJar, genSourceJar);
    outputDepsProto = helper.createOutputDepsProtoArtifact(classJar, javaArtifactsBuilder);
    helper.createCompileActionWithInstrumentation(classJar, manifestProtoOutput, genSourceJar, outputDepsProto, javaArtifactsBuilder);
    if (isBinary) {
        generatedExtensionRegistryProvider = javaSemantics.createGeneratedExtensionRegistry(ruleContext, javaCommon, filesBuilder, javaArtifactsBuilder, javaRuleOutputJarsProviderBuilder, javaSourceJarsProviderBuilder);
    }
    filesToBuild = filesBuilder.build();
    if ((attributes.hasSourceFiles() || attributes.hasSourceJars()) && jar != null) {
        iJar = helper.createCompileTimeJarAction(jar, javaArtifactsBuilder);
    }
    JavaCompilationArtifacts javaArtifacts = javaArtifactsBuilder.build();
    compileTimeDependencyArtifacts = javaCommon.collectCompileTimeDependencyArtifacts(javaArtifacts.getCompileTimeDependencyArtifact());
    javaCommon.setJavaCompilationArtifacts(javaArtifacts);
    javaCommon.setClassPathFragment(new ClasspathConfiguredFragment(javaCommon.getJavaCompilationArtifacts(), attributes, asNeverLink, helper.getBootclasspathOrDefault()));
    transitiveNeverlinkLibraries = collectTransitiveNeverlinkLibraries(ruleContext, javaCommon.getDependencies(), javaCommon.getJavaCompilationArtifacts().getRuntimeJars());
    if (collectJavaCompilationArgs) {
        boolean hasSources = attributes.hasSourceFiles() || attributes.hasSourceJars();
        this.javaCompilationArgs = collectJavaCompilationArgs(exportDeps, asNeverLink, hasSources);
        this.recursiveJavaCompilationArgs = collectJavaCompilationArgs(true, asNeverLink, /* hasSources */
        true);
    }
}
Also used : ClasspathConfiguredFragment(com.google.devtools.build.lib.rules.java.ClasspathConfiguredFragment) JavaCompilationArtifacts(com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts) JavaTargetAttributes(com.google.devtools.build.lib.rules.java.JavaTargetAttributes) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)1 ClasspathConfiguredFragment (com.google.devtools.build.lib.rules.java.ClasspathConfiguredFragment)1 JavaCompilationArtifacts (com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts)1 JavaTargetAttributes (com.google.devtools.build.lib.rules.java.JavaTargetAttributes)1