@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 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(); }
@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(); }
@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(); }
@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 .add( attr("foo", LABEL_LIST) .allowedFileTypes(FileTypeSet.ANY_FILE) .aspect(ErrorAspect.class)) .add(attr("bar", LABEL_LIST).allowedFileTypes(FileTypeSet.ANY_FILE)) .build(); }
@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(); }
@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(); }
@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(); }
@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(); }
@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 <groupId>:<artifactId>:<version>, 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, 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(); }