From 67a07d799f8e63680e695f2ed026e37894904d73 Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Sat, 15 Jun 2024 15:24:34 +0000 Subject: [PATCH 1/9] Make `get_default_canonical_id` public --- MODULE.bazel.lock | 2 +- .../starlark/StarlarkBaseExternalContext.java | 22 +++++++++++++++++-- src/test/tools/bzlmod/MODULE.bazel.lock | 8 +++---- tools/build_defs/repo/cache.bzl | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 8c006016faa067..3e08283183abe5 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -286,7 +286,7 @@ "usagesDigest": "S0vNSOLxzaSWBw2qFrqtiXI9txwZdU8Tc5Bmz/zBoJA=", "recordedFileInputs": { "@@//MODULE.bazel": "d944444e1624a90a47831d10fa134b9d6d2d387c22c97481c493a1a6ea86f467", - "@@//src/test/tools/bzlmod/MODULE.bazel.lock": "1b05fa65f3b7cb10e2d018eb5183171dca5d84e64820892e9d78290aa089f262" + "@@//src/test/tools/bzlmod/MODULE.bazel.lock": "d2a0c7def36e78e92c57b8ca01538fefdf44268328855cd157b7df684e9ae37b" }, "recordedDirentsInputs": {}, "envVariables": {}, diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java index 074bf39773418d..03af30a4c160f8 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java @@ -576,7 +576,16 @@ private StructImpl completeDownload(PendingDownload pendingDownload) "Downloads a file to the output path for the provided url and returns a struct" + " containing success, a flag which is true if the" + " download completed successfully, and if successful, a hash of the file" - + " with the fields sha256 and integrity.", + + " with the fields sha256 and integrity." + + "Setting an explicit canonical_id is highly recommended. e.g." + + "
\n"
+              + "load(\"@bazel_tools//tools/build_defs/repo:cache.bzl\", \"get_default_canonical_id\")\n"
+              + "# ...\n"
+              + "    repository_ctx.download(\n"
+              + "        url = urls,\n"
+              + "        canonical_id = get_default_canonical_id(repository_ctx, urls),\n"
+              + "    ),\n"
+              + "
", useStarlarkThread = true, parameters = { @Param( @@ -755,7 +764,16 @@ public Object download( "Downloads a file to the output path for the provided url, extracts it, and returns a" + " struct containing success, a flag which is true if the" + " download completed successfully, and if successful, a hash of the file with the" - + " fields sha256 and integrity.", + + " fields sha256 and integrity." + + "Setting an explicit canonical_id is highly recommended. e.g." + + "
\n"
+              + "load(\"@bazel_tools//tools/build_defs/repo:cache.bzl\", \"get_default_canonical_id\")\n"
+              + "# ...\n"
+              + "    repository_ctx.download_and_extract(\n"
+              + "        url = urls,\n"
+              + "        canonical_id = get_default_canonical_id(repository_ctx, urls),\n"
+              + "    ),\n"
+              + "
", useStarlarkThread = true, parameters = { @Param( diff --git a/src/test/tools/bzlmod/MODULE.bazel.lock b/src/test/tools/bzlmod/MODULE.bazel.lock index 28d28091afa3d7..59c8b59094c1a3 100644 --- a/src/test/tools/bzlmod/MODULE.bazel.lock +++ b/src/test/tools/bzlmod/MODULE.bazel.lock @@ -78,7 +78,7 @@ }, "@@rules_jvm_external~//:extensions.bzl%maven": { "general": { - "bzlTransitiveDigest": "ktqZUWl2nBo/3HEhakOj9tfmT3+/Z90z7ldq8XwxYnE=", + "bzlTransitiveDigest": "83FuJZZmnUYFkBL19yvsQqztouHV6bGNJDZ2S/XzjUk=", "usagesDigest": "UPebZtX4g40+QepdK3oMHged0o0tq6ojKbW84wE6XRA=", "recordedFileInputs": { "@@rules_jvm_external~//rules_jvm_external_deps_install.json": "10442a5ae27d9ff4c2003e5ab71643bf0d8b48dcf968b4173fa274c3232a8c06" @@ -1102,7 +1102,7 @@ }, "@@rules_jvm_external~//:non-module-deps.bzl%non_module_deps": { "general": { - "bzlTransitiveDigest": "4VF2Z/DNZaLHTP3izo0uTvnjS8it3dSViL5+ack4ogE=", + "bzlTransitiveDigest": "jHJWUyid6+25jvds2/R7FnOsR5Ib0ejFpjunhDyGyOg=", "usagesDigest": "bTG4ItERqhG1LeSs62hQ01DiMarFsflWgpZaghM5qik=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1130,7 +1130,7 @@ }, "@@rules_python~//python/extensions:python.bzl%python": { "general": { - "bzlTransitiveDigest": "e3ZmjG1ZEg3xSbspFPC5afi43pqfpAU89V2ghTtcNug=", + "bzlTransitiveDigest": "xZ+0+4bLHpygHy8fAvBj9Q+D6Wip5ytNwOyL5o3RYgk=", "usagesDigest": "7vjNHuEgQORYN9+9/77Q4zw1kawobM2oCQb9p0uhL68=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1160,7 +1160,7 @@ }, "@@rules_python~//python/extensions/private:internal_deps.bzl%internal_deps": { "general": { - "bzlTransitiveDigest": "f4sn8DF0csno6nVTa/bU1ixR43r+jYeZRRCD3xniTxQ=", + "bzlTransitiveDigest": "2m9fPjGoRqQ1sdoON2zc84DeDZnfeTFkrEUJL4HILPw=", "usagesDigest": "b+nMDqtqPCBxiMBewNNde3aNjzKqZyvJuN5/49xB62s=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, diff --git a/tools/build_defs/repo/cache.bzl b/tools/build_defs/repo/cache.bzl index 8381446da242ff..c4b13695c6ec3a 100644 --- a/tools/build_defs/repo/cache.bzl +++ b/tools/build_defs/repo/cache.bzl @@ -20,7 +20,7 @@ """Returns the default canonical id to use for downloads.""" -visibility("private") +visibility("public") DEFAULT_CANONICAL_ID_ENV = "BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID" From f349322d2bbb136220c8f4a020b335c8c5939ef3 Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Sat, 15 Jun 2024 15:34:43 +0000 Subject: [PATCH 2/9] Add docs, and add to docs --- tools/build_defs/repo/BUILD | 1 + tools/build_defs/repo/cache.bzl | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/build_defs/repo/BUILD b/tools/build_defs/repo/BUILD index 5106cd4aa4a06e..7f4421ec4a22bf 100644 --- a/tools/build_defs/repo/BUILD +++ b/tools/build_defs/repo/BUILD @@ -40,6 +40,7 @@ genrule( ) REPO_BZL_FILES = [ + "cache", "git", "http", "local", diff --git a/tools/build_defs/repo/cache.bzl b/tools/build_defs/repo/cache.bzl index c4b13695c6ec3a..c25f03a0a3d51c 100644 --- a/tools/build_defs/repo/cache.bzl +++ b/tools/build_defs/repo/cache.bzl @@ -37,7 +37,14 @@ machines without the file in the cache. This behavior can be disabled with """.format(env = DEFAULT_CANONICAL_ID_ENV) def get_default_canonical_id(repository_ctx, urls): - """Returns the default canonical id to use for downloads.""" + """Returns the default canonical id to use for downloads. + + Args: + repository_ctx: The repository context of the repository rule calling this utility + function. + urls: A list of URLs matching what is passed to `repository_ctx.download` and + `repository_ctx.download_and_extract`. + """ if repository_ctx.os.environ.get(DEFAULT_CANONICAL_ID_ENV) == "0": return "" From 96ea949775ccdc786cdc7c3a4acf8751dbf42316 Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Sat, 29 Jun 2024 09:02:15 +0000 Subject: [PATCH 3/9] Fix yet another stale lockfile test --- src/test/tools/bzlmod/MODULE.bazel.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/tools/bzlmod/MODULE.bazel.lock b/src/test/tools/bzlmod/MODULE.bazel.lock index 11c8b42a271965..c9d12009c389c0 100644 --- a/src/test/tools/bzlmod/MODULE.bazel.lock +++ b/src/test/tools/bzlmod/MODULE.bazel.lock @@ -78,7 +78,7 @@ }, "@@rules_jvm_external~//:extensions.bzl%maven": { "general": { - "bzlTransitiveDigest": "83FuJZZmnUYFkBL19yvsQqztouHV6bGNJDZ2S/XzjUk=", + "bzlTransitiveDigest": "KqzMuW/WAXZVkDWtLCyF/SgwNKtkT/Ic50xRSPt+UVs=", "usagesDigest": "UPebZtX4g40+QepdK3oMHged0o0tq6ojKbW84wE6XRA=", "recordedFileInputs": { "@@rules_jvm_external~//rules_jvm_external_deps_install.json": "10442a5ae27d9ff4c2003e5ab71643bf0d8b48dcf968b4173fa274c3232a8c06" @@ -1102,7 +1102,7 @@ }, "@@rules_jvm_external~//:non-module-deps.bzl%non_module_deps": { "general": { - "bzlTransitiveDigest": "jHJWUyid6+25jvds2/R7FnOsR5Ib0ejFpjunhDyGyOg=", + "bzlTransitiveDigest": "4L1cBO6rzT4fCqbYTp/aDelibXGNLxzj7JGXDMXqUNA=", "usagesDigest": "bTG4ItERqhG1LeSs62hQ01DiMarFsflWgpZaghM5qik=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1130,7 +1130,7 @@ }, "@@rules_python~//python/extensions:python.bzl%python": { "general": { - "bzlTransitiveDigest": "xZ+0+4bLHpygHy8fAvBj9Q+D6Wip5ytNwOyL5o3RYgk=", + "bzlTransitiveDigest": "Sr3mvz6wxNgpIXYR0EygIRbJru7FRf1KaDjiLbMXDv8=", "usagesDigest": "7vjNHuEgQORYN9+9/77Q4zw1kawobM2oCQb9p0uhL68=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1160,7 +1160,7 @@ }, "@@rules_python~//python/extensions/private:internal_deps.bzl%internal_deps": { "general": { - "bzlTransitiveDigest": "2m9fPjGoRqQ1sdoON2zc84DeDZnfeTFkrEUJL4HILPw=", + "bzlTransitiveDigest": "uJIedcInGWKaa4CnzTU6eGO0hE2KfC3YWdT3Dx2PsNA=", "usagesDigest": "b+nMDqtqPCBxiMBewNNde3aNjzKqZyvJuN5/49xB62s=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, From ed91c3cb1958050e10b9972f6da2fb06d201d074 Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Mon, 1 Jul 2024 08:00:55 +0000 Subject: [PATCH 4/9] Remove dev container (added by mistake in merge) --- .devcontainer/Dockerfile | 37 --------------------------------- .devcontainer/devcontainer.json | 22 -------------------- 2 files changed, 59 deletions(-) delete mode 100644 .devcontainer/Dockerfile delete mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index f5f9a7b133edab..00000000000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -FROM ubuntu:24.10 - -# Update package lists -RUN apt-get update - -RUN apt-get install -y \ - # Required to build Bazel - https://bazel.build/install/compile-source#build-bazel-on-unixes - # NOTE python3 already installed, python2 is no longer supported - build-essential \ - openjdk-21-jdk \ - zip \ - unzip \ - # Dev utils - git \ - curl - -# Install bazelisk, buildifier, buildozer, unused_deps, starpls (amd64 only) -ARG TARGETARCH -RUN if [ $TARGETARCH = "arm64" ]; then \ - curl https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-arm64 -Lo /usr/local/bin/bazel ; \ - curl https://github.com/bazelbuild/buildtools/releases/download/v7.1.2/buildifier-linux-arm64 -Lo /usr/local/bin/buildifier ; \ - curl https://github.com/bazelbuild/buildtools/releases/download/v7.1.2/buildozer-linux-arm64 -Lo /usr/local/bin/buildozer ; \ - curl https://github.com/bazelbuild/buildtools/releases/download/v7.1.2/unused_deps-linux-arm64 -Lo /usr/local/bin/unused_deps ; \ - fi -RUN if [ $TARGETARCH = "amd64" ]; then \ - curl https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64 -Lo /usr/local/bin/bazel ; \ - curl https://github.com/bazelbuild/buildtools/releases/download/v7.1.2/buildifier-linux-amd64 -Lo /usr/local/bin/buildifier ; \ - curl https://github.com/bazelbuild/buildtools/releases/download/v7.1.2/buildozer-linux-amd64 -Lo /usr/local/bin/buildozer ; \ - curl https://github.com/bazelbuild/buildtools/releases/download/v7.1.2/unused_deps-linux-amd64 -Lo /usr/local/bin/unused_deps ; \ - curl https://github.com/withered-magic/starpls/releases/download/v0.1.14/starpls-linux-amd64 -Lo /usr/local/bin/starpls ; \ - fi -RUN chmod +x /usr/local/bin/bazel /usr/local/bin/buildifier /usr/local/bin/buildozer /usr/local/bin/unused_deps -RUN if [ $TARGETARCH = "amd64" ]; then \ - chmod +x /usr/local/bin/starpls ; \ - fi - -CMD [ "bash"] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 9365168e5a2193..00000000000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "Bazel from master", - "build": { - "dockerfile": "./Dockerfile" - }, - "customizations": { - "vscode": { - "extensions": [ - "bazelbuild.vscode-bazel", - "zxh404.vscode-proto3", - "ms-vscode.cpptools", - "galexite.bazel-cpp-tools", - "siliconsoldier.java-with-bazel" - ], - "settings": { - "bazel.enableCodeLens": true, - "bazel.lsp.command": "starpls", - "bazel.lsp.args": ["server"] - } - } - } -} \ No newline at end of file From a45b5112855e8f14bc71e8bd77bd1363f218218d Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Mon, 1 Jul 2024 08:15:39 +0000 Subject: [PATCH 5/9] Make recommendation for specific, improve readability with multi-line text blocks --- .../starlark/StarlarkBaseExternalContext.java | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java index 10713cc7808ddf..1d0d7d3cd98082 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java @@ -598,20 +598,23 @@ private StructImpl completeDownload(PendingDownload pendingDownload) @StarlarkMethod( name = "download", - doc = - "Downloads a file to the output path for the provided url and returns a struct" - + " containing success, a flag which is true if the" - + " download completed successfully, and if successful, a hash of the file" - + " with the fields sha256 and integrity." - + "Setting an explicit canonical_id is highly recommended. e.g." - + "
\n"
-              + "load(\"@bazel_tools//tools/build_defs/repo:cache.bzl\", \"get_default_canonical_id\")\n"
-              + "# ...\n"
-              + "    repository_ctx.download(\n"
-              + "        url = urls,\n"
-              + "        canonical_id = get_default_canonical_id(repository_ctx, urls),\n"
-              + "    ),\n"
-              + "
", + doc = """ + Downloads a file to the output path for the provided url and returns a struct containing \ + success, a flag which is true if the download completed \ + successfully, and if successful, a hash of the file with the fields sha256 \ + and integrity. \ + When sha256 or integrity is user specified, setting an explicit \ + canonical_id is highly recommended. e.g.\ +
+        load("@bazel_tools//tools/build_defs/repo:cache.bzl", "get_default_canonical_id")
+        # ...
+            repository_ctx.download(
+                url = urls,
+                integrity = integrity
+                canonical_id = get_default_canonical_id(repository_ctx, urls),
+            ),
+        
+ """, useStarlarkThread = true, parameters = { @Param( @@ -787,20 +790,23 @@ public Object download( @StarlarkMethod( name = "download_and_extract", - doc = - "Downloads a file to the output path for the provided url, extracts it, and returns a" - + " struct containing success, a flag which is true if the" - + " download completed successfully, and if successful, a hash of the file with the" - + " fields sha256 and integrity." - + "Setting an explicit canonical_id is highly recommended. e.g." - + "
\n"
-              + "load(\"@bazel_tools//tools/build_defs/repo:cache.bzl\", \"get_default_canonical_id\")\n"
-              + "# ...\n"
-              + "    repository_ctx.download_and_extract(\n"
-              + "        url = urls,\n"
-              + "        canonical_id = get_default_canonical_id(repository_ctx, urls),\n"
-              + "    ),\n"
-              + "
", + doc = """ + Downloads a file to the output path for the provided url, extracts it, and returns a \ + struct containing success, a flag which is true if the download \ + completed successfully, and if successful, a hash of the file with the fields \ + sha256 and integrity. \ + When sha256 or integrity is user specified, setting an explicit \ + canonical_id is highly recommended. e.g.\ +
+        load("@bazel_tools//tools/build_defs/repo:cache.bzl", "get_default_canonical_id")
+        # ...
+            repository_ctx.download_and_extract(
+                url = urls,
+                integrity = integrity
+                canonical_id = get_default_canonical_id(repository_ctx, urls),
+            ),
+        
+ """, useStarlarkThread = true, parameters = { @Param( From f76dfcd3394c04bf0b395df7c98fa77c757cdc16 Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Thu, 11 Jul 2024 08:27:43 +0000 Subject: [PATCH 6/9] Add integration test for `get_default_canonical_id` --- .../shell/bazel/external_integration_test.sh | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh index bf14e71adeeabc..a43d2fa243146f 100755 --- a/src/test/shell/bazel/external_integration_test.sh +++ b/src/test/shell/bazel/external_integration_test.sh @@ -3003,6 +3003,26 @@ EOF test -h "$execroot/external/ext" || fail "Expected symlink to external repo." } +function test_default_canonical_id() { + cat > repo.bzl < WORKSPACE <$TEST_log || fail 'Expected fetch to succeed' + expect_log "canonical_id \"url-1 url-2\"" +} + function test_environ_incrementally() { # Set up workspace with a repository rule to examine env vars. Assert that undeclared # env vars don't trigger reevaluations. From 0521b6d15a0bb0b840a37ec4021208031b039bf2 Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Sun, 28 Jul 2024 08:21:24 +0000 Subject: [PATCH 7/9] Relocate example --- .../starlark/StarlarkBaseExternalContext.java | 24 ++++--------------- tools/build_defs/repo/cache.bzl | 11 +++++++++ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java index eaa6959f25e8c4..0eb21dcb7de693 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java @@ -607,16 +607,8 @@ private StructImpl completeDownload(PendingDownload pendingDownload) download completed successfully, and if successful, a hash of the file \ with the fields sha256 and integrity. \ When sha256 or integrity is user specified, setting an explicit \ - canonical_id is highly recommended. e.g.\ -
-          load("@bazel_tools//tools/build_defs/repo:cache.bzl", "get_default_canonical_id")
-          # ...
-              repository_ctx.download(
-                  url = urls,
-                  integrity = integrity
-                  canonical_id = get_default_canonical_id(repository_ctx, urls),
-              ),
-          
+ canonical_id is highly recommended. e.g. \ + get_default_canonical_id """, useStarlarkThread = true, parameters = { @@ -810,16 +802,8 @@ public Object download( download completed successfully, and if successful, a hash of the file with the \ fields sha256 and integrity. \ When sha256 or integrity is user specified, setting an explicit \ - canonical_id is highly recommended. e.g.\ -
-          load("@bazel_tools//tools/build_defs/repo:cache.bzl", "get_default_canonical_id")
-          # ...
-              repository_ctx.download_and_extract(
-                  url = urls,
-                  integrity = integrity
-                  canonical_id = get_default_canonical_id(repository_ctx, urls),
-              ),
-          
+ canonical_id is highly recommended. e.g. \ + get_default_canonical_id """, useStarlarkThread = true, parameters = { diff --git a/tools/build_defs/repo/cache.bzl b/tools/build_defs/repo/cache.bzl index c25f03a0a3d51c..94549f5abe609c 100644 --- a/tools/build_defs/repo/cache.bzl +++ b/tools/build_defs/repo/cache.bzl @@ -38,6 +38,17 @@ machines without the file in the cache. This behavior can be disabled with def get_default_canonical_id(repository_ctx, urls): """Returns the default canonical id to use for downloads. + + e.g. + ```python + load("@bazel_tools//tools/build_defs/repo:cache.bzl", "get_default_canonical_id") + # ... + repository_ctx.download_and_extract( + url = urls, + integrity = integrity + canonical_id = get_default_canonical_id(repository_ctx, urls), + ), + ``` Args: repository_ctx: The repository context of the repository rule calling this utility From ec4284be46dac6912ca2adf8b37a869de7e06a39 Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Sun, 28 Jul 2024 08:25:41 +0000 Subject: [PATCH 8/9] Document how `BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID` changes function behaviour. --- tools/build_defs/repo/cache.bzl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/build_defs/repo/cache.bzl b/tools/build_defs/repo/cache.bzl index 94549f5abe609c..f37005f1acda28 100644 --- a/tools/build_defs/repo/cache.bzl +++ b/tools/build_defs/repo/cache.bzl @@ -39,6 +39,9 @@ machines without the file in the cache. This behavior can be disabled with def get_default_canonical_id(repository_ctx, urls): """Returns the default canonical id to use for downloads. + Returns `""` (empty string) when Bazel is run with + `--repo_env=BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=0`. + e.g. ```python load("@bazel_tools//tools/build_defs/repo:cache.bzl", "get_default_canonical_id") From b5d449a415997574fc5ccdec06560fb955765ff2 Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Wed, 7 Aug 2024 10:26:41 +0000 Subject: [PATCH 9/9] Handle test env quirks, regen reference lockfile --- .../shell/bazel/external_integration_test.sh | 28 +++++++++++++++++-- src/test/tools/bzlmod/MODULE.bazel.lock | 8 +++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh index a43d2fa243146f..41536520b7c00b 100755 --- a/src/test/shell/bazel/external_integration_test.sh +++ b/src/test/shell/bazel/external_integration_test.sh @@ -3003,7 +3003,7 @@ EOF test -h "$execroot/external/ext" || fail "Expected symlink to external repo." } -function test_default_canonical_id() { +function test_default_canonical_id_enabled() { cat > repo.bzl <$TEST_log || fail 'Expected fetch to succeed' + # NOTE: Test environment modifies defaults, so --repo_env must be explicitly set + bazel query @foo//:all --repo_env=BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=1 \ + 2>$TEST_log || fail 'Expected fetch to succeed' expect_log "canonical_id \"url-1 url-2\"" } +function test_default_canonical_id_disabled() { + cat > repo.bzl < WORKSPACE <$TEST_log || fail 'Expected fetch to succeed' + expect_log "canonical_id \"\"" +} + function test_environ_incrementally() { # Set up workspace with a repository rule to examine env vars. Assert that undeclared # env vars don't trigger reevaluations. diff --git a/src/test/tools/bzlmod/MODULE.bazel.lock b/src/test/tools/bzlmod/MODULE.bazel.lock index d15c7b7f18c48e..b0738e25d4ea0b 100644 --- a/src/test/tools/bzlmod/MODULE.bazel.lock +++ b/src/test/tools/bzlmod/MODULE.bazel.lock @@ -78,7 +78,7 @@ }, "@@rules_jvm_external+//:extensions.bzl%maven": { "general": { - "bzlTransitiveDigest": "KqzMuW/WAXZVkDWtLCyF/SgwNKtkT/Ic50xRSPt+UVs=", + "bzlTransitiveDigest": "CquSOxMbEXJdiin22S07vdF5XueLe7C/1aUegFJraoI=", "usagesDigest": "UPebZtX4g40+QepdK3oMHged0o0tq6ojKbW84wE6XRA=", "recordedFileInputs": { "@@rules_jvm_external+//rules_jvm_external_deps_install.json": "10442a5ae27d9ff4c2003e5ab71643bf0d8b48dcf968b4173fa274c3232a8c06" @@ -1102,7 +1102,7 @@ }, "@@rules_jvm_external+//:non-module-deps.bzl%non_module_deps": { "general": { - "bzlTransitiveDigest": "4L1cBO6rzT4fCqbYTp/aDelibXGNLxzj7JGXDMXqUNA=", + "bzlTransitiveDigest": "t8wjmXm1XYN/Ym2VFdqsGJL4YFqYI0/j/LQNVKfZHXg=", "usagesDigest": "bTG4ItERqhG1LeSs62hQ01DiMarFsflWgpZaghM5qik=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1130,7 +1130,7 @@ }, "@@rules_python+//python/extensions:python.bzl%python": { "general": { - "bzlTransitiveDigest": "Sr3mvz6wxNgpIXYR0EygIRbJru7FRf1KaDjiLbMXDv8=", + "bzlTransitiveDigest": "Ro358QxUJINcE96J92gi59lKmnWyK7ABXzyB564+cgQ=", "usagesDigest": "7vjNHuEgQORYN9+9/77Q4zw1kawobM2oCQb9p0uhL68=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1160,7 +1160,7 @@ }, "@@rules_python+//python/extensions/private:internal_deps.bzl%internal_deps": { "general": { - "bzlTransitiveDigest": "uJIedcInGWKaa4CnzTU6eGO0hE2KfC3YWdT3Dx2PsNA=", + "bzlTransitiveDigest": "Il4AzhQf+7B+fihF4rBFnzs5MxUDyNc/sd2zhtlfIVI=", "usagesDigest": "b+nMDqtqPCBxiMBewNNde3aNjzKqZyvJuN5/49xB62s=", "recordedFileInputs": {}, "recordedDirentsInputs": {},