Update rules_java v8.0.0-rc2 & stop exporting the java rules from `@_builtins`
- keeps the native stub definitions for now
- cleanup of the rules & updating to rules_java v8.0.0 will be in a followup
PiperOrigin-RevId: 682810444
Change-Id: I9dee6631697309af157655f0814532506e94cb2e
diff --git a/src/MODULE.tools b/src/MODULE.tools
index 412884d..265e028 100644
--- a/src/MODULE.tools
+++ b/src/MODULE.tools
@@ -41,8 +41,8 @@
# Dependencies used to auto-load removed symbols and rules from Bazel (due to Starlarkification)
# See also: --incompatible_autoload_externally, AutoloadSymbols
-bazel_dep(name = "protobuf", version = "24.4", repo_name = "com_google_protobuf")
-bazel_dep(name = "rules_java", version = "7.12.1")
+bazel_dep(name = "protobuf", version = "27.0", repo_name = "com_google_protobuf")
+bazel_dep(name = "rules_java", version = "8.0.0-rc2")
bazel_dep(name = "rules_cc", version = "0.0.10")
bazel_dep(name = "rules_python", version = "0.36.0")
# add rules_android
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/rules/BUILD
index d4aab29..1d74391 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BUILD
@@ -47,7 +47,6 @@
"//src/main/java/com/google/devtools/build/lib/bazel/repository",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/cpp",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/genrule",
- "//src/main/java/com/google/devtools/build/lib/bazel/rules/java",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/java:bazel_java_semantics",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/python",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/sh",
@@ -145,6 +144,7 @@
""",
repos = [
"bazel_skylib", # Dependency of other rules
+ "protobuf", # dependency of rules_java
"rules_java", # For auto-load java rules symbols
"rules_cc", # For auto-load cc rules symbols
"rules_python", # For auto-load python rules symbols
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/JavaRules.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/JavaRules.java
index 373ff25..d211f65 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/JavaRules.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/JavaRules.java
@@ -19,8 +19,6 @@
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider.RuleSet;
-import com.google.devtools.build.lib.bazel.rules.java.BazelJavaBinaryRule;
-import com.google.devtools.build.lib.bazel.rules.java.BazelJavaRuleClasses;
import com.google.devtools.build.lib.bazel.rules.java.BazelJavaSemantics;
import com.google.devtools.build.lib.rules.core.CoreRules;
import com.google.devtools.build.lib.rules.extra.ActionListenerRule;
@@ -49,12 +47,9 @@
public void init(ConfiguredRuleClassProvider.Builder builder) {
builder.addConfigurationFragment(JavaConfiguration.class);
- builder.addRuleDefinition(new BazelJavaRuleClasses.BaseJavaBinaryRule());
builder.addRuleDefinition(new JavaToolchainBaseRule());
builder.addRuleDefinition(new JavaRuntimeBaseRule());
- builder.addRuleDefinition(new BazelJavaRuleClasses.JavaBaseRule());
- builder.addRuleDefinition(new BazelJavaRuleClasses.JavaRule());
- builder.addRuleDefinition(new BazelJavaBinaryRule());
+ builder.addRuleDefinition(new BaseRuleClasses.EmptyRule("java_binary") {});
builder.addRuleDefinition(new BaseRuleClasses.EmptyRule("java_library") {});
builder.addRuleDefinition(new BaseRuleClasses.EmptyRule("java_import") {});
builder.addRuleDefinition(new BaseRuleClasses.EmptyRule("java_test") {});
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BUILD
index 826e0b3..0d0555d 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BUILD
@@ -14,30 +14,6 @@
exports_files(["java_stub_template.txt"])
java_library(
- name = "java",
- srcs = glob(
- ["*.java"],
- exclude = ["BazelJavaSemantics.java"],
- ),
- resources = glob(
- [
- "*.txt",
- ],
- ),
- deps = [
- "//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
- "//src/main/java/com/google/devtools/build/lib/analysis:config/execution_transition_factory",
- "//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment",
- "//src/main/java/com/google/devtools/build/lib/bazel/rules/cpp",
- "//src/main/java/com/google/devtools/build/lib/packages",
- "//src/main/java/com/google/devtools/build/lib/rules/cpp",
- "//src/main/java/com/google/devtools/build/lib/rules/java:java-compilation",
- "//src/main/java/com/google/devtools/build/lib/util:filetype",
- "//third_party:guava",
- ],
-)
-
-java_library(
name = "bazel_java_semantics",
srcs = ["BazelJavaSemantics.java"],
deps = [
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBinaryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBinaryRule.java
deleted file mode 100644
index ddb2432..0000000
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBinaryRule.java
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.bazel.rules.java;
-
-import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
-
-import com.google.devtools.build.lib.analysis.BaseRuleClasses.BinaryBaseRule;
-import com.google.devtools.build.lib.analysis.BaseRuleClasses.EmptyRuleConfiguredTargetFactory;
-import com.google.devtools.build.lib.analysis.RuleDefinition;
-import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
-import com.google.devtools.build.lib.bazel.rules.java.BazelJavaRuleClasses.BaseJavaBinaryRule;
-import com.google.devtools.build.lib.packages.RuleClass;
-import com.google.devtools.build.lib.util.FileTypeSet;
-
-/**
- * Rule definition for the java_binary rule.
- *
- * <p>This rule is implemented in Starlark. This class remains only for doc-gen purposes.
- */
-public final class BazelJavaBinaryRule implements RuleDefinition {
- @Override
- public RuleClass build(RuleClass.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
- /* <!-- #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><<var>name</var>>_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="${link 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>
- <p>If your target specifies a <a href="#java_binary.launcher">launcher</a>
- attribute, then instead of being a normal JAR file, the _deploy.jar will be a
- native binary. This will contain the launcher plus any native (C++) dependencies of
- your rule, all linked into a static binary. The actual jar file's bytes will be
- appended to that native binary, creating a single binary blob containing both the
- executable and the Java code. You can execute the resulting jar file directly
- like you would execute any native binary.</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>
- </ul>
- <!-- #END_BLAZE_RULE.IMPLICIT_OUTPUTS --> */
- /* <!-- #BLAZE_RULE(java_binary).ATTRIBUTE(deploy_env) -->
- A list of other <code>java_binary</code> targets which represent the deployment
- environment for this binary.
- Set this attribute when building a plugin which will be loaded by another
- <code>java_binary</code>.<br/> Setting this attribute excludes all dependencies from
- the runtime classpath (and the deploy jar) of this binary that are shared between this
- binary and the targets specified in <code>deploy_env</code>.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(
- attr("deploy_env", LABEL_LIST)
- .allowedRuleClasses("java_binary")
- .allowedFileTypes(FileTypeSet.NO_FILE))
- .build();
- }
-
- @Override
- public Metadata getMetadata() {
- return Metadata.builder()
- .name("java_binary")
- .ancestors(BaseJavaBinaryRule.class, BinaryBaseRule.class)
- .factoryClass(EmptyRuleConfiguredTargetFactory.class)
- .build();
- }
-}
-
-/*<!-- #BLAZE_RULE (NAME = java_binary, TYPE = BINARY, FAMILY = Java) -->
-
-<p>
- Builds a Java archive ("jar file"), plus a wrapper shell script with the same name as the rule.
- The wrapper shell script uses a classpath that includes, among other things, a jar file for each
- library on which the binary depends. When running the wrapper shell script, any nonempty
- <code>JAVABIN</code> environment variable will take precedence over the version specified via
- Bazel's <code>--java_runtime_version</code> flag.
-</p>
-<p>
- The wrapper script accepts several unique flags. Refer to
- <code>//src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt</code>
- for a list of configurable flags and environment variables accepted by the wrapper.
-</p>
-
-${IMPLICIT_OUTPUTS}
-
-<p>
- A <code>deps</code> attribute is not allowed in a <code>java_binary</code> rule without
- <a href="${link java_binary.srcs}"><code>srcs</code></a>; such a rule requires a
- <a href="${link java_binary.main_class}"><code>main_class</code></a> provided by
- <a href="${link java_binary.runtime_deps}"><code>runtime_deps</code></a>.
-</p>
-
-<p>The following code snippet illustrates a common mistake:</p>
-
-<pre class="code">
-java_binary(
- name = "DontDoThis",
- srcs = [
- ...,
- "GeneratedJavaFile.java", # a generated .java file
- ],
- deps = [":generating_rule"], # rule that generates that file
-)
-</pre>
-
-<p>Do this instead:</p>
-
-<pre class="code">
-java_binary(
- name = "DoThisInstead",
- srcs = [
- ...,
- ":generating_rule",
- ],
-)
-</pre>
-
-<!-- #END_BLAZE_RULE -->*/
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java
deleted file mode 100644
index 1c40d1a..0000000
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java
+++ /dev/null
@@ -1,410 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.bazel.rules.java;
-
-import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.BuildType.LABEL;
-import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Types.STRING_LIST;
-import static com.google.devtools.build.lib.rules.java.JavaRuleClasses.CONTAINS_JAVA_PROVIDER;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.devtools.build.lib.analysis.BaseRuleClasses;
-import com.google.devtools.build.lib.analysis.RuleDefinition;
-import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
-import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
-import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses.CcToolchainRequiringRule;
-import com.google.devtools.build.lib.packages.RuleClass;
-import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
-import com.google.devtools.build.lib.packages.StarlarkProviderIdentifier;
-import com.google.devtools.build.lib.packages.TriState;
-import com.google.devtools.build.lib.rules.cpp.CcInfo;
-import com.google.devtools.build.lib.rules.cpp.CcLauncherInfo;
-import com.google.devtools.build.lib.rules.java.JavaInfo;
-import com.google.devtools.build.lib.rules.java.JavaPluginInfo;
-import com.google.devtools.build.lib.rules.java.JavaRuleClasses.JavaRuntimeBaseRule;
-import com.google.devtools.build.lib.rules.java.JavaRuleClasses.JavaToolchainBaseRule;
-import com.google.devtools.build.lib.rules.java.JavaSemantics;
-import com.google.devtools.build.lib.util.FileTypeSet;
-
-/**
- * Rule class definitions for Java rules.
- */
-public class BazelJavaRuleClasses {
- public static final ImmutableList<StarlarkProviderIdentifier> CONTAINS_CC_LINK_PARAMS =
- ImmutableList.of(StarlarkProviderIdentifier.forKey(CcInfo.PROVIDER.getKey()));
-
- /**
- * Meant to be the value of {@code mandatoryProvidersLists} in order for the rule to provide only
- * a {@link JavaInfo} through an attribute.
- */
- public static final ImmutableList<ImmutableList<StarlarkProviderIdentifier>>
- MANDATORY_JAVA_PROVIDER_ONLY = ImmutableList.of(CONTAINS_JAVA_PROVIDER);
-
- /** Common attributes for Java rules. */
- public static final class JavaBaseRule implements RuleDefinition {
- @Override
- public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
- return builder.build();
- }
-
- @Override
- public Metadata getMetadata() {
- return RuleDefinition.Metadata.builder()
- .name("$java_base_rule")
- .type(RuleClassType.ABSTRACT)
- .ancestors(JavaToolchainBaseRule.class)
- .build();
- }
- }
-
- static final ImmutableSet<String> ALLOWED_RULES_IN_DEPS =
- ImmutableSet.of(
- "cc_binary", // NB: linkshared=1
- "cc_library",
- "genrule",
- "genproto", // TODO(bazel-team): we should filter using providers instead (starlark rule).
- "java_import",
- "java_library",
- "java_proto_library",
- "java_lite_proto_library",
- "proto_library",
- "sh_binary",
- "sh_library");
-
- /**
- * Common attributes for Java rules.
- */
- public static final class JavaRule implements RuleDefinition {
- @Override
- public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
- return builder
- /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(deps) -->
- The list of other libraries to be linked in to the target.
- See general comments about <code>deps</code> at
- <a href="common-definitions.html#typical-attributes">Typical attributes defined by
- most build rules</a>.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .override(
- builder
- .copy("deps")
- .allowedFileTypes(JavaSemantics.JAR)
- .allowedRuleClasses(ALLOWED_RULES_IN_DEPS)
- .mandatoryProvidersList(
- ImmutableList.of(CONTAINS_CC_LINK_PARAMS, CONTAINS_JAVA_PROVIDER))
- .skipAnalysisTimeFileTypeCheck())
- /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(runtime_deps) -->
- Libraries to make available to the final binary or test at runtime only.
- 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)
- .mandatoryProvidersList(MANDATORY_JAVA_PROVIDER_ONLY)
- .skipAnalysisTimeFileTypeCheck())
-
- /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(srcs) -->
- The list of source files that are processed to create the target.
- 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>
- 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.SOURCE_JAR,
- JavaSemantics.PROPERTIES))
- /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(resources) -->
- A list of data files to include in a Java jar.
- <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 <code><workspace root>/x/java/y/java/z</code>, the
- path of the resource will be <code>y/java/z</code>. This heuristic cannot be overridden,
- however, the <code>resource_strip_prefix</code> attribute can be used to specify a
- specific alternative directory for resource files.
- </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)
- .dontCheckConstraints())
- /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(resource_strip_prefix) -->
- The path prefix to strip from Java resources.
- <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(resource_jars) -->
- Deprecated: Use java_import and deps or runtime_deps instead.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(
- attr("resource_jars", LABEL_LIST)
- .orderIndependent()
- .allowedFileTypes(JavaSemantics.JAR))
- /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(plugins) -->
- Java compiler plugins to run at compile-time.
- 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(ExecutionTransitionFactory.createFactory())
- .mandatoryProviders(JavaPluginInfo.PROVIDER.id())
- .legacyAllowAnyFileType())
- /* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(javacopts) -->
- Extra compiler options for this library.
- Subject to <a href="make-variables.html">"Make variable"</a> substitution and
- <a href="common-definitions.html#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 Metadata getMetadata() {
- return RuleDefinition.Metadata.builder()
- .name("$java_rule")
- .type(RuleClassType.ABSTRACT)
- .ancestors(BaseRuleClasses.NativeActionCreatingRule.class, JavaBaseRule.class)
- .build();
- }
- }
-
- /**
- * Base class for rule definitions producing Java binaries.
- */
- public static final class BaseJavaBinaryRule implements RuleDefinition {
-
- @Override
- public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironment env) {
- return builder
- /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(classpath_resources) -->
- <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.
- Subject to <a href="${link make-variables#location}">$(location)</a> and
- <a href="make-variables.html">"Make variable"</a> substitution, and
- <a href="common-definitions.html#sh-tokenization">Bourne shell tokenization</a>.
-
- <p>The wrapper script for a Java binary includes a CLASSPATH 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>
-
- <p>Note that this attribute has <em>no effect</em> on <code>*_deploy.jar</code>
- outputs.</p>
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("jvm_flags", STRING_LIST))
- /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(use_testrunner) -->
- Use the test runner (by default
- <code>com.google.testing.junit.runner.BazelTestRunner</code>) class as the
- main entry point for a Java program, and provide the test class
- to the test runner as a value of <code>bazel.test_suite</code>
- system property.
-
- You can use this to override the default
- behavior, which is to use test runner for
- <code>java_test</code> rules,
- and not use it for <code>java_binary</code> rules. It is unlikely
- you will want to do this. One use is for <code>AllTest</code>
- rules that are invoked by another rule (to set up a database
- before running the tests, for example). The <code>AllTest</code>
- rule must be declared as a <code>java_binary</code>, but should
- still use the test runner as its main entry point.
-
- The name of a test runner class can be overridden with <code>main_class</code> attribute.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("use_testrunner", BOOLEAN).value(false))
- /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(main_class) -->
- Name of class with <code>main()</code> method to use as entry point.
- 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) -->
- Deprecated, use <code>java_single_jar</code> instead.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("create_executable", BOOLEAN).nonconfigurable("internal").value(true))
- /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(deploy_manifest_lines) -->
- 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.html">"Make variable"</a> substitution.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("deploy_manifest_lines", STRING_LIST))
- /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(stamp) -->
- Whether to encode build information into the binary. Possible values:
- <ul>
- <li>
- <code>stamp = 1</code>: Always stamp the build information into the binary, even in
- <a href="${link user-manual#flag--stamp}"><code>--nostamp</code></a> builds. <b>This
- setting should be avoided</b>, since it potentially kills remote caching for the
- binary and any downstream actions that depend on it.
- </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="${link user-manual#flag--stamp}"><code>--[no]stamp</code></a> flag.
- </li>
- </ul>
- <p>Stamped binaries are <em>not</em> rebuilt unless their dependencies change.</p>
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- // TODO(bazel-team): describe how to access this data at runtime
- .add(attr("stamp", TRISTATE).value(TriState.AUTO))
- /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(launcher) -->
- Specify a binary that will be used to run your Java program instead of the
- normal <code>bin/java</code> program included with the JDK.
- The target must be a <code>cc_binary</code>. Any <code>cc_binary</code> that
- implements the
- <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html">
- Java Invocation API</a> can be specified as a value for this attribute.
-
- <p>By default, Bazel will use the normal JDK launcher (bin/java or java.exe).</p>
-
- <p>The related <a href="${link user-manual#flag--java_launcher}"><code>
- --java_launcher</code></a> Bazel flag affects only those
- <code>java_binary</code> and <code>java_test</code> targets that have
- <i>not</i> specified a <code>launcher</code> attribute.</p>
-
- <p>Note that your native (C++, SWIG, JNI) dependencies will be built differently
- depending on whether you are using the JDK launcher or another launcher:</p>
-
- <ul>
- <li>If you are using the normal JDK launcher (the default), native dependencies are
- built as a shared library named <code>{name}_nativedeps.so</code>, where
- <code>{name}</code> is the <code>name</code> attribute of this java_binary rule.
- Unused code is <em>not</em> removed by the linker in this configuration.</li>
-
- <li>If you are using any other launcher, native (C++) dependencies are statically
- linked into a binary named <code>{name}_nativedeps</code>, where <code>{name}</code>
- is the <code>name</code> attribute of this java_binary rule. In this case,
- the linker will remove any code it thinks is unused from the resulting binary,
- which means any C++ code accessed only via JNI may not be linked in unless
- that <code>cc_library</code> target specifies <code>alwayslink = 1</code>.</li>
- </ul>
-
- <p>When using any launcher other than the default JDK launcher, the format
- of the <code>*_deploy.jar</code> output changes. See the main
- <a href="#java_binary">java_binary</a> docs for details.</p>
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(
- attr("launcher", LABEL)
- .allowedFileTypes(FileTypeSet.NO_FILE)
- .mandatoryProviders(
- StarlarkProviderIdentifier.forKey(CcLauncherInfo.PROVIDER.getKey())))
- /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(use_launcher) -->
- Whether the binary should use a custom launcher.
-
- <p>If this attribute is set to false, the
- <a href="${link java_binary.launcher}">launcher</a> attribute and the related
- <a href="${link user-manual#flag--java_launcher}"><code>--java_launcher</code></a> flag
- will be ignored for this target.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("use_launcher", BOOLEAN).value(true))
- .add(
- attr("$launcher", LABEL)
- .cfg(ExecutionTransitionFactory.createFactory())
- .value(env.getToolsLabel("//tools/launcher:launcher")))
- .build();
- }
- @Override
- public Metadata getMetadata() {
- return RuleDefinition.Metadata.builder()
- .name("$base_java_binary")
- .type(RuleClassType.ABSTRACT)
- .ancestors(
- JavaRule.class,
- JavaRuntimeBaseRule.class,
- // java_binary and java_test require the crosstool C++ runtime
- // libraries (libstdc++.so, libgcc_s.so).
- // TODO(bazel-team): Add tests for Java+dynamic runtime.
- CcToolchainRequiringRule.class)
- .build();
- }
- }
-}
diff --git a/src/main/starlark/builtins_bzl/bazel/exports.bzl b/src/main/starlark/builtins_bzl/bazel/exports.bzl
index 9619805..a231fe7 100644
--- a/src/main/starlark/builtins_bzl/bazel/exports.bzl
+++ b/src/main/starlark/builtins_bzl/bazel/exports.bzl
@@ -15,15 +15,11 @@
"""Exported builtins symbols that are specific to OSS Bazel."""
load("@_builtins//:common/cc/cc_proto_library.bzl", "cc_proto_aspect", "cc_proto_library")
-load("@_builtins//:common/java/java_import.bzl", "java_import")
-load("@_builtins//:common/java/java_library.bzl", "JAVA_LIBRARY_ATTRS", "bazel_java_library_rule", "java_library")
-load("@_builtins//:common/java/java_plugin.bzl", "java_plugin")
+load("@_builtins//:common/java/java_library.bzl", "JAVA_LIBRARY_ATTRS", "bazel_java_library_rule")
load("@_builtins//:common/java/proto/java_proto_library.bzl", "java_proto_library")
load("@_builtins//:common/proto/proto_library.bzl", "proto_library")
load("@_builtins//:common/python/py_internal.bzl", "py_internal")
load("@_builtins//:common/python/py_runtime_macro.bzl", "py_runtime") # still used in @bazel_tools
-load(":bazel/java/bazel_java_binary.bzl", "java_test")
-load(":bazel/java/bazel_java_binary_wrapper.bzl", "java_binary")
load(":bazel/sh/sh_library.bzl", "sh_library")
load(":common/java/java_package_configuration.bzl", "java_package_configuration")
load(":common/java/java_runtime.bzl", "java_runtime")
@@ -42,13 +38,8 @@
}
exported_rules = {
"proto_library": proto_library,
- "java_library": java_library,
- "java_plugin": java_plugin,
- "java_import": java_import,
"java_proto_library": java_proto_library,
"cc_proto_library": cc_proto_library,
- "java_binary": java_binary,
- "java_test": java_test,
"java_package_configuration": java_package_configuration,
"java_runtime": java_runtime,
"java_toolchain": java_toolchain,
diff --git a/src/main/starlark/docgen/BUILD b/src/main/starlark/docgen/BUILD
index 827809d..d9255f0 100644
--- a/src/main/starlark/docgen/BUILD
+++ b/src/main/starlark/docgen/BUILD
@@ -12,6 +12,10 @@
starlark_doc_extract(
name = "gen_be_java_stardoc_proto",
src = "java.bzl",
+ deps = [
+ "@protobuf//bazel/common:proto_info_bzl",
+ "@rules_java//java/bazel/rules",
+ ],
)
starlark_doc_extract(
diff --git a/src/main/starlark/docgen/java.bzl b/src/main/starlark/docgen/java.bzl
index fa43fd6..feba5b6 100644
--- a/src/main/starlark/docgen/java.bzl
+++ b/src/main/starlark/docgen/java.bzl
@@ -11,27 +11,34 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
"""Java"""
-# Build Encyclopedia entry point for Java rules implemented in Starlark in Bazel's @_builtins
+
+load("@rules_java//java/bazel/rules:bazel_java_binary.bzl", _java_binary = "java_binary")
+load("@rules_java//java/bazel/rules:bazel_java_import.bzl", _java_import = "java_import")
+load("@rules_java//java/bazel/rules:bazel_java_library.bzl", _java_library = "java_library")
+load("@rules_java//java/bazel/rules:bazel_java_plugin.bzl", _java_plugin = "java_plugin")
+load("@rules_java//java/bazel/rules:bazel_java_test.bzl", _java_test = "java_test")
+
+# Build Encyclopedia entry point for Java rules implemented in Starlark
binary_rules = struct(
+ java_binary = _java_binary,
)
library_rules = struct(
- java_import = native.java_import,
- java_library = native.java_library,
+ java_import = _java_import,
+ java_library = _java_library,
java_lite_proto_library = native.java_lite_proto_library,
java_proto_library = native.java_proto_library,
)
test_rules = struct(
- java_test = native.java_test,
+ java_test = _java_test,
)
other_rules = struct(
java_package_configuration = native.java_package_configuration,
- java_plugin = native.java_plugin,
+ java_plugin = _java_plugin,
java_runtime = native.java_runtime,
java_toolchain = native.java_toolchain,
)
diff --git a/src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh b/src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh
index 2a9e331..a059484 100755
--- a/src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh
+++ b/src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh
@@ -206,7 +206,13 @@
)
EOF
- bazel build --experimental_cc_static_library //pkg:protobuf \
+ # can be removed with protobuf v28.x onwards
+ if $is_windows; then
+ CXXOPTS=""
+ else
+ CXXOPTS="--cxxopt=-Wno-deprecated-declarations --host_cxxopt=-Wno-deprecated-declarations"
+ fi
+ bazel build $CXXOPTS --experimental_cc_static_library //pkg:protobuf \
&> $TEST_log || fail "Expected build to fail"
}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/BUILD b/src/test/java/com/google/devtools/build/lib/analysis/mock/BUILD
index aaa659e..11e1770 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/mock/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/BUILD
@@ -23,7 +23,7 @@
"@rules_cc//cc:srcs",
"@rules_cc//cc/common:srcs",
"@rules_cc//cc/toolchains:srcs",
- "@rules_java//java:rules",
+ "@rules_java//java:for_bazel_tests",
"@rules_java//toolchains:srcs",
"@rules_python//python:defs_bzl",
],
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
index 9458fab..e1efd57 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
@@ -36,6 +36,7 @@
import com.google.devtools.build.lib.packages.util.MockCcSupport;
import com.google.devtools.build.lib.packages.util.MockGenruleSupport;
import com.google.devtools.build.lib.packages.util.MockPlatformSupport;
+import com.google.devtools.build.lib.packages.util.MockProtoSupport;
import com.google.devtools.build.lib.packages.util.MockPythonSupport;
import com.google.devtools.build.lib.packages.util.MockToolsConfig;
import com.google.devtools.build.lib.rules.repository.RepositoryFunction;
@@ -217,145 +218,147 @@
config.create(
"embedded_tools/tools/jdk/BUILD",
"""
- load(
- ":java_toolchain_alias.bzl",
- "java_host_runtime_alias",
- "java_runtime_alias",
- "java_toolchain_alias",
- )
- load(":launcher_flag_alias.bzl", "launcher_flag_alias")
+load("@rules_java//java:defs.bzl",
+ "java_binary", "java_import", "java_toolchain")
+load(
+ ":java_toolchain_alias.bzl",
+ "java_host_runtime_alias",
+ "java_runtime_alias",
+ "java_toolchain_alias",
+)
+load(":launcher_flag_alias.bzl", "launcher_flag_alias")
- package(default_visibility = ["//visibility:public"])
+package(default_visibility = ["//visibility:public"])
- java_toolchain(
- name = "toolchain",
- bootclasspath = [":bootclasspath"],
- genclass = ["GenClass_deploy.jar"],
- header_compiler = ["turbine_deploy.jar"],
- header_compiler_direct = ["TurbineDirect_deploy.jar"],
- ijar = ["ijar"],
- jacocorunner = ":JacocoCoverage",
- java_runtime = "host_jdk",
- javabuilder = ["JavaBuilder_deploy.jar"],
- singlejar = ["singlejar"],
- source_version = "8",
- target_version = "8",
- )
+java_toolchain(
+ name = "toolchain",
+ bootclasspath = [":bootclasspath"],
+ genclass = ["GenClass_deploy.jar"],
+ header_compiler = ["turbine_deploy.jar"],
+ header_compiler_direct = ["TurbineDirect_deploy.jar"],
+ ijar = ["ijar"],
+ jacocorunner = ":JacocoCoverage",
+ java_runtime = "host_jdk",
+ javabuilder = ["JavaBuilder_deploy.jar"],
+ singlejar = ["singlejar"],
+ source_version = "8",
+ target_version = "8",
+)
- java_toolchain(
- name = "remote_toolchain",
- bootclasspath = [":bootclasspath"],
- genclass = ["GenClass_deploy.jar"],
- header_compiler = ["turbine_deploy.jar"],
- header_compiler_direct = ["TurbineDirect_deploy.jar"],
- ijar = ["ijar"],
- jacocorunner = ":JacocoCoverage",
- java_runtime = "host_jdk",
- javabuilder = ["JavaBuilder_deploy.jar"],
- singlejar = ["singlejar"],
- source_version = "8",
- target_version = "8",
- )
+java_toolchain(
+ name = "remote_toolchain",
+ bootclasspath = [":bootclasspath"],
+ genclass = ["GenClass_deploy.jar"],
+ header_compiler = ["turbine_deploy.jar"],
+ header_compiler_direct = ["TurbineDirect_deploy.jar"],
+ ijar = ["ijar"],
+ jacocorunner = ":JacocoCoverage",
+ java_runtime = "host_jdk",
+ javabuilder = ["JavaBuilder_deploy.jar"],
+ singlejar = ["singlejar"],
+ source_version = "8",
+ target_version = "8",
+)
- java_import(
- name = "JacocoCoverageRunner",
- jars = ["JacocoCoverage_jarjar_deploy.jar"],
- )
+java_import(
+ name = "JacocoCoverageRunner",
+ jars = ["JacocoCoverage_jarjar_deploy.jar"],
+)
- java_import(
- name = "proguard_import",
- jars = ["proguard_rt.jar"],
- )
+java_import(
+ name = "proguard_import",
+ jars = ["proguard_rt.jar"],
+)
- java_binary(
- name = "proguard",
- main_class = "proguard.Proguard",
- runtime_deps = [":proguard_import"],
- )
+java_binary(
+ name = "proguard",
+ main_class = "proguard.Proguard",
+ runtime_deps = [":proguard_import"],
+)
- java_import(
- name = "TestRunner",
- jars = ["TestRunner.jar"],
- )
+java_import(
+ name = "TestRunner",
+ jars = ["TestRunner.jar"],
+)
- java_runtime(
- name = "jdk",
- srcs = [],
- )
+java_runtime(
+ name = "jdk",
+ srcs = [],
+)
- java_runtime(
- name = "host_jdk",
- srcs = [],
- )
+java_runtime(
+ name = "host_jdk",
+ srcs = [],
+)
- java_runtime(
- name = "remote_jdk11",
- srcs = [],
- )
+java_runtime(
+ name = "remote_jdk11",
+ srcs = [],
+)
- java_toolchain_alias(name = "current_java_toolchain")
+java_toolchain_alias(name = "current_java_toolchain")
- java_runtime_alias(name = "current_java_runtime")
+java_runtime_alias(name = "current_java_runtime")
- java_host_runtime_alias(name = "current_host_java_runtime")
+java_host_runtime_alias(name = "current_host_java_runtime")
- filegroup(
- name = "bootclasspath",
- srcs = ["jdk/jre/lib/rt.jar"],
- )
+filegroup(
+ name = "bootclasspath",
+ srcs = ["jdk/jre/lib/rt.jar"],
+)
- filegroup(
- name = "extdir",
- srcs = glob(
- ["jdk/jre/lib/ext/*"],
- allow_empty = True,
- ),
- )
+filegroup(
+ name = "extdir",
+ srcs = glob(
+ ["jdk/jre/lib/ext/*"],
+ allow_empty = True,
+ ),
+)
- filegroup(
- name = "java",
- srcs = ["jdk/jre/bin/java"],
- )
+filegroup(
+ name = "java",
+ srcs = ["jdk/jre/bin/java"],
+)
- filegroup(
- name = "JacocoCoverage",
- srcs = ["JacocoCoverage_deploy.jar"],
- )
+filegroup(
+ name = "JacocoCoverage",
+ srcs = ["JacocoCoverage_deploy.jar"],
+)
- exports_files([
- "JavaBuilder_deploy.jar",
- "singlejar",
- "TestRunner_deploy.jar",
- "ijar",
- "GenClass_deploy.jar",
- "turbine_deploy.jar",
- "TurbineDirect_deploy.jar",
- "proguard_allowlister.par",
- ])
+exports_files([
+ "JavaBuilder_deploy.jar",
+ "singlejar",
+ "TestRunner_deploy.jar",
+ "ijar",
+ "GenClass_deploy.jar",
+ "turbine_deploy.jar",
+ "TurbineDirect_deploy.jar",
+ "proguard_allowlister.par",
+])
- toolchain_type(name = "toolchain_type")
+toolchain_type(name = "toolchain_type")
- toolchain_type(name = "runtime_toolchain_type")
+toolchain_type(name = "runtime_toolchain_type")
- toolchain(
- name = "dummy_java_toolchain",
- toolchain = ":toolchain",
- toolchain_type = ":toolchain_type",
- )
+toolchain(
+ name = "dummy_java_toolchain",
+ toolchain = ":toolchain",
+ toolchain_type = ":toolchain_type",
+)
- toolchain(
- name = "dummy_java_runtime_toolchain",
- toolchain = ":jdk",
- toolchain_type = ":runtime_toolchain_type",
- )
+toolchain(
+ name = "dummy_java_runtime_toolchain",
+ toolchain = ":jdk",
+ toolchain_type = ":runtime_toolchain_type",
+)
- java_plugins_flag_alias(name = "java_plugins_flag_alias")
+java_plugins_flag_alias(name = "java_plugins_flag_alias")
- launcher_flag_alias(
- name = "launcher_flag_alias",
- visibility = ["//visibility:public"],
- )
- """);
+launcher_flag_alias(
+ name = "launcher_flag_alias",
+ visibility = ["//visibility:public"],
+)
+""");
config.create(
TestConstants.CONSTRAINTS_PATH + "/android/BUILD",
@@ -372,19 +375,14 @@
// Create the actual SDKs.
config.create(
"embedded_tools/src/tools/android/java/com/google/devtools/build/android/r8/BUILD",
- "java_library(name='r8')\n");
+ """
+ filegroup(name='r8', srcs = [])
+ """);
config.create(
"android_gmaven_r8/jar/BUILD",
"""
- java_import(
- name = "jar",
- jars = ["r8.jar"],
- )
-
- filegroup(
- name = "file",
- srcs = [],
- )
+ filegroup(name = "jar", srcs = ["r8.jar"])
+ filegroup(name = "file", srcs = [])
""");
config.create("android_gmaven_r8/WORKSPACE");
@@ -686,7 +684,7 @@
packages = ["public"],
)
""");
-
+ MockProtoSupport.setupWorkspace(config);
MockPlatformSupport.setup(config);
ccSupport().setup(config);
javaSupport().setupRulesJava(config, runfiles::rlocation);
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AbstractMockJavaSupport.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AbstractMockJavaSupport.java
index d93584d..bfed88e 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/AbstractMockJavaSupport.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AbstractMockJavaSupport.java
@@ -13,14 +13,10 @@
// limitations under the License.
package com.google.devtools.build.lib.analysis.util;
-import static java.nio.charset.StandardCharsets.UTF_8;
-import com.google.common.collect.ImmutableList;
-import com.google.common.io.MoreFiles;
import com.google.devtools.build.lib.packages.util.MockToolsConfig;
+import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
import java.util.function.Function;
public abstract class AbstractMockJavaSupport {
@@ -32,36 +28,20 @@
MockToolsConfig config, Function<String, String> runfilesResolver) throws IOException {
config.create("rules_java_workspace/WORKSPACE", "workspace(name = 'rules_java')");
config.create("rules_java_workspace/MODULE.bazel", "module(name = 'rules_java')");
- config.create("rules_java_workspace/java/BUILD");
- config.create("rules_java_workspace/java/common/BUILD");
- config.create("rules_java_workspace/java/private/BUILD");
- config.create("rules_java_workspace/java/toolchains/BUILD");
- config.create("rules_java_workspace/toolchains/BUILD");
- ImmutableList<String> toolsToCopy =
- ImmutableList.of(
- "java/defs.bzl",
- "java/java_binary.bzl",
- "java/java_import.bzl",
- "java/java_library.bzl",
- "java/java_plugin.bzl",
- "java/java_test.bzl",
- "java/common/java_common.bzl",
- "java/common/java_info.bzl",
- "java/common/java_plugin_info.bzl",
- "java/private/native.bzl",
- "java/toolchains/java_package_configuration.bzl",
- "java/toolchains/java_runtime.bzl",
- "java/toolchains/java_toolchain.bzl",
- "toolchains/java_toolchain_alias.bzl");
- for (String relativePath : toolsToCopy) {
- Path path = Path.of(runfilesResolver.apply("rules_java/" + relativePath));
- if (Files.exists(path)) {
- config.create(
- "rules_java_workspace/" + relativePath,
- MoreFiles.asCharSource(path, UTF_8).read());
- }
- }
+ PathFragment rulesJavaRoot =
+ PathFragment.create(runfilesResolver.apply("rules_java/java/defs.bzl"))
+ .getParentDirectory()
+ .getParentDirectory();
+ config.copyDirectory(
+ rulesJavaRoot.getRelative("java"),
+ "rules_java_workspace/java",
+ Integer.MAX_VALUE,
+ true);
+ config.copyTool(
+ rulesJavaRoot.getRelative("toolchains/java_toolchain_alias.bzl"),
+ "rules_java_workspace/toolchains/java_toolchain_alias.bzl");
// mocks
+ config.create("rules_java_workspace/toolchains/BUILD");
config.create(
"rules_java_workspace/toolchains/local_java_repository.bzl",
"""
@@ -70,7 +50,7 @@
""");
config.create(
"rules_java_workspace/toolchains/jdk_build_file.bzl", "JDK_BUILD_TEMPLATE = ''");
- config.create(
+ config.overwrite(
"rules_java_workspace/java/repositories.bzl",
"""
def rules_java_dependencies():
@@ -81,7 +61,7 @@
native.register_toolchains("//java/toolchains/javac:all")
""");
- config.create(
+ config.overwrite(
"rules_java_workspace/java/toolchains/runtime/BUILD",
"""
toolchain_type(name = "toolchain_type")
@@ -92,7 +72,7 @@
toolchain_type = "@rules_java//java/toolchains/runtime:toolchain_type",
)
""");
- config.create(
+ config.overwrite(
"rules_java_workspace/java/toolchains/javac/BUILD",
"""
toolchain_type(name = "toolchain_type")
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockProtoSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockProtoSupport.java
index eea00ba..ee05d29 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/MockProtoSupport.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockProtoSupport.java
@@ -473,5 +473,11 @@
toolchain = name,
)
""");
+ config.create("protobuf_workspace/bazel/common/BUILD");
+ config.create(
+ "protobuf_workspace/bazel/common/proto_info.bzl",
+ """
+ ProtoInfo = provider()
+ """);
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
index 1045324..72d2046 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
@@ -155,6 +155,7 @@
public static final ImmutableList<String> PRODUCT_SPECIFIC_BUILD_LANG_OPTIONS =
ImmutableList.of(
+ "--experimental_rule_extension_api",
// Don't apply autoloads in unit tests, because not all repos are available
"--incompatible_autoload_externally=");
diff --git a/src/test/py/bazel/test_base.py b/src/test/py/bazel/test_base.py
index 1f9afd6..0cbd66a 100644
--- a/src/test/py/bazel/test_base.py
+++ b/src/test/py/bazel/test_base.py
@@ -75,6 +75,7 @@
self._test_cwd = tempfile.mkdtemp(dir=self._tests_root)
self._test_bazelrc = os.path.join(self._temp, 'test_bazelrc')
with open(self._test_bazelrc, 'wt') as f:
+ f.write('common --experimental_rule_extension_api\n')
f.write('common --nolegacy_external_runfiles\n')
shared_install_base = os.environ.get('TEST_INSTALL_BASE')
if shared_install_base:
diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD
index c5e8f89..c1dc83e 100644
--- a/src/test/shell/bazel/BUILD
+++ b/src/test/shell/bazel/BUILD
@@ -32,6 +32,7 @@
":test-deps-wo-bazel",
"//src:bazel",
"//src/test/shell:bin/bazel",
+ "//third_party/protobuf:proto_info_bzl_deps.patch",
"//third_party/protobuf:remove_rules_rust.patch",
],
visibility = [
diff --git a/src/test/shell/bazel/bazel_rules_cc_test.sh b/src/test/shell/bazel/bazel_rules_cc_test.sh
index e8e7990..856855a 100755
--- a/src/test/shell/bazel/bazel_rules_cc_test.sh
+++ b/src/test/shell/bazel/bazel_rules_cc_test.sh
@@ -51,6 +51,9 @@
esac
function test_rules_cc_can_be_overridden() {
+ # rules_java relies on rules_cc contents
+ mock_rules_java_to_avoid_downloading
+
# The bazelrc file might contain an --override_repository flag for rules_cc,
# which would cause this test to fail to override the repo via a WORKSPACE file.
sed -i.bak '/override_repository=rules_cc/d' $TEST_TMPDIR/bazelrc
@@ -80,9 +83,14 @@
function test_rules_cc_repository_builds_itself() {
add_rules_cc "MODULE.bazel"
write_default_bazelrc
-
+ # can be removed with protobuf v28.x onwards
+ if $is_windows; then
+ CXXOPTS=""
+ else
+ CXXOPTS="--cxxopt=-Wno-deprecated-declarations --host_cxxopt=-Wno-deprecated-declarations"
+ fi
# We test that a built-in @rules_cc repository is buildable.
- bazel build @rules_cc//cc/... &> $TEST_log \
+ bazel build $CXXOPTS @rules_cc//cc/... &> $TEST_log \
|| fail "Build failed unexpectedly"
}
diff --git a/src/test/shell/integration/discard_graph_edges_test.sh b/src/test/shell/integration/discard_graph_edges_test.sh
index 92e020c..b1a1d29 100755
--- a/src/test/shell/integration/discard_graph_edges_test.sh
+++ b/src/test/shell/integration/discard_graph_edges_test.sh
@@ -274,13 +274,13 @@
# is still low (external packages don't contribute there). We can lower this
# number again once we remove WORKSPACE logic and move repo rules to not use
# Package anymore.
- [[ "$package_count" -le 50 ]] \
+ [[ "$package_count" -le 51 ]] \
|| fail "package count $package_count too high"
globs_count="$(extract_histogram_count "$histo_file" "GlobsValue$")"
[[ "$globs_count" -le 1 ]] \
|| fail "globs count $globs_count too high"
module_count="$(extract_histogram_count "$histo_file" 'eval.Module$')"
- [[ "$module_count" -lt 215 ]] \
+ [[ "$module_count" -le 265 ]] \
|| fail "Module count $module_count too high"
ct_count="$(extract_histogram_count "$histo_file" \
'RuleConfiguredTarget$')"
diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh
index 6124053..fd6a3b5 100755
--- a/src/test/shell/testenv.sh
+++ b/src/test/shell/testenv.sh
@@ -321,6 +321,9 @@
build --java_runtime_version=21
build --tool_java_runtime_version=21
+# for rules_java
+common --experimental_rule_extension_api
+
${EXTRA_BAZELRC:-}
EOF
@@ -597,6 +600,7 @@
mkdir -p third_party/protobuf
touch third_party/protobuf/BUILD
cp "$(rlocation io_bazel/third_party/protobuf/remove_rules_rust.patch)" third_party/protobuf/remove_rules_rust.patch
+ cp "$(rlocation io_bazel/third_party/protobuf/proto_info_bzl_deps.patch)" third_party/protobuf/proto_info_bzl_deps.patch
cat >> "$1" <<EOF
archive_override(
module_name = "protobuf",
@@ -605,7 +609,10 @@
# Temporarily patch out rules_rust stuff from protobuf. Not just because we don't need it,
# but also because it introduces huge dependency bloat: rules_rust -> aspect_rules_js ->
# aspect_rules_lint -> rules_buf.
- patches = ["//third_party/protobuf:remove_rules_rust.patch"],
+ patches = [
+ "//third_party/protobuf:proto_info_bzl_deps.patch",
+ "//third_party/protobuf:remove_rules_rust.patch",
+ ],
strip_prefix = "protobuf-3b62052186d39775090fb074adcba078ea622f54",
urls = ["https://github.com/protocolbuffers/protobuf/archive/3b62052186d39775090fb074adcba078ea622f54.zip"],
)
diff --git a/src/test/tools/bzlmod/MODULE.bazel.lock b/src/test/tools/bzlmod/MODULE.bazel.lock
index 12d51e5..cdb09a2 100644
--- a/src/test/tools/bzlmod/MODULE.bazel.lock
+++ b/src/test/tools/bzlmod/MODULE.bazel.lock
@@ -25,6 +25,8 @@
"https://bcr.bazel.build/modules/googletest/1.11.0/MODULE.bazel": "3a83f095183f66345ca86aa13c58b59f9f94a2f81999c093d4eeaa2d262d12f4",
"https://bcr.bazel.build/modules/googletest/1.14.0/MODULE.bazel": "cfbcbf3e6eac06ef9d85900f64424708cc08687d1b527f0ef65aa7517af8118f",
"https://bcr.bazel.build/modules/googletest/1.14.0/source.json": "2478949479000fdd7de9a3d0107ba2c85bb5f961c3ecb1aa448f52549ce310b5",
+ "https://bcr.bazel.build/modules/jsoncpp/1.9.5/MODULE.bazel": "31271aedc59e815656f5736f282bb7509a97c7ecb43e927ac1a37966e0578075",
+ "https://bcr.bazel.build/modules/jsoncpp/1.9.5/source.json": "4108ee5085dd2885a341c7fab149429db457b3169b86eb081fa245eadf69169d",
"https://bcr.bazel.build/modules/platforms/0.0.10/MODULE.bazel": "8cb8efaf200bdeb2150d93e162c40f388529a25852b332cec879373771e48ed5",
"https://bcr.bazel.build/modules/platforms/0.0.10/source.json": "f22828ff4cf021a6b577f1bf6341cb9dcd7965092a439f64fc1bb3b7a5ae4bd5",
"https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee",
@@ -34,7 +36,8 @@
"https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d",
"https://bcr.bazel.build/modules/protobuf/23.1/MODULE.bazel": "88b393b3eb4101d18129e5db51847cd40a5517a53e81216144a8c32dfeeca52a",
"https://bcr.bazel.build/modules/protobuf/24.4/MODULE.bazel": "7bc7ce5f2abf36b3b7b7c8218d3acdebb9426aeb35c2257c96445756f970eb12",
- "https://bcr.bazel.build/modules/protobuf/24.4/source.json": "ace4b8c65d4cfe64efe544f09fc5e5df77faf3a67fbb29c5341e0d755d9b15d6",
+ "https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c",
+ "https://bcr.bazel.build/modules/protobuf/27.0/source.json": "1acf3d080c728d42f423fde5422fd0a1a24f44c15908124ce12363a253384193",
"https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647",
"https://bcr.bazel.build/modules/rules_cc/0.0.10/MODULE.bazel": "ec1705118f7eaedd6e118508d3d26deba2a4e76476ada7e0e3965211be012002",
"https://bcr.bazel.build/modules/rules_cc/0.0.10/source.json": "90310b16e0e7df0cf40f8d1dccd7d373360f42419a6bfbbf5bb013182dd70e84",
@@ -43,10 +46,11 @@
"https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e",
"https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5",
"https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74",
+ "https://bcr.bazel.build/modules/rules_java/5.3.5/MODULE.bazel": "a4ec4f2db570171e3e5eb753276ee4b389bae16b96207e9d3230895c99644b86",
"https://bcr.bazel.build/modules/rules_java/7.1.0/MODULE.bazel": "30d9135a2b6561c761bd67bd4990da591e6bdc128790ce3e7afd6a3558b2fb64",
- "https://bcr.bazel.build/modules/rules_java/7.12.1/MODULE.bazel": "0a2ebb53b48a6eb092aef24b36db23294d4d3ebf96bff02b0ccc962bdc70717d",
- "https://bcr.bazel.build/modules/rules_java/7.12.1/source.json": "2ab5ceabe9d87a773fa44e4cce42c950e34ff6d2f5164e7413088542fa4f1f3e",
"https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe",
+ "https://bcr.bazel.build/modules/rules_java/8.0.0-rc2/MODULE.bazel": "84e718dbd0f6190aa2314d610ed8fab60dd9d67c1dde6b36dd23434675159e22",
+ "https://bcr.bazel.build/modules/rules_java/8.0.0-rc2/source.json": "c519ebc46a9c0d1173793c98d43d2ee9db4eb66a5eab8a42126b1fba6d718d50",
"https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7",
"https://bcr.bazel.build/modules/rules_jvm_external/5.1/MODULE.bazel": "33f6f999e03183f7d088c9be518a63467dfd0be94a11d0055fe2d210f89aa909",
"https://bcr.bazel.build/modules/rules_jvm_external/5.2/MODULE.bazel": "d9351ba35217ad0de03816ef3ed63f89d411349353077348a45348b096615036",
@@ -69,7 +73,6 @@
"https://bcr.bazel.build/modules/stardoc/0.7.0/MODULE.bazel": "05e3d6d30c099b6770e97da986c53bd31844d7f13d41412480ea265ac9e8079c",
"https://bcr.bazel.build/modules/stardoc/0.7.0/source.json": "e3c524bf2ef20992539ce2bc4a2243f4853130209ee831689983e28d05769099",
"https://bcr.bazel.build/modules/upb/0.0.0-20230516-61a97ef/MODULE.bazel": "c0df5e35ad55e264160417fd0875932ee3c9dda63d9fccace35ac62f45e1b6f9",
- "https://bcr.bazel.build/modules/upb/0.0.0-20230516-61a97ef/source.json": "b2150404947339e8b947c6b16baa39fa75657f4ddec5e37272c7b11c7ab533bc",
"https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0",
"https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/MODULE.bazel": "af322bc08976524477c79d1e45e241b6efbeb918c497e8840b8ab116802dda79",
"https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/source.json": "2be409ac3c7601245958cd4fcdff4288be79ed23bd690b4b951f500d54ee6e7d"
@@ -93,39 +96,10 @@
"recordedRepoMappingEntries": []
}
},
- "@@protobuf+//:non_module_deps.bzl%non_module_deps": {
- "general": {
- "bzlTransitiveDigest": "OaID94YoUuo89CDCPUVeomNfmMBqRMz/aFoknez7nyQ=",
- "usagesDigest": "gm6VqhySjIy+wcQAVypXblDDqYn/eivmtcUsXjLnx3g=",
- "recordedFileInputs": {},
- "recordedDirentsInputs": {},
- "envVariables": {},
- "generatedRepoSpecs": {
- "utf8_range": {
- "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
- "ruleClassName": "http_archive",
- "attributes": {
- "urls": [
- "https://github.com/protocolbuffers/utf8_range/archive/de0b4a8ff9b5d4c98108bdfe723291a33c52c54f.zip"
- ],
- "strip_prefix": "utf8_range-de0b4a8ff9b5d4c98108bdfe723291a33c52c54f",
- "sha256": "5da960e5e5d92394c809629a03af3c7709d2d3d0ca731dacb3a9fb4bf28f7702"
- }
- }
- },
- "recordedRepoMappingEntries": [
- [
- "protobuf+",
- "bazel_tools",
- "bazel_tools"
- ]
- ]
- }
- },
"@@rules_jvm_external+//:extensions.bzl%maven": {
"general": {
"bzlTransitiveDigest": "mLp5egTYHBwh51cnzz5DFLc8C6bKoL2o7uOj7ozbGiI=",
- "usagesDigest": "YW5ucYd9ghy06e5qfOaujzSfCdLLlgeb4GtdxPorpQg=",
+ "usagesDigest": "D4pzNNc0xMo/xkafrajjWOmuEsgZjCK/xfDI5gVSzU4=",
"recordedFileInputs": {
"@@rules_jvm_external+//rules_jvm_external_deps_install.json": "3ab1f67b0de4815df110bc72ccd6c77882b3b21d3d1e0a84445847b6ce3235a3",
"@@stardoc+//maven_install.json": "de0bfa778b4ed6aebb77509362dd87ab8d20fc7c7c18d2a7429cdfee03949a21"
@@ -133,45 +107,6 @@
"recordedDirentsInputs": {},
"envVariables": {},
"generatedRepoSpecs": {
- "maven": {
- "bzlFile": "@@rules_jvm_external+//:coursier.bzl",
- "ruleClassName": "coursier_fetch",
- "attributes": {
- "repositories": [
- "{ \"repo_url\": \"https://repo1.maven.org/maven2\" }"
- ],
- "artifacts": [
- "{ \"group\": \"com.google.code.findbugs\", \"artifact\": \"jsr305\", \"version\": \"3.0.2\" }",
- "{ \"group\": \"com.google.code.gson\", \"artifact\": \"gson\", \"version\": \"2.8.9\" }",
- "{ \"group\": \"com.google.errorprone\", \"artifact\": \"error_prone_annotations\", \"version\": \"2.3.2\" }",
- "{ \"group\": \"com.google.j2objc\", \"artifact\": \"j2objc-annotations\", \"version\": \"1.3\" }",
- "{ \"group\": \"com.google.guava\", \"artifact\": \"guava\", \"version\": \"31.1-jre\" }",
- "{ \"group\": \"com.google.guava\", \"artifact\": \"guava-testlib\", \"version\": \"31.1-jre\" }",
- "{ \"group\": \"com.google.truth\", \"artifact\": \"truth\", \"version\": \"1.1.2\" }",
- "{ \"group\": \"junit\", \"artifact\": \"junit\", \"version\": \"4.13.2\" }",
- "{ \"group\": \"org.mockito\", \"artifact\": \"mockito-core\", \"version\": \"4.3.1\" }"
- ],
- "fail_on_missing_checksum": true,
- "fetch_sources": true,
- "fetch_javadoc": false,
- "excluded_artifacts": [],
- "generate_compat_repositories": false,
- "version_conflict_policy": "default",
- "override_targets": {},
- "strict_visibility": false,
- "strict_visibility_value": [
- "@@//visibility:private"
- ],
- "resolve_timeout": 600,
- "jetify": false,
- "jetify_include_list": [
- "*"
- ],
- "use_starlark_android_rules": false,
- "aar_import_bzl_label": "@build_bazel_rules_android//android:rules.bzl",
- "duplicate_version_warning": "warn"
- }
- },
"unpinned_rules_jvm_external_deps": {
"bzlFile": "@@rules_jvm_external+//:coursier.bzl",
"ruleClassName": "coursier_fetch",
@@ -3609,35 +3544,6 @@
]
]
}
- },
- "@@upb+//:non_module_deps.bzl%non_module_deps": {
- "general": {
- "bzlTransitiveDigest": "OaID94YoUuo89CDCPUVeomNfmMBqRMz/aFoknez7nyQ=",
- "usagesDigest": "pZOZBYc8Kee/Hi8/EIf3SfYt6ar0unb9MMI2Tczhi6g=",
- "recordedFileInputs": {},
- "recordedDirentsInputs": {},
- "envVariables": {},
- "generatedRepoSpecs": {
- "utf8_range": {
- "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
- "ruleClassName": "http_archive",
- "attributes": {
- "urls": [
- "https://github.com/protocolbuffers/utf8_range/archive/de0b4a8ff9b5d4c98108bdfe723291a33c52c54f.zip"
- ],
- "strip_prefix": "utf8_range-de0b4a8ff9b5d4c98108bdfe723291a33c52c54f",
- "sha256": "5da960e5e5d92394c809629a03af3c7709d2d3d0ca731dacb3a9fb4bf28f7702"
- }
- }
- },
- "recordedRepoMappingEntries": [
- [
- "upb+",
- "bazel_tools",
- "bazel_tools"
- ]
- ]
- }
}
}
}