diff options
author | 2018-02-20 09:31:37 -0800 | |
---|---|---|
committer | 2018-02-20 09:35:06 -0800 | |
commit | a7b34a1591cfa1034dca9b2c4ff9743d81396a97 (patch) | |
tree | 5626845e44389dd5b5758b8f466368337dba8fed /src/main/java | |
parent | cc16e7cb3e7203f5033928f1348722cad6d8e59d (diff) |
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
Diffstat (limited to 'src/main/java')
5 files changed, 73 insertions, 5 deletions
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 6c973ea0a4..7bf642fed0 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.packages.Rule; 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.SkyFunction.Environment; 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 @@ public class HttpArchiveFunction extends RepositoryFunction { } } + @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 ba042bfd7d..73bf8c7102 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.packages.Rule; 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 class NewHttpArchiveFunction extends HttpArchiveFunction { 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 fde47f5c62..a40ca667e6 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 @@ public final class SkylarkSemanticsCodec implements ObjectCodec<SkylarkSemantics 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 @@ public final class SkylarkSemanticsCodec implements ObjectCodec<SkylarkSemantics 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 36dfbe0f01..e901353f79 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 class SkylarkSemanticsOptions extends OptionsBase implements Serializable 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 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable .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 ccdef1eb5f..d14a09c694 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 class SkylarkSemantics { 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 @@ public abstract class SkylarkSemantics { .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 class SkylarkSemantics { 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); |