Decprecate native http_archive
Since the skylark implementation of http_archive provides all
the features available in the native http_archive and a few
more (patching), there is no need to have to rule implementations
doing the same thing. Hence deprecate the native one as part
of our plan of moving more functionality to skylark.
RELNOTES: The native http_archive rule is deprecated. Use the
Skylark version available via load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
instead.
Change-Id: I107c2f25f5a37c67f56b4362e7c9d9ade8428c16
PiperOrigin-RevId: 186314624
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpArchiveFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpArchiveFunction.java
index 6c973ea..7bf642f 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpArchiveFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpArchiveFunction.java
@@ -22,7 +22,9 @@
import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue;
import com.google.devtools.build.lib.rules.repository.RepositoryFunction;
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.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
@@ -30,6 +32,7 @@
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import java.io.IOException;
import java.util.Map;
+import javax.annotation.Nullable;
/**
* Downloads a file over HTTP.
@@ -56,10 +59,32 @@
}
}
+ @Nullable
@Override
- public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory,
- BlazeDirectories directories, Environment env, Map<String, String> markerData)
+ public RepositoryDirectoryValue.Builder fetch(
+ Rule rule,
+ Path outputDirectory,
+ BlazeDirectories directories,
+ Environment env,
+ Map<String, String> markerData)
throws RepositoryFunctionException, InterruptedException {
+ // Deprecation in favor of the Skylark variant.
+ SkylarkSemantics skylarkSemantics = PrecomputedValue.SKYLARK_SEMANTICS.get(env);
+ if (skylarkSemantics == null) {
+ return null;
+ }
+ if (skylarkSemantics.incompatibleRemoveNativeHttpArchive()) {
+ throw new RepositoryFunctionException(
+ new EvalException(
+ null,
+ "The native http_archive rule is deprecated."
+ + " load(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\") for a"
+ + " drop-in replacement."
+ + "\nUse --incompatible_remove_native_http_archive=false to temporarily continue"
+ + " using the native rule."),
+ Transience.PERSISTENT);
+ }
+
// The output directory is always under output_base/external (to stay out of the way of
// artifacts from this repository) and uses the rule's name to avoid conflicts with other
// remote repository rules. For example, suppose you had the following WORKSPACE file:
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/NewHttpArchiveFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/NewHttpArchiveFunction.java
index ba042bf..73bf8c7 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/NewHttpArchiveFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/NewHttpArchiveFunction.java
@@ -20,7 +20,9 @@
import com.google.devtools.build.lib.rules.repository.NewRepositoryFileHandler;
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.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
@@ -45,6 +47,24 @@
public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory,
BlazeDirectories directories, Environment env, Map<String, String> markerData)
throws RepositoryFunctionException, InterruptedException {
+ // Deprecation in favor of the Skylark variant.
+ SkylarkSemantics skylarkSemantics = PrecomputedValue.SKYLARK_SEMANTICS.get(env);
+ if (skylarkSemantics == null) {
+ return null;
+ }
+ if (skylarkSemantics.incompatibleRemoveNativeHttpArchive()) {
+ throw new RepositoryFunctionException(
+ new EvalException(
+ null,
+ "The native new_http_archive rule is deprecated."
+ + " load(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\") for a"
+ + " drop-in replacement."
+ + "\nUse --incompatible_remove_native_http_archive=false to temporarily continue"
+ + " using the native rule."),
+ Transience.PERSISTENT);
+ }
+
+ // The output directory is always under output_base/external (to stay out of the way of
NewRepositoryFileHandler fileHandler = new NewRepositoryFileHandler(directories.getWorkspace());
if (!fileHandler.prepareFile(rule, env)) {
return null;
diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java
index fde47f5..a40ca66 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java
@@ -52,6 +52,7 @@
codedOut.writeBoolNoTag(semantics.incompatibleDisallowUncalledSetConstructor());
codedOut.writeBoolNoTag(semantics.incompatibleLoadArgumentIsLabel());
codedOut.writeBoolNoTag(semantics.incompatibleNewActionsApi());
+ codedOut.writeBoolNoTag(semantics.incompatibleRemoveNativeHttpArchive());
codedOut.writeBoolNoTag(semantics.incompatibleShowAllPrintMessages());
codedOut.writeBoolNoTag(semantics.incompatibleStringIsNotIterable());
codedOut.writeBoolNoTag(semantics.internalSkylarkFlagTestCanary());
@@ -72,6 +73,7 @@
builder.incompatibleDisallowUncalledSetConstructor(codedIn.readBool());
builder.incompatibleLoadArgumentIsLabel(codedIn.readBool());
builder.incompatibleNewActionsApi(codedIn.readBool());
+ builder.incompatibleRemoveNativeHttpArchive(codedIn.readBool());
builder.incompatibleShowAllPrintMessages(codedIn.readBool());
builder.incompatibleStringIsNotIterable(codedIn.readBool());
builder.internalSkylarkFlagTestCanary(codedIn.readBool());
diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java
index 36dfbe0..e901353 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java
@@ -171,6 +171,19 @@
public boolean incompatibleNewActionsApi;
@Option(
+ name = "incompatible_remove_native_http_archive",
+ defaultValue = "false",
+ category = "incompatible changes",
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
+ help =
+ "If set to true, the native http_archive rules are disabled; only the skylark version "
+ + "will be available"
+ )
+ public boolean incompatibleRemoveNativeHttpArchive;
+
+ @Option(
name = "incompatible_show_all_print_messages",
defaultValue = "true",
category = "incompatible changes",
@@ -219,6 +232,7 @@
.incompatibleDisallowUncalledSetConstructor(incompatibleDisallowUncalledSetConstructor)
.incompatibleLoadArgumentIsLabel(incompatibleLoadArgumentIsLabel)
.incompatibleNewActionsApi(incompatibleNewActionsApi)
+ .incompatibleRemoveNativeHttpArchive(incompatibleRemoveNativeHttpArchive)
.incompatibleShowAllPrintMessages(incompatibleShowAllPrintMessages)
.incompatibleStringIsNotIterable(incompatibleStringIsNotIterable)
.internalSkylarkFlagTestCanary(internalSkylarkFlagTestCanary)
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
index ccdef1e..d14a09c 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
@@ -52,6 +52,9 @@
public abstract boolean incompatibleLoadArgumentIsLabel();
public abstract boolean incompatibleNewActionsApi();
public abstract boolean incompatibleShowAllPrintMessages();
+
+ public abstract boolean incompatibleRemoveNativeHttpArchive();
+
public abstract boolean incompatibleStringIsNotIterable();
public abstract boolean internalSkylarkFlagTestCanary();
@@ -79,10 +82,11 @@
.incompatibleDisallowUncalledSetConstructor(true)
.incompatibleLoadArgumentIsLabel(true)
.incompatibleNewActionsApi(false)
+ .incompatibleRemoveNativeHttpArchive(false)
.incompatibleShowAllPrintMessages(true)
- .incompatibleStringIsNotIterable(false)
- .internalSkylarkFlagTestCanary(false)
- .build();
+ .incompatibleStringIsNotIterable(false)
+ .internalSkylarkFlagTestCanary(false)
+ .build();
/** Builder for {@link SkylarkSemantics}. All fields are mandatory. */
@AutoValue.Builder
@@ -101,6 +105,9 @@
public abstract Builder incompatibleDisallowUncalledSetConstructor(boolean value);
public abstract Builder incompatibleLoadArgumentIsLabel(boolean value);
public abstract Builder incompatibleNewActionsApi(boolean value);
+
+ public abstract Builder incompatibleRemoveNativeHttpArchive(boolean value);
+
public abstract Builder incompatibleShowAllPrintMessages(boolean value);
public abstract Builder incompatibleStringIsNotIterable(boolean value);
public abstract Builder internalSkylarkFlagTestCanary(boolean value);
diff --git a/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java b/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
index 276a1c2..df6ee43 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
@@ -128,6 +128,7 @@
"--incompatible_disallow_uncalled_set_constructor=" + rand.nextBoolean(),
"--incompatible_load_argument_is_label=" + rand.nextBoolean(),
"--incompatible_new_actions_api=" + rand.nextBoolean(),
+ "--incompatible_remove_native_http_archive=" + rand.nextBoolean(),
"--incompatible_show_all_print_messages=" + rand.nextBoolean(),
"--incompatible_string_is_not_iterable=" + rand.nextBoolean(),
"--internal_skylark_flag_test_canary=" + rand.nextBoolean());
@@ -149,6 +150,7 @@
.incompatibleDisallowUncalledSetConstructor(rand.nextBoolean())
.incompatibleLoadArgumentIsLabel(rand.nextBoolean())
.incompatibleNewActionsApi(rand.nextBoolean())
+ .incompatibleRemoveNativeHttpArchive(rand.nextBoolean())
.incompatibleShowAllPrintMessages(rand.nextBoolean())
.incompatibleStringIsNotIterable(rand.nextBoolean())
.internalSkylarkFlagTestCanary(rand.nextBoolean())