@Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
   return builder
       .add(attr(":jvm", LABEL).cfg(HOST).value(JavaSemantics.JVM))
       .add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.HOST_JDK))
       .add(attr(":java_toolchain", LABEL).value(JavaSemantics.JAVA_TOOLCHAIN))
       .add(
           attr("$javac_extdir", LABEL)
               .cfg(HOST)
               .value(env.getLabel(JavaSemantics.JAVAC_EXTDIR_LABEL)))
       .add(
           attr("$java_langtools", LABEL)
               .cfg(HOST)
               .value(
                   env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/defaults:java_langtools")))
       .add(
           attr("$javac_bootclasspath", LABEL)
               .cfg(HOST)
               .value(env.getLabel(JavaSemantics.JAVAC_BOOTCLASSPATH_LABEL)))
       .add(
           attr("$javabuilder", LABEL)
               .cfg(HOST)
               .value(env.getLabel(JavaSemantics.JAVABUILDER_LABEL)))
       .add(
           attr("$singlejar", LABEL)
               .cfg(HOST)
               .value(env.getLabel(JavaSemantics.SINGLEJAR_LABEL)))
       .add(attr("$genclass", LABEL).cfg(HOST).value(env.getLabel(JavaSemantics.GENCLASS_LABEL)))
       .build();
 }
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       /*<!-- #BLAZE_RULE(action_listener).ATTRIBUTE(mnemonics) -->
       A list of action mnemonics this <code>action_listener</code> should listen
       for, e.g. <code>[ "Javac" ]</code>.
       ${SYNOPSIS}
       <p>
         Mnemonics are not a public interface.
         There's no guarantee that the mnemonics and their actions don't change.
       </p>
       <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
       .add(attr("mnemonics", STRING_LIST).mandatory())
       /*<!-- #BLAZE_RULE(action_listener).ATTRIBUTE(extra_actions) -->
       A list of <code><a href="#extra_action">extra_action</a></code> targets
       this <code>action_listener</code> should add to the build graph.
       ${SYNOPSIS}
       E.g. <code>[ "//my/tools:analyzer" ]</code>.
       <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
       .add(
           attr("extra_actions", LABEL_LIST)
               .mandatory()
               .allowedRuleClasses("extra_action")
               .allowedFileTypes())
       .removeAttribute("deps")
       .removeAttribute("data")
       .removeAttribute(":action_listener")
       .build();
 }
Beispiel #3
0
    @Override
    public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
      return builder
          .add(
              attr("size", STRING)
                  .value("medium")
                  .taggable()
                  .nonconfigurable("policy decision: should be consistent across configurations"))
          .add(
              attr("timeout", STRING)
                  .taggable()
                  .nonconfigurable("policy decision: should be consistent across configurations")
                  .value(
                      new Attribute.ComputedDefault() {
                        @Override
                        public Object getDefault(AttributeMap rule) {
                          TestSize size = TestSize.getTestSize(rule.get("size", Type.STRING));
                          if (size != null) {
                            String timeout = size.getDefaultTimeout().toString();
                            if (timeout != null) {
                              return timeout;
                            }
                          }
                          return "illegal";
                        }
                      }))
          .add(
              attr("flaky", BOOLEAN)
                  .value(false)
                  .taggable()
                  .nonconfigurable("policy decision: should be consistent across configurations"))
          .add(attr("shard_count", INTEGER).value(-1))
          .add(
              attr("local", BOOLEAN)
                  .value(false)
                  .taggable()
                  .nonconfigurable("policy decision: should be consistent across configurations"))
          .add(attr("args", STRING_LIST))
          // Input files for every test action
          .add(
              attr("$test_runtime", LABEL_LIST)
                  .cfg(HOST)
                  .value(ImmutableList.of(env.getToolsLabel("//tools/test:runtime"))))
          // Input files for test actions collecting code coverage
          .add(
              attr("$coverage_support", LABEL)
                  .cfg(HOST)
                  .value(env.getLabel("//tools/defaults:coverage_support")))
          // Used in the one-per-build coverage report generation action.
          .add(
              attr("$coverage_report_generator", LABEL)
                  .cfg(HOST)
                  .value(env.getLabel("//tools/defaults:coverage_report_generator"))
                  .singleArtifact())

          // The target itself and run_under both run on the same machine. We use the DATA config
          // here because the run_under acts like a data dependency (e.g. no LIPO optimization).
          .add(attr(":run_under", LABEL).cfg(DATA).value(RUN_UNDER).skipPrereqValidatorCheck())
          .build();
    }
Beispiel #4
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
   return builder
       .add(attr("deps", LABEL_LIST).legacyAllowAnyFileType())
       .add(attr("data", LABEL_LIST).cfg(DATA).allowedFileTypes(FileTypeSet.ANY_FILE))
       .build();
 }
Beispiel #5
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
   return builder
       .setUndocumented()
       /* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(source_version) -->
       The Java source version (e.g., '6' or '7'). It specifies which set of code structures
       are allowed in the Java source code.
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("source_version", STRING).mandatory()) // javac -source flag value.
       /* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(target_version) -->
       The Java target version (e.g., '6' or '7'). It specifies for which Java runtime the class
       should be build.
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("target_version", STRING).mandatory()) // javac -target flag value.
       /* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(encoding) -->
       The encoding of the java files (e.g., 'UTF-8').
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("encoding", STRING).mandatory()) // javac -encoding flag value.
       /* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(xlint) -->
       The list of warning to add or removes from default list. Precedes it with a dash to
       removes it. Please see the Javac documentation on the -Xlint options for more information.
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("xlint", STRING_LIST).value(ImmutableList.<String>of()))
       /* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(misc) -->
       The list of extra arguments for the Java compiler. Please refer to the Java compiler
       documentation for the extensive list of possible Java compiler flags.
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("misc", STRING_LIST).value(ImmutableList.<String>of()))
       /* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(jvm_opts) -->
       The list of arguments for the JVM when invoking the Java compiler. Please refer to the Java
       virtual machine documentation for the extensive list of possible flags for this option.
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("jvm_opts", STRING_LIST).value(defaultJavacJvmOpts))
       .build();
 }
Beispiel #6
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       .add(attr("foo", LABEL_LIST).allowedFileTypes(FileTypeSet.ANY_FILE))
       .advertiseProvider(RequiredProvider.class)
       .build();
 }
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       .setUndocumented()
       .setWorkspaceOnly()
       .setExternalBindingsFunction(BINDINGS_FUNCTION)
       .add(attr("path", STRING).mandatory().nonconfigurable("WORKSPACE rule"))
       .build();
 }
Beispiel #8
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       .add(
           attr("foo", LABEL_LIST)
               .allowedFileTypes(FileTypeSet.ANY_FILE)
               .aspect(ExtraAttributeAspectRequiringProvider.class))
       .build();
 }
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       .setUndocumented()
       .setWorkspaceOnly()
       .setExternalBindingsFunction(BINDINGS_FUNCTION)
       .add(attr("url", STRING).mandatory())
       .add(attr("sha256", STRING).mandatory())
       .build();
 }
Beispiel #10
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       .setUndocumented()
       .add(
           attr(":android_sdk", LABEL)
               .allowedRuleClasses("android_sdk", "filegroup")
               .value(ANDROID_SDK))
       .build();
 }
Beispiel #11
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       .add(
           attr("foo", LABEL_LIST)
               .allowedFileTypes(FileTypeSet.ANY_FILE)
               .aspect(ErrorAspect.class))
       .add(attr("bar", LABEL_LIST).allowedFileTypes(FileTypeSet.ANY_FILE))
       .build();
 }
Beispiel #12
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       .add(
           attr("foo", LABEL_LIST)
               .allowedFileTypes(FileTypeSet.ANY_FILE)
               .aspect(ParametrizedDefinitionAspect.class, new TestAspectParametersExtractor()))
       .add(attr("baz", STRING))
       .build();
 }
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
   return builder
       .add(
           attr("$ijar", LABEL)
               .cfg(HOST)
               .exec()
               .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/defaults:ijar")))
       .setPreferredDependencyPredicate(JavaSemantics.JAVA_SOURCE)
       .build();
 }
Beispiel #14
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();
 }
Beispiel #15
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();
 }
Beispiel #16
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
   return builder
       .add(attr("testonly", BOOLEAN).nonconfigurable("test").value(false))
       .add(attr("deprecation", STRING).nonconfigurable("test"))
       .add(attr("tags", STRING_LIST))
       .add(
           attr("visibility", NODEP_LABEL_LIST)
               .orderIndependent()
               .cfg(HOST)
               .nonconfigurable("test"))
       .add(
           attr(RuleClass.COMPATIBLE_ENVIRONMENT_ATTR, LABEL_LIST)
               .allowedFileTypes(FileTypeSet.NO_FILE))
       .add(
           attr(RuleClass.RESTRICTED_ENVIRONMENT_ATTR, LABEL_LIST)
               .allowedFileTypes(FileTypeSet.NO_FILE))
       .build();
 }
Beispiel #17
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();
 }
Beispiel #19
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
   // filegroup ignores any filtering set with setSrcsAllowedFiles.
   return builder
       /*<!-- #BLAZE_RULE(filegroup).ATTRIBUTE(srcs) -->
       The list of targets that are members of the file group.
       ${SYNOPSIS}
       <p>
         It is common to use the result of a <a href="#glob">glob</a> expression for the value
         of the <code>srcs</code> attribute. If a rule and a source file with the same name both
         exist in the package, the glob will return the outputs of the rule instead of the source
         file.
       </p>
       <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
       .add(attr("srcs", LABEL_LIST).allowedFileTypes(FileTypeSet.ANY_FILE))
       /*<!-- #BLAZE_RULE(filegroup).ATTRIBUTE(data) -->
       The list of files needed by this rule at runtime.
       ${SYNOPSIS}
       <p>
         Targets named in the <code>data</code> attribute will be added to the
         <code>runfiles</code> of this <code>filegroup</code> rule. When the
         <code>filegroup</code> is referenced in the <code>data</code> attribute of
         another rule its <code>runfiles</code> will be added to the <code>runfiles</code>
         of the depending rule. See the <a href="build-ref.html#data">data dependencies</a>
         section and <a href="#common.data">general documentation of <code>data</code></a>
         for more information about how to depend on and use data files.
       </p>
       <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
       .add(attr("data", LABEL_LIST).cfg(DATA).allowedFileTypes(FileTypeSet.ANY_FILE))
       .add(attr("output_licenses", LICENSE))
       /*<!-- #BLAZE_RULE(filegroup).ATTRIBUTE(path) -->
       An optional string to set a path to the files in the group, relative to the package path.
       ${SYNOPSIS}
       <p>
         This attribute can be used internally by other rules depending on this
         <code>filegroup</code> to find the name of the directory holding the files.
       </p>
       <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
       .add(attr("path", STRING))
       .build();
 }
Beispiel #20
0
 @Override
 public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
   return builder
       /* <!-- #BLAZE_RULE(ios_device).ATTRIBUTE(ios_version) -->
       The operating system version of the device. This corresponds to the
       <code>simctl</code> runtime.
       ${SYNOPSIS}
       <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
       .add(attr("ios_version", STRING).mandatory())
       /* <!-- #BLAZE_RULE(ios_device).ATTRIBUTE(type) -->
       The hardware type. This corresponds to the <code>simctl</code> device
       type.
       ${SYNOPSIS}
       <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
       .add(attr("type", STRING).mandatory())
       .add(
           attr("locale", STRING)
               .undocumented("this is not yet supported by any test runner")
               .value("en"))
       .build();
 }
Beispiel #21
0
  @Override
  public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
    return builder
        /* <!-- #BLAZE_RULE(maven_jar).ATTRIBUTE(artifact) -->
        A description of a Maven artifact using
        <a href="https://maven.apache.org/pom.html#Maven_Coordinates">Maven coordinates</a>.

        <p>These descriptions are of the form &lt;groupId&gt:&lt;artifactId&gt;:&lt;version&gt;,
        see <a href="#maven_jar_examples">the documentation below</a> for an example.
        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
        .add(attr("artifact", Type.STRING))
        .add(attr("artifact_id", Type.STRING).undocumented("deprecated"))
        .add(attr("group_id", Type.STRING).undocumented("deprecated"))
        .add(attr("version", Type.STRING).undocumented("deprecated"))
        /* <!-- #BLAZE_RULE(maven_jar).ATTRIBUTE(repository) -->
        A URL for a Maven repository to fetch the jar from.

        <p>Either this or <code>server</code> can be specified. Defaults to Maven Central
         ("central.maven.org").</p>
        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
        .add(attr("repository", Type.STRING))
        /* <!-- #BLAZE_RULE(maven_jar).ATTRIBUTE(server) -->
        A maven_server to use for this artifact.

        <p>Either this or <code>repository</code> can be specified.</p>
        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
        .add(attr("server", Type.STRING))
        /* <!-- #BLAZE_RULE(maven_jar).ATTRIBUTE(sha1) -->
        A SHA-1 hash of the desired jar.

        <p>If the downloaded jar does not match this hash, Bazel will error out. <em>It is a
        security risk to omit the SHA-1 as remote files can change.</em> At best omitting this
        field will make your build non-hermetic. It is optional to make development easier but
        should be set before shipping.</p>
        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
        .add(attr("sha1", Type.STRING))
        .setWorkspaceOnly()
        .build();
  }
    @Override
    public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
      return builder
          /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(deps) -->
          The list of other libraries to be linked in to the target.
          ${SYNOPSIS}
          See general comments about <code>deps</code> at <a href="#common-attributes">Attributes
          common to all build rules</a>.
          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
          .override(
              builder
                  .copy("deps")
                  .allowedFileTypes(JavaSemantics.JAR)
                  .allowedRuleClasses(ALLOWED_RULES_IN_DEPS)
                  .skipAnalysisTimeFileTypeCheck())
          /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(runtime_deps) -->
          Libraries to make available to the final binary or test at runtime only.
          ${SYNOPSIS}
          Like ordinary <code>deps</code>, these will appear on the runtime classpath, but unlike
          them, not on the compile-time classpath. Dependencies needed only at runtime should be
          listed here. Dependency-analysis tools should ignore targets that appear in both
          <code>runtime_deps</code> and <code>deps</code>.
          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
          .add(
              attr("runtime_deps", LABEL_LIST)
                  .allowedFileTypes(JavaSemantics.JAR)
                  .allowedRuleClasses(ALLOWED_RULES_IN_DEPS)
                  .skipAnalysisTimeFileTypeCheck())

          /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(srcs) -->
          The list of source files that are processed to create the target.
          ${SYNOPSIS}
          This attribute is almost always required; see exceptions below.
          <p>
            Source files of type <code>.java</code> are compiled. In case of generated
            <code>.java</code> files it is generally advisable to put the generating rule's name
            here instead of the name of the file itself. This not only improves readability but
            makes the rule more resilient to future changes: if the generating rule generates
            different files in the future, you only need to fix one place: the <code>outs</code> of
            the generating rule. You should not list the generating rule in <code>deps</code>
            because it is a no-op.
          </p>
          <p>
            Source files of type <code>.srcjar</code> are unpacked and compiled. (This is useful if
            you need to generate a set of <code>.java</code> files with a genrule.)
          </p>
          <p>
            Source files of type <code>.jar</code> are linked in. <em class="harmful">This is
            discouraged, use <a href="#java_import"><code>java_import</code></a></em> if you need to
            link against existing (or generated) jar files (which is useful if you have a
            <code>.jar</code> file without sources).
          </p>
          <p>
            Rules: if the rule (typically <code>genrule</code> or <code>filegroup</code>) generates
            any of the files listed above, they will be used the same way as described for source
            files.
          </p>

          <p>
            This argument is almost always required, except if a
            <a href="#java_binary.main_class"><code>main_class</code></a> attribute specifies a
            class on the runtime classpath or you specify the <code>runtime_deps</code> argument.
          </p>
          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
          .add(
              attr("srcs", LABEL_LIST)
                  .orderIndependent()
                  .direct_compile_time_input()
                  .allowedFileTypes(
                      JavaSemantics.JAVA_SOURCE,
                      JavaSemantics.JAR,
                      JavaSemantics.SOURCE_JAR,
                      JavaSemantics.PROPERTIES))
          /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(resources) -->
          A list of data files to include in a Java jar.
          ${SYNOPSIS}
          <p>
            If resources are specified, they will be bundled in the jar along with the usual
            <code>.class</code> files produced by compilation. The location of the resources inside
            of the jar file is determined by the project structure. Bazel first looks for Maven's
            <a href="https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html">standard directory layout</a>,
            (a "src" directory followed by a "resources" directory grandchild). If that is not
            found, Bazel then looks for the topmost directory named "java" or "javatests" (so, for
            example, if a resource is at &lt;workspace root&gt;/x/java/y/java/z, Bazel will use the
             path y/java/z. This heuristic cannot be overridden.
          </p>

          <p>
            Resources may be source files or generated files.
          </p>
          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
          .add(
              attr("resources", LABEL_LIST)
                  .orderIndependent()
                  .allowedFileTypes(FileTypeSet.ANY_FILE))
          /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(resource_strip_prefix) -->
          The path prefix to strip from Java resources.
          ${SYNOPSIS}
          <p>
            If specified, this path prefix is stripped from every file in the <code>resources</code>
            attribute. It is an error for a resource file not to be under this directory. If not
            specified (the default), the path of resource file is determined according to the same
            logic as the Java package of source files. For example, a source file at
            <code>stuff/java/foo/bar/a.txt</code> will be located at <code>foo/bar/a.txt</code>.
          </p>
          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
          .add(attr("resource_strip_prefix", STRING))
          /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(plugins) -->
          Java compiler plugins to run at compile-time.
          ${SYNOPSIS}
          Every <code>java_plugin</code> specified in this attribute will be run whenever this rule
          is built. A library may also inherit plugins from dependencies that use
          <code><a href="#java_library.exported_plugins">exported_plugins</a></code>. Resources
          generated by the plugin will be included in the resulting jar of this rule.
          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
          .add(
              attr("plugins", LABEL_LIST)
                  .cfg(HOST)
                  .allowedRuleClasses("java_plugin")
                  .legacyAllowAnyFileType())
          .add(
              attr(":java_plugins", LABEL_LIST)
                  .cfg(HOST)
                  .allowedRuleClasses("java_plugin")
                  .silentRuleClassFilter()
                  .value(JavaSemantics.JAVA_PLUGINS))
          /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(javacopts) -->
          Extra compiler options for this library.
          ${SYNOPSIS}
          Subject to <a href="#make_variables">"Make variable"</a> substitution and
          <a href="#sh-tokenization">Bourne shell tokenization</a>.
          <p>These compiler options are passed to javac after the global compiler options.</p>
          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
          .add(attr("javacopts", STRING_LIST))
          .build();
    }
 @Override
 public RuleClass build(Builder builder, final RuleDefinitionEnvironment env) {
   return builder
       /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(classpath_resources) -->
       ${SYNOPSIS}
       <em class="harmful">DO NOT USE THIS OPTION UNLESS THERE IS NO OTHER WAY)</em>
       <p>
         A list of resources that must be located at the root of the java tree. This attribute's
         only purpose is to support third-party libraries that require that their resources be
         found on the classpath as exactly <code>"myconfig.xml"</code>. It is only allowed on
         binaries and not libraries, due to the danger of namespace conflicts.
       </p>
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("classpath_resources", LABEL_LIST).legacyAllowAnyFileType())
       /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(jvm_flags) -->
       A list of flags to embed in the wrapper script generated for running this binary.
       ${SYNOPSIS}
       Subject to <a href="#make_variables">"Make variable"</a> substitution and
       <a href="#sh-tokenization">Bourne shell tokenization</a>.
       <p>
         The wrapper script for a Java binary includes a <code>CLASSPATH</code> definition (to
         find all the dependent jars) and invokes the right Java interpreter. The command line
         generated by the wrapper script includes the name of the main class followed by a
         <code>"$@"</code> so you can pass along other arguments after the classname.  However,
         arguments intended for parsing by the JVM must be specified <i>before</i> the classname
         on the command line. The contents of <code>jvm_flags</code> are added to the wrapper
         script before the classname is listed.
       </p>
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("jvm_flags", STRING_LIST))
       /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(main_class) -->
       Name of class with <code>main()</code> method to use as entry point.
       ${SYNOPSIS}
       If a rule uses this option, it does not need a <code>srcs=[...]</code> list.
       Thus, with this attribute one can make an executable from a Java library that already
       contains one or more <code>main()</code> methods.
       <p>
         The value of this attribute is a class name, not a source file. The class must be
         available at runtime: it may be compiled by this rule (from <code>srcs</code>) or
         provided by direct or transitive dependencies (through <code>runtime_deps</code> or
         <code>deps</code>). If the class is unavailable, the binary will fail at runtime; there
         is no build-time check.
       </p>
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("main_class", STRING))
       /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(create_executable) -->
       Whether to build the executable wrapper script or not.
       ${SYNOPSIS}
       If this option is present, no executable wrapper script is built around the
       <code>.jar</code> file. Incompatible with <code>main_class</code> attribute.
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("create_executable", BOOLEAN).nonconfigurable("internal").value(true))
       /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(deploy_manifest_lines) -->
       ${SYNOPSIS}
       A list of lines to add to the <code>META-INF/manifest.mf</code> file generated for the
       <code>*_deploy.jar</code> target. The contents of this attribute are <em>not</em> subject
       to <a href="#make_variables">"Make variable"</a> substitution.
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       .add(attr("deploy_manifest_lines", STRING_LIST))
       /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(stamp) -->
       Enable link stamping.
       ${SYNOPSIS}
       Whether to encode build information into the binary. Possible values:
       <ul>
         <li><code>stamp = 1</code>: Stamp the build information into the binary. Stamped
           binaries are only rebuilt when their dependencies change. Use this if there are tests
           that depend on the build information.</li>
         <li><code>stamp = 0</code>: Always replace build information by constant values. This
           gives good build result caching.</li>
         <li><code>stamp = -1</code>: Embedding of build information is controlled by the
           <a href="blaze-user-manual.html#flag--stamp">--[no]stamp</a> flag.</li>
       </ul>
       <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
       // TODO(bazel-team): describe how to access this data at runtime
       .add(attr("stamp", TRISTATE).value(TriState.AUTO))
       .add(attr(":java_launcher", LABEL).value(JavaSemantics.JAVA_LAUNCHER)) // blaze flag
       .build();
 }