-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use URLs as default canonical IDs in common repo rules
RELNOTES[INC]: The `http_archive`, `http_file`, `http_jar`, `jvm_maven_import_external`, and `jvm_import_external` repository rules now use the URLs as the default canonical ID. If this behavior is not desired, it can be disabled via `--repo_env==BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=0`. The `--experimental_repository_cache_urls_as_default_canonical_id` flag is now a no-op.
- Loading branch information
Showing
15 changed files
with
139 additions
and
64 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ filegroup( | |
filegroup( | ||
name = "http_src", | ||
srcs = [ | ||
"cache.bzl", | ||
"http.bzl", | ||
"utils.bzl", | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2023 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. | ||
|
||
# WARNING: | ||
# https://github.com/bazelbuild/bazel/issues/17713 | ||
# .bzl files in this package (tools/build_defs/repo) are evaluated | ||
# in a Starlark environment without "@_builtins" injection, and must not refer | ||
# to symbols associated with build/workspace .bzl files | ||
|
||
visibility("private") | ||
|
||
DEFAULT_CANONICAL_ID_ENV = "BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID" | ||
|
||
CANONICAL_ID_DOC = """A canonical ID of the file downloaded. | ||
If specified and non-empty, Bazel will not take the file from cache, unless it | ||
was added to the cache by a request with the same canonical ID. | ||
If unspecified or empty, Bazel by default uses the URLs of the file as the | ||
canonical ID. This helps catch the common mistake of updating the URLs without | ||
also updating the hash, resulting in builds that succeed locally but fail on | ||
machines without the file in the cache. This behavior can be disabled with | ||
--repo_env={env}=0. | ||
""".format(env = DEFAULT_CANONICAL_ID_ENV) | ||
|
||
def get_default_canonical_id(repository_ctx, urls): | ||
"""Returns the default canonical id to use for downloads.""" | ||
if repository_ctx.os.environ.get(DEFAULT_CANONICAL_ID_ENV) == "0": | ||
return "" | ||
|
||
# Do not sort URLs to prevent the following scenario: | ||
# 1. http_archive with urls = [B, A] created. | ||
# 2. Successful fetch from B results in canonical ID "A B". | ||
# 3. Order of urls is flipped to [A, B]. | ||
# 4. Fetch would reuse cache entry for "A B", even though A may be broken (it has never been | ||
# fetched before). | ||
return " ".join(urls) |
Oops, something went wrong.