示例#1
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       .requiresConfigurationFragments(AndroidConfiguration.class)
       .setUndocumented()
       // This is the Proguard that comes from the --proguard_top attribute.
       .add(attr(":proguard", LABEL).cfg(HOST).value(PROGUARD).exec())
       // This is the Proguard in the BUILD file that contains the android_sdk rule. Used when
       // --proguard_top is not specified.
       .add(attr("proguard", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(attr("aapt", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(attr("dx", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(
           attr("main_dex_list_creator", LABEL)
               .mandatory()
               .cfg(HOST)
               .allowedFileTypes(ANY_FILE)
               .exec())
       .add(attr("adb", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(attr("framework_aidl", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE))
       .add(attr("aidl", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(attr("android_jar", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE))
       .add(attr("shrinked_android_jar", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE))
       .add(
           attr("android_jack", LABEL)
               .cfg(HOST)
               .allowedFileTypes(ANY_FILE)
               // TODO(bazel-team): Remove defaults and make mandatory when android_sdk targets
               // have been updated to include manually specified Jack attributes.
               .value(environment.getLabel("//tools/android/jack:android_jack")))
       .add(attr("annotations_jar", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE))
       .add(attr("main_dex_classes", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE))
       .add(attr("apkbuilder", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(attr("zipalign", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(
           attr("jack", LABEL)
               .cfg(HOST)
               .allowedFileTypes(ANY_FILE)
               .exec()
               .value(environment.getLabel("//tools/android/jack:jack")))
       .add(
           attr("jill", LABEL)
               .cfg(HOST)
               .allowedFileTypes(ANY_FILE)
               .exec()
               .value(environment.getLabel("//tools/android/jack:jill")))
       .add(
           attr("resource_extractor", LABEL)
               .cfg(HOST)
               .allowedFileTypes(ANY_FILE)
               .exec()
               .value(environment.getLabel("//tools/android/jack:resource_extractor")))
       .build();
 }
示例#2
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
   /* <!-- #BLAZE_RULE(java_binary).NAME -->
   <br/>It is good practice to use the name of the source file that is the main entry point of the
   application (minus the extension). For example, if your entry point is called
   <code>Main.java</code>, then your name could be <code>Main</code>.
   <!-- #END_BLAZE_RULE.NAME --> */
   return builder
       .requiresConfigurationFragments(JavaConfiguration.class, Jvm.class)
       /* <!-- #BLAZE_RULE(java_binary).IMPLICIT_OUTPUTS -->
       <ul>
         <li><code><var>name</var>.jar</code>: A Java archive, containing the class files and other
           resources corresponding to the binary's direct dependencies.</li>
         <li><code><var>name</var>-src.jar</code>: An archive containing the sources ("source
           jar").</li>
         <li><code><var>name</var>_deploy.jar</code>: A Java archive suitable for deployment (only
           built if explicitly requested).
           <p>
             Building the <code>&lt;<var>name</var>&gt;_deploy.jar</code> target for your rule
             creates a self-contained jar file with a manifest that allows it to be run with the
             <code>java -jar</code> command or with the wrapper script's <code>--singlejar</code>
             option. Using the wrapper script is preferred to <code>java -jar</code> because it
             also passes the <a href="#java_binary.jvm_flags">JVM flags</a> and the options to load
             native libraries.
           </p>
           <p>
             The deploy jar contains all the classes that would be found by a classloader that
             searched the classpath from the binary's wrapper script from beginning to end. It also
             contains the native libraries needed for dependencies. These are automatically loaded
             into the JVM at runtime.
           </p>
         </li>
         <li><code><var>name</var>_deploy-src.jar</code>: An archive containing the sources
           collected from the transitive closure of the target. These will match the classes in the
           <code>deploy.jar</code> except where jars have no matching source jar.</li>
         <li><code><var>name</var>-gen.jar</code>: An archive containing the class files for
           source files generated by annotation processors ("gen jar").</li>
       </ul>
       <!-- #END_BLAZE_RULE.IMPLICIT_OUTPUTS --> */
       .setImplicitOutputsFunction(BazelJavaRuleClasses.JAVA_BINARY_IMPLICIT_OUTPUTS)
       .override(
           attr("$is_executable", BOOLEAN)
               .nonconfigurable("automatic")
               .value(
                   new Attribute.ComputedDefault() {
                     @Override
                     public Object getDefault(AttributeMap rule) {
                       return rule.get("create_executable", BOOLEAN);
                     }
                   }))
       .build();
 }
示例#3
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       .requiresConfigurationFragments(JavaConfiguration.class, AndroidConfiguration.class)
       .setUndocumented()
       // build_tools_version is assumed to be the latest version if omitted.
       .add(attr("build_tools_version", STRING))
       // This is the Proguard that comes from the --proguard_top attribute.
       .add(attr(":proguard", LABEL).cfg(HOST).value(JavaSemantics.PROGUARD).exec())
       // This is the Proguard in the BUILD file that contains the android_sdk rule. Used when
       // --proguard_top is not specified.
       .add(attr("proguard", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(attr("aapt", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(attr("dx", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(
           attr("main_dex_list_creator", LABEL)
               .mandatory()
               .cfg(HOST)
               .allowedFileTypes(ANY_FILE)
               .exec())
       .add(attr("adb", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(attr("framework_aidl", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE))
       .add(attr("aidl", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(attr("android_jar", LABEL).mandatory().cfg(HOST).allowedFileTypes(JavaSemantics.JAR))
       .add(attr("shrinked_android_jar", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE))
       .add(attr("annotations_jar", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE))
       .add(attr("main_dex_classes", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE))
       .add(attr("apkbuilder", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(attr("zipalign", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
       .add(attr("jack", LABEL).cfg(HOST).allowedFileTypes(ANY_FILE).exec().mandatory())
       .add(attr("jill", LABEL).cfg(HOST).allowedFileTypes(ANY_FILE).exec().mandatory())
       .add(
           attr("resource_extractor", LABEL)
               .cfg(HOST)
               .allowedFileTypes(ANY_FILE)
               .exec()
               .mandatory())
       .add(
           attr(":java_toolchain", LABEL)
               .allowedRuleClasses("java_toolchain")
               .value(JavaSemantics.JAVA_TOOLCHAIN))
       .build();
 }
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       .requiresConfigurationFragments(
           JavaConfiguration.class, CppConfiguration.class, J2ObjcConfiguration.class)
       .add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.HOST_JDK))
       /* <!-- #BLAZE_RULE(java_import).ATTRIBUTE(jars) -->
       The list of JAR files provided to Java targets that depend on this target.
       ${SYNOPSIS}
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("jars", LABEL_LIST).mandatory().nonEmpty().allowedFileTypes(JavaSemantics.JAR))
       /* <!-- #BLAZE_RULE(java_import).ATTRIBUTE(srcjar) -->
       A JAR file that contains source code for the compiled JAR files.
       ${SYNOPSIS}
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(
           attr("srcjar", LABEL)
               .allowedFileTypes(JavaSemantics.SOURCE_JAR, JavaSemantics.JAR)
               .direct_compile_time_input())
       .removeAttribute("deps") // only exports are allowed; nothing is compiled
       /* <!-- #BLAZE_RULE(java_import).ATTRIBUTE(neverlink) -->
       Only use this library for compilation and not at runtime.
       ${SYNOPSIS}
       Useful if the library will be provided by the runtime environment
       during execution. Examples of libraries like this are IDE APIs
       for IDE plug-ins or <code>tools.jar</code> for anything running on
       a standard JDK.
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("neverlink", BOOLEAN).value(false))
       /* <!-- #BLAZE_RULE(java_import).ATTRIBUTE(constraints) -->
       Extra constraints imposed on this rule as a Java library.
       ${SYNOPSIS}
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(
           attr("constraints", STRING_LIST)
               .orderIndependent()
               .nonconfigurable(
                   "used in Attribute.validityPredicate implementations (loading time)"))
       .advertiseProvider(JavaSourceInfoProvider.class)
       .advertiseProvider(JavaCompilationArgsProvider.class)
       .build();
 }