Search in sources :

Example 1 with JavaCompilationHelper

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

the class AndroidCommon method init.

public JavaTargetAttributes init(JavaSemantics javaSemantics, AndroidSemantics androidSemantics, ResourceApk resourceApk, boolean addCoverageSupport, boolean collectJavaCompilationArgs, boolean isBinary) throws InterruptedException {
    classJar = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_CLASS_JAR);
    idlHelper = new AndroidIdlHelper(ruleContext, classJar);
    ImmutableList<Artifact> bootclasspath;
    if (getAndroidConfig(ruleContext).desugarJava8()) {
        bootclasspath = ImmutableList.<Artifact>builder().addAll(ruleContext.getPrerequisite("$desugar_java8_extra_bootclasspath", Mode.HOST).getProvider(FileProvider.class).getFilesToBuild()).add(AndroidSdkProvider.fromRuleContext(ruleContext).getAndroidJar()).build();
    } else {
        bootclasspath = ImmutableList.of(AndroidSdkProvider.fromRuleContext(ruleContext).getAndroidJar());
    }
    JavaTargetAttributes.Builder attributes = javaCommon.initCommon(idlHelper.getIdlGeneratedJavaSources(), androidSemantics.getJavacArguments(ruleContext)).setBootClassPath(bootclasspath);
    if (DataBinding.isEnabled(ruleContext)) {
        DataBinding.addAnnotationProcessor(ruleContext, attributes);
    }
    JavaCompilationArtifacts.Builder artifactsBuilder = new JavaCompilationArtifacts.Builder();
    NestedSetBuilder<Artifact> jarsProducedForRuntime = NestedSetBuilder.<Artifact>stableOrder();
    NestedSetBuilder<Artifact> filesBuilder = NestedSetBuilder.<Artifact>stableOrder();
    Artifact resourcesJar = resourceApk.getResourceJavaSrcJar();
    if (resourcesJar != null) {
        filesBuilder.add(resourcesJar);
        // Use a fast-path R class generator for android_binary with local resources, where there is
        // a bottleneck. For legacy resources, the srcjar and R class compiler don't match up
        // (the legacy srcjar requires the createJarJar step below).
        boolean useRClassGenerator = isBinary && !resourceApk.isLegacy();
        compileResources(javaSemantics, resourceApk, resourcesJar, artifactsBuilder, attributes, filesBuilder, jarsProducedForRuntime, useRClassGenerator);
        if (resourceApk.isLegacy()) {
            // Repackages the R.java for each dependency package and places the resultant jars before
            // the dependency libraries to ensure that the generated resource ids are correct.
            createJarJarActions(attributes, jarsProducedForRuntime, resourceApk.getResourceDependencies().getResources(), resourceApk.getPrimaryResource().getJavaPackage(), resourceClassJar);
        }
    }
    JavaCompilationHelper helper = initAttributes(attributes, javaSemantics);
    if (ruleContext.hasErrors()) {
        return null;
    }
    if (addCoverageSupport) {
        androidSemantics.addCoverageSupport(ruleContext, this, javaSemantics, true, attributes, artifactsBuilder);
        if (ruleContext.hasErrors()) {
            return null;
        }
    }
    jackCompilationHelper = initJack(helper.getAttributes());
    if (ruleContext.hasErrors()) {
        return null;
    }
    initJava(javaSemantics, helper, artifactsBuilder, collectJavaCompilationArgs, filesBuilder, isBinary);
    if (ruleContext.hasErrors()) {
        return null;
    }
    if (generatedExtensionRegistryProvider != null) {
        jarsProducedForRuntime.add(generatedExtensionRegistryProvider.getClassJar());
    }
    this.jarsProducedForRuntime = jarsProducedForRuntime.add(classJar).build();
    return helper.getAttributes();
}
Also used : JavaCompilationArtifacts(com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts) FileProvider(com.google.devtools.build.lib.analysis.FileProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact) JavaTargetAttributes(com.google.devtools.build.lib.rules.java.JavaTargetAttributes) JavaCompilationHelper(com.google.devtools.build.lib.rules.java.JavaCompilationHelper)

Example 2 with JavaCompilationHelper

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

the class AndroidCommon method initAttributes.

private JavaCompilationHelper initAttributes(JavaTargetAttributes.Builder attributes, JavaSemantics semantics) {
    JavaCompilationHelper helper = new JavaCompilationHelper(ruleContext, semantics, javaCommon.getJavacOpts(), attributes, DataBinding.isEnabled(ruleContext) ? DataBinding.processDeps(ruleContext, attributes) : ImmutableList.<Artifact>of());
    helper.addLibrariesToAttributes(javaCommon.targetsTreatedAsDeps(ClasspathType.COMPILE_ONLY));
    attributes.setRuleKind(ruleContext.getRule().getRuleClass());
    attributes.setTargetLabel(ruleContext.getLabel());
    JavaCommon.validateConstraint(ruleContext, "android", javaCommon.targetsTreatedAsDeps(ClasspathType.BOTH));
    ruleContext.checkSrcsSamePackage(true);
    return helper;
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) JavaCompilationHelper(com.google.devtools.build.lib.rules.java.JavaCompilationHelper)

Example 3 with JavaCompilationHelper

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

the class AndroidCommon method compileResourceJar.

private void compileResourceJar(JavaSemantics javaSemantics, ResourceApk resourceApk, Artifact resourcesJar, boolean useRClassGenerator) throws InterruptedException {
    resourceSourceJar = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_SOURCE_JAR);
    resourceClassJar = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_CLASS_JAR);
    JavaCompilationArtifacts.Builder javaArtifactsBuilder = new JavaCompilationArtifacts.Builder();
    JavaTargetAttributes.Builder javacAttributes = new JavaTargetAttributes.Builder(javaSemantics).addSourceJar(resourcesJar);
    JavaCompilationHelper javacHelper = new JavaCompilationHelper(ruleContext, javaSemantics, getJavacOpts(), javacAttributes);
    // Only build the class jar if it's not already generated internally by resource processing.
    if (resourceApk.getResourceJavaClassJar() == null) {
        if (useRClassGenerator) {
            RClassGeneratorActionBuilder actionBuilder = new RClassGeneratorActionBuilder(ruleContext).withPrimary(resourceApk.getPrimaryResource()).withDependencies(resourceApk.getResourceDependencies()).setClassJarOut(resourceClassJar);
            actionBuilder.build();
        } else {
            Artifact outputDepsProto = javacHelper.createOutputDepsProtoArtifact(resourceClassJar, javaArtifactsBuilder);
            javacHelper.createCompileActionWithInstrumentation(resourceClassJar, null, /* manifestProtoOutput */
            null, /* genSourceJar */
            outputDepsProto, javaArtifactsBuilder);
        }
    } else {
        // Otherwise, it should have been the AndroidRuleClasses.ANDROID_RESOURCES_CLASS_JAR.
        Preconditions.checkArgument(resourceApk.getResourceJavaClassJar().equals(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_CLASS_JAR)));
    }
    javacHelper.createSourceJarAction(resourceSourceJar, null);
}
Also used : JavaCompilationArtifacts(com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) JavaTargetAttributes(com.google.devtools.build.lib.rules.java.JavaTargetAttributes) Artifact(com.google.devtools.build.lib.actions.Artifact) JavaCompilationHelper(com.google.devtools.build.lib.rules.java.JavaCompilationHelper)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)3 JavaCompilationHelper (com.google.devtools.build.lib.rules.java.JavaCompilationHelper)3 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)2 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)2 JavaCompilationArtifacts (com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts)2 JavaTargetAttributes (com.google.devtools.build.lib.rules.java.JavaTargetAttributes)2 FileProvider (com.google.devtools.build.lib.analysis.FileProvider)1