Skip to content

Commit

Permalink
Add flag to control native maven jar rule deprecation.
Browse files Browse the repository at this point in the history
Closes #6768.
Relevant to #6799.

PiperOrigin-RevId: 223375698
  • Loading branch information
dkelmer authored and Copybara-Service committed Nov 29, 2018
1 parent 692d148 commit 21f4bd3
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
56 changes: 56 additions & 0 deletions site/docs/skylark/backward-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ External repositories

* [Remove native git repository](#remove-native-git-repository)
* [Remove native http archive](#remove-native-http-archive)
* [Remove native maven jar](#remove-native-maven-jar)

Java

Expand Down Expand Up @@ -394,6 +395,61 @@ parameter, not `url`).
* Flag: `--incompatible_remove_native_http_archive`
* Default: `true`

### Remove native maven jar

When set, the native `maven_jar` rule is disabled. The Starlark version

```python
load("@bazel_tools//tools/build_defs/repo:java.bzl", "java_import_external")
```

or the convenience wrapper

```python
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")
```

should be used instead. These rules are more reliable and offer additional
functionality over the native `maven_jar` rule. In addition to downloading
the jars, they allow defining the jar's dependencies. They also enable
downloading src-jars.

Given a `WORKSPACE` file that looks like the following:

```python
maven_jar(
name = "truth",
artifact = "com.google.truth:truth:0.30",
sha1 = "9d591b5a66eda81f0b88cf1c748ab8853d99b18b",
)
```

It will need to look like this after updating:
```python
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")
jvm_maven_import_external(
name = "truth",
artifact = "com.google.truth:truth:0.30",
artifact_sha256 = "59721f0805e223d84b90677887d9ff567dc534d7c502ca903c0c2b17f05c116a",
server_urls = ["http://central.maven.org/maven2"],
licenses = ["notice"], # Apache 2.0
)
```

Notably
* the `licenses` attribute is mandatory
* sha1 is no longer supported, only sha256 is
* the `server_urls` attribute is mandatory. If your `maven_jar` rule
did not specify a url then you should use the default server
("http://central.maven.org/maven2"). If your rule did specify a url then
keep using that one.

Documentation for the rule is
[here](https://source.bazel.build/bazel/+/master:tools/build_defs/repo/java.bzl;l=15).

* Flag: `--incompatible_remove_native_maven_jar`
* Default: `false`

### New-style JavaInfo constructor

When set, `java_common.create_provider` and certain arguments to `JavaInfo` are deprecated. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue;
import com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper;
import com.google.devtools.build.lib.skyframe.PrecomputedValue;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.SkylarkSemantics;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.Fingerprint;
import com.google.devtools.build.lib.vfs.Path;
Expand Down Expand Up @@ -96,6 +98,24 @@ private static MavenServerValue getServer(Rule rule, Environment env)
public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory,
BlazeDirectories directories, Environment env, Map<String, String> markerData)
throws RepositoryFunctionException, InterruptedException {

// Deprecation in favor of the Starlark rule
SkylarkSemantics skylarkSemantics = PrecomputedValue.SKYLARK_SEMANTICS.get(env);
if (skylarkSemantics == null) {
return null;
}
if (skylarkSemantics.incompatibleRemoveNativeMavenJar()) {
throw new RepositoryFunctionException(
new EvalException(
null,
"The native maven_jar rule is deprecated."
+ " See https://docs.bazel.build/versions/master/skylark/"
+ "backward-compatibility.html#remove-native-maven-jar for migration information."
+ "\nUse --incompatible_remove_native_maven_jar=false to temporarily continue"
+ " using the native rule."),
Transience.PERSISTENT);
}

MavenServerValue serverValue = getServer(rule, env);
if (env.valuesMissing()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,20 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable
+ "will be available")
public boolean incompatibleRemoveNativeHttpArchive;

@Option(
name = "incompatible_remove_native_maven_jar",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.SKYLARK_SEMANTICS,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help =
"If set to true, the native maven_jar rule is disabled; only the Starlark version "
+ "will be available")
public boolean incompatibleRemoveNativeMavenJar;

@Option(
name = "incompatible_static_name_resolution",
defaultValue = "true",
Expand Down Expand Up @@ -566,6 +580,7 @@ public SkylarkSemantics toSkylarkSemantics() {
.incompatibleRangeType(incompatibleRangeType)
.incompatibleRemoveNativeGitRepository(incompatibleRemoveNativeGitRepository)
.incompatibleRemoveNativeHttpArchive(incompatibleRemoveNativeHttpArchive)
.incompatibleRemoveNativeMavenJar(incompatibleRemoveNativeMavenJar)
.incompatibleStaticNameResolution(incompatibleStaticNameResolution)
.incompatibleStricArgumentOrdering(incompatibleStricArgumentOrdering)
.incompatibleStringIsNotIterable(incompatibleStringIsNotIterable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ public boolean flagValue(FlagIdentifier flagIdentifier) {

public abstract boolean incompatibleRemoveNativeHttpArchive();

public abstract boolean incompatibleRemoveNativeMavenJar();

public abstract boolean incompatibleStaticNameResolution();

public abstract boolean incompatibleStricArgumentOrdering();
Expand Down Expand Up @@ -231,6 +233,7 @@ public static Builder builderWithDefaults() {
.incompatibleRangeType(true)
.incompatibleRemoveNativeGitRepository(true)
.incompatibleRemoveNativeHttpArchive(true)
.incompatibleRemoveNativeMavenJar(false)
.incompatibleStaticNameResolution(true)
.incompatibleStricArgumentOrdering(false)
.incompatibleStringIsNotIterable(false)
Expand Down Expand Up @@ -306,6 +309,8 @@ public abstract static class Builder {

public abstract Builder incompatibleRemoveNativeHttpArchive(boolean value);

public abstract Builder incompatibleRemoveNativeMavenJar(boolean value);

public abstract Builder incompatibleStaticNameResolution(boolean value);

public abstract Builder incompatibleStricArgumentOrdering(boolean value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private static SkylarkSemanticsOptions buildRandomOptions(Random rand) throws Ex
"--incompatible_range_type=" + rand.nextBoolean(),
"--incompatible_remove_native_git_repository=" + rand.nextBoolean(),
"--incompatible_remove_native_http_archive=" + rand.nextBoolean(),
"--incompatible_remove_native_maven_jar=" + rand.nextBoolean(),
"--incompatible_static_name_resolution=" + rand.nextBoolean(),
"--incompatible_strict_argument_ordering=" + rand.nextBoolean(),
"--incompatible_string_is_not_iterable=" + rand.nextBoolean(),
Expand Down Expand Up @@ -199,6 +200,7 @@ private static SkylarkSemantics buildRandomSemantics(Random rand) {
.incompatibleRangeType(rand.nextBoolean())
.incompatibleRemoveNativeGitRepository(rand.nextBoolean())
.incompatibleRemoveNativeHttpArchive(rand.nextBoolean())
.incompatibleRemoveNativeMavenJar(rand.nextBoolean())
.incompatibleStaticNameResolution(rand.nextBoolean())
.incompatibleStricArgumentOrdering(rand.nextBoolean())
.incompatibleStringIsNotIterable(rand.nextBoolean())
Expand Down

0 comments on commit 21f4bd3

Please sign in to comment.