Exemplo n.º 1
0
  private JavaCompilationHelper initAttributes(
      JavaTargetAttributes.Builder attributes, JavaSemantics semantics) {
    JavaCompilationHelper helper =
        new JavaCompilationHelper(ruleContext, semantics, javaCommon.getJavacOpts(), attributes);

    helper.addLibrariesToAttributes(javaCommon.targetsTreatedAsDeps(ClasspathType.COMPILE_ONLY));
    helper.addProvidersToAttributes(
        JavaCommon.compilationArgsFromSources(ruleContext), asNeverLink);
    attributes.setStrictJavaDeps(getStrictAndroidDeps());
    attributes.setRuleKind(ruleContext.getRule().getRuleClass());
    attributes.setTargetLabel(ruleContext.getLabel());

    JavaCommon.validateConstraint(
        ruleContext, "android", javaCommon.targetsTreatedAsDeps(ClasspathType.BOTH));
    ruleContext.checkSrcsSamePackage(true);
    return helper;
  }
Exemplo n.º 2
0
 private void compileResources(
     JavaSemantics javaSemantics,
     Artifact resourcesJar,
     JavaCompilationArtifacts.Builder artifactsBuilder,
     JavaTargetAttributes.Builder attributes,
     NestedSetBuilder<Artifact> filesBuilder,
     ImmutableList.Builder<Artifact> jarsProducedForRuntime)
     throws InterruptedException {
   compileResourceJar(javaSemantics, resourcesJar);
   // Add the compiled resource jar to the classpath of the main compilation.
   attributes.addDirectJars(ImmutableList.of(resourceClassJar));
   attributes.addDirectCompileTimeClassPathEntries(ImmutableList.of(resourceClassJar));
   // Add the compiled resource jar to the classpath of consuming targets.
   artifactsBuilder.addCompileTimeJar(resourceClassJar);
   // Combined resource constants needs to come even before our own classes that may contain
   // local resource constants.
   artifactsBuilder.addRuntimeJar(resourceClassJar);
   jarsProducedForRuntime.add(resourceClassJar);
   // Add the compiled resource jar as a declared output of the rule.
   filesBuilder.add(resourceSourceJar);
   filesBuilder.add(resourceClassJar);
 }
Exemplo n.º 3
0
  private void createJarJarActions(
      JavaTargetAttributes.Builder attributes,
      ImmutableList.Builder<Artifact> jarsProducedForRuntime,
      Iterable<ResourceContainer> resourceContainers,
      String originalPackage,
      Artifact binaryResourcesJar) {
    // Now use jarjar for the rest of the resources. We need to make a copy
    // of the final generated resources for each of the targets included in
    // the transitive closure of this binary.
    for (ResourceContainer otherContainer : resourceContainers) {
      if (otherContainer.getLabel().equals(ruleContext.getLabel())) {
        continue;
      }

      Artifact resourcesJar = createResourceJarArtifact(ruleContext, otherContainer, ".jar");
      // combined resource constants copy needs to come before library classes that may contain
      // their local resource constants
      attributes.addRuntimeClassPathEntry(resourcesJar);

      Artifact jarJarRuleFile =
          createResourceJarArtifact(ruleContext, otherContainer, ".jar_jarjar_rules.txt");

      String jarJarRule =
          String.format("rule %s.* %s.@1", originalPackage, otherContainer.getJavaPackage());
      ruleContext.registerAction(
          new FileWriteAction(ruleContext.getActionOwner(), jarJarRuleFile, jarJarRule, false));

      FilesToRunProvider jarjar = ruleContext.getExecutablePrerequisite("$jarjar_bin", Mode.HOST);

      ruleContext.registerAction(
          new SpawnAction.Builder()
              .setExecutable(jarjar)
              .addArgument("process")
              .addInputArgument(jarJarRuleFile)
              .addInputArgument(binaryResourcesJar)
              .addOutputArgument(resourcesJar)
              .setProgressMessage("Repackaging jar")
              .setMnemonic("AndroidRepackageJar")
              .build(ruleContext));
      jarsProducedForRuntime.add(resourcesJar);
    }
  }