diff --git a/BUILD b/BUILD index 1bc6ddede85a02..b49eb116ba7f45 100644 --- a/BUILD +++ b/BUILD @@ -196,9 +196,7 @@ pkg_tar( write_file( name = "gen_maven_repo_name", out = "MAVEN_CANONICAL_REPO_NAME", - # TODO: Use this instead after building with Bazel 7.1.0 or later. - # content = [get_canonical_repo_name("@maven")], - content = ["rules_jvm_external~~maven~maven"], + content = [get_canonical_repo_name("@maven")], ) # The @maven repository is created by maven_install from rules_jvm_external. diff --git a/MODULE.bazel b/MODULE.bazel index 49be7bd6d9c275..18c17375be0c1f 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -33,9 +33,6 @@ bazel_dep(name = "rules_testing", version = "0.6.0") bazel_dep(name = "googletest", version = "1.14.0", repo_name = "com_google_googletest") bazel_dep(name = "with_cfg.bzl", version = "0.2.4") -# TODO(fmeum): Remove the dependency on buildozer after Bazel is built with 7.2.0. -bazel_dep(name = "buildozer", version = "7.1.2") - # TODO(pcloudy): Add remoteapis and googleapis as Bazel modules in the BCR. bazel_dep(name = "remoteapis", version = "") bazel_dep(name = "googleapis", version = "") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index db920441366925..414a2ea78a523e 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 6, - "moduleFileHash": "a7763ee017cb7133cd854e5217de5391d51c90faf7b9e2c412b37980b1952a32", + "moduleFileHash": "5ab4801a351c4ba66bb40b9468e244e1a0e26a0f7978d08975c72527237ae7b9", "flags": { "cmdRegistries": [ "https://bcr.bazel.build/" @@ -39,7 +39,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 80, + "line": 77, "column": 22 }, "imports": { @@ -170,7 +170,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 81, + "line": 78, "column": 14 } }, @@ -185,7 +185,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 207, + "line": 204, "column": 19 } }, @@ -200,7 +200,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 207, + "line": 204, "column": 19 } }, @@ -215,7 +215,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 207, + "line": 204, "column": 19 } }, @@ -230,7 +230,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 207, + "line": 204, "column": 19 } }, @@ -245,7 +245,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 207, + "line": 204, "column": 19 } }, @@ -260,7 +260,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 207, + "line": 204, "column": 19 } }, @@ -275,7 +275,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 207, + "line": 204, "column": 19 } }, @@ -290,7 +290,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 207, + "line": 204, "column": 19 } }, @@ -305,7 +305,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 207, + "line": 204, "column": 19 } }, @@ -333,7 +333,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 371, + "line": 368, "column": 22 } } @@ -347,7 +347,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 228, + "line": 225, "column": 32 }, "imports": { @@ -387,7 +387,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 262, + "line": 259, "column": 23 }, "imports": {}, @@ -401,7 +401,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 263, + "line": 260, "column": 17 } } @@ -415,7 +415,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 265, + "line": 262, "column": 20 }, "imports": { @@ -433,7 +433,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 266, + "line": 263, "column": 10 } } @@ -447,7 +447,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 277, + "line": 274, "column": 33 }, "imports": { @@ -478,7 +478,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 298, + "line": 295, "column": 29 }, "imports": { @@ -495,7 +495,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 301, + "line": 298, "column": 20 }, "imports": { @@ -514,7 +514,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 302, + "line": 299, "column": 12 } } @@ -551,7 +551,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 313, + "line": 310, "column": 10 } }, @@ -568,7 +568,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 320, + "line": 317, "column": 10 } }, @@ -585,7 +585,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 327, + "line": 324, "column": 10 } } @@ -599,7 +599,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 338, + "line": 335, "column": 32 }, "imports": { @@ -618,7 +618,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 346, + "line": 343, "column": 31 }, "imports": { @@ -635,7 +635,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 349, + "line": 346, "column": 48 }, "imports": { @@ -652,7 +652,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 393, + "line": 390, "column": 35 }, "imports": { @@ -669,7 +669,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 396, + "line": 393, "column": 42 }, "imports": { @@ -703,7 +703,6 @@ "rules_testing": "rules_testing@0.6.0", "com_google_googletest": "googletest@1.14.0", "with_cfg.bzl": "with_cfg.bzl@0.2.4", - "buildozer": "buildozer@7.1.2", "remoteapis": "remoteapis@_", "googleapis": "googleapis@_", "apple_support": "apple_support@1.8.1", @@ -1922,73 +1921,6 @@ } } }, - "buildozer@7.1.2": { - "name": "buildozer", - "version": "7.1.2", - "key": "buildozer@7.1.2", - "repoName": "buildozer", - "executionPlatformsToRegister": [], - "toolchainsToRegister": [], - "extensionUsages": [ - { - "extensionBzlFile": "@buildozer//:buildozer_binary.bzl", - "extensionName": "buildozer_binary", - "usingModule": "buildozer@7.1.2", - "location": { - "file": "https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel", - "line": 9, - "column": 33 - }, - "imports": { - "buildozer_binary": "buildozer_binary" - }, - "devImports": [], - "tags": [ - { - "tagName": "buildozer", - "attributeValues": { - "sha256": { - "darwin-amd64": "90da5cf4f7db73007977a8c6bec23fa7022265978187e1da8df5edc91daf6ee1", - "darwin-arm64": "bedff301bc51f04da46d2c8900c1753032ea88485af375a9f1b7bed0915558e0", - "linux-amd64": "8d5c459ab21b411b8be059a8bdf59f0d3eabf9dff943d5eccb80e36e525cc09d", - "linux-arm64": "a00d1790e8c92c5022d83e345d6629506836d73c23c5338d5f777589bfaed02d", - "windows-amd64": "3a650e10f07787760889d7e5694924d881265ae2384499fd59ada7c39c02366e" - }, - "version": "7.1.2" - }, - "devDependency": false, - "location": { - "file": "https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel", - "line": 10, - "column": 27 - } - } - ], - "hasDevUseExtension": false, - "hasNonDevUseExtension": true - } - ], - "deps": { - "bazel_features": "bazel_features@1.11.0", - "bazel_tools": "bazel_tools@_", - "local_config_platform": "local_config_platform@_" - }, - "repoSpec": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_archive", - "attributes": { - "urls": [ - "https://github.com/fmeum/buildozer/releases/download/v7.1.2/buildozer-v7.1.2.tar.gz" - ], - "integrity": "sha256-/HfDfwjmdFCKV5jYSRiuUrO5UQGZ4KwBESo3iWfaQVg=", - "strip_prefix": "buildozer-7.1.2", - "remote_patches": { - "https://bcr.bazel.build/modules/buildozer/7.1.2/patches/module_dot_bazel_version.patch": "sha256-nbMWB+h5mPmkLZWAFPslhFDwz615WFnN2VTEr7Fxhfo=" - }, - "remote_patch_strip": 1 - } - } - }, "remoteapis@_": { "name": "remoteapis", "version": "", @@ -2585,7 +2517,7 @@ "rules_license": "rules_license@0.0.7", "rules_proto": "rules_proto@5.3.0-21.7", "rules_python": "rules_python@0.26.0", - "buildozer": "buildozer@7.1.2", + "buildozer": "buildozer@6.4.0.2", "platforms": "platforms@0.0.9", "com_google_protobuf": "protobuf@21.7", "zlib": "zlib@1.3", @@ -2833,12 +2765,78 @@ "remote_patch_strip": 0 } } + }, + "buildozer@6.4.0.2": { + "name": "buildozer", + "version": "6.4.0.2", + "key": "buildozer@6.4.0.2", + "repoName": "buildozer", + "executionPlatformsToRegister": [], + "toolchainsToRegister": [], + "extensionUsages": [ + { + "extensionBzlFile": "@buildozer//:buildozer_binary.bzl", + "extensionName": "buildozer_binary", + "usingModule": "buildozer@6.4.0.2", + "location": { + "file": "https://bcr.bazel.build/modules/buildozer/6.4.0.2/MODULE.bazel", + "line": 7, + "column": 33 + }, + "imports": { + "buildozer_binary": "buildozer_binary" + }, + "devImports": [], + "tags": [ + { + "tagName": "buildozer", + "attributeValues": { + "sha256": { + "darwin-amd64": "d29e347ecd6b5673d72cb1a8de05bf1b06178dd229ff5eb67fad5100c840cc8e", + "darwin-arm64": "9b9e71bdbec5e7223871e913b65d12f6d8fa026684daf991f00e52ed36a6978d", + "linux-amd64": "8dfd6345da4e9042daa738d7fdf34f699c5dfce4632f7207956fceedd8494119", + "linux-arm64": "6559558fded658c8fa7432a9d011f7c4dcbac6b738feae73d2d5c352e5f605fa", + "windows-amd64": "e7f05bf847f7c3689dd28926460ce6e1097ae97380ac8e6ae7147b7b706ba19b" + }, + "version": "6.4.0" + }, + "devDependency": false, + "location": { + "file": "https://bcr.bazel.build/modules/buildozer/6.4.0.2/MODULE.bazel", + "line": 8, + "column": 27 + } + } + ], + "hasDevUseExtension": false, + "hasNonDevUseExtension": true + } + ], + "deps": { + "bazel_tools": "bazel_tools@_", + "local_config_platform": "local_config_platform@_" + }, + "repoSpec": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "urls": [ + "https://github.com/fmeum/buildozer/releases/download/v6.4.0.2/buildozer-v6.4.0.2.tar.gz" + ], + "integrity": "sha256-k7tFKQMR2AygxpmZfH0yEPnQmF3efFgD9rBPkj+Yz/8=", + "strip_prefix": "buildozer-6.4.0.2", + "remote_patches": { + "https://bcr.bazel.build/modules/buildozer/6.4.0.2/patches/module_dot_bazel_version.patch": "sha256-gKANF2HMilj7bWmuXs4lbBIAAansuWC4IhWGB/CerjU=" + }, + "remote_patch_strip": 1 + } + } } }, "moduleExtensions": { "//:extensions.bzl%bazel_android_deps": { "general": { - "bzlTransitiveDigest": "fsj2Y0/OdubiefV/mXYFaPLbTvxWyuGu7Pp/xcVMWBE=", + "bzlTransitiveDigest": "XTQGhOZRH+L0QMKlqRVyTpRffVkj5HAr2lYssjaosFQ=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -2879,11 +2877,6 @@ "blake3", "blake3~" ], - [ - "", - "buildozer", - "buildozer~" - ], [ "", "c-ares", @@ -2983,20 +2976,15 @@ "bazel_tools", "bazel_tools", "bazel_tools" - ], - [ - "buildozer~", - "buildozer_binary", - "buildozer~~buildozer_binary~buildozer_binary" ] ] } }, "//:extensions.bzl%bazel_build_deps": { "general": { - "bzlTransitiveDigest": "fsj2Y0/OdubiefV/mXYFaPLbTvxWyuGu7Pp/xcVMWBE=", + "bzlTransitiveDigest": "XTQGhOZRH+L0QMKlqRVyTpRffVkj5HAr2lYssjaosFQ=", "recordedFileInputs": { - "@@//MODULE.bazel": "a7763ee017cb7133cd854e5217de5391d51c90faf7b9e2c412b37980b1952a32", + "@@//MODULE.bazel": "5ab4801a351c4ba66bb40b9468e244e1a0e26a0f7978d08975c72527237ae7b9", "@@//src/test/tools/bzlmod/MODULE.bazel.lock": "828ca18c55ab0580454760a1a8b00d414057233329bd7a44c31e477cdaa56d81" }, "recordedDirentsInputs": {}, @@ -3083,7 +3071,6 @@ "apple_support~", "bazel_skylib~", "blake3~", - "buildozer~", "c-ares~", "grpc~", "protobuf~", @@ -3273,11 +3260,6 @@ "blake3", "blake3~" ], - [ - "", - "buildozer", - "buildozer~" - ], [ "", "c-ares", @@ -3377,18 +3359,13 @@ "bazel_tools", "bazel_tools", "bazel_tools" - ], - [ - "buildozer~", - "buildozer_binary", - "buildozer~~buildozer_binary~buildozer_binary" ] ] } }, "//:extensions.bzl%bazel_test_deps": { "general": { - "bzlTransitiveDigest": "fsj2Y0/OdubiefV/mXYFaPLbTvxWyuGu7Pp/xcVMWBE=", + "bzlTransitiveDigest": "XTQGhOZRH+L0QMKlqRVyTpRffVkj5HAr2lYssjaosFQ=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -3439,11 +3416,6 @@ "blake3", "blake3~" ], - [ - "", - "buildozer", - "buildozer~" - ], [ "", "c-ares", @@ -3543,11 +3515,6 @@ "bazel_tools", "bazel_tools", "bazel_tools" - ], - [ - "buildozer~", - "buildozer_binary", - "buildozer~~buildozer_binary~buildozer_binary" ] ] } @@ -3713,6 +3680,31 @@ "recordedRepoMappingEntries": [] } }, + "@@buildozer~//:buildozer_binary.bzl%buildozer_binary": { + "general": { + "bzlTransitiveDigest": "EleDU/FQ1+e/RgkW3aIDmdaxZEthvoWQhsqFTxiSgMI=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "buildozer_binary": { + "bzlFile": "@@buildozer~//private:buildozer_binary.bzl", + "ruleClassName": "_buildozer_binary_repo", + "attributes": { + "sha256": { + "darwin-amd64": "d29e347ecd6b5673d72cb1a8de05bf1b06178dd229ff5eb67fad5100c840cc8e", + "darwin-arm64": "9b9e71bdbec5e7223871e913b65d12f6d8fa026684daf991f00e52ed36a6978d", + "linux-amd64": "8dfd6345da4e9042daa738d7fdf34f699c5dfce4632f7207956fceedd8494119", + "linux-arm64": "6559558fded658c8fa7432a9d011f7c4dcbac6b738feae73d2d5c352e5f605fa", + "windows-amd64": "e7f05bf847f7c3689dd28926460ce6e1097ae97380ac8e6ae7147b7b706ba19b" + }, + "version": "6.4.0" + } + } + }, + "recordedRepoMappingEntries": [] + } + }, "@@gazelle~//:extensions.bzl%go_deps": { "general": { "bzlTransitiveDigest": "V0I2A6HQbPqRuhGhygxjQV47OuSSxVaAXG5m+/637Zw=", diff --git a/repositories.bzl b/repositories.bzl index d73fed56530621..2a7e8d5ec3e211 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -29,7 +29,6 @@ DIST_ARCHIVE_REPOS = [get_canonical_repo_name(repo) for repo in [ "apple_support", "bazel_skylib", "blake3", - "buildozer", "c-ares", "com_github_grpc_grpc", "com_google_protobuf", diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RepoSpec.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RepoSpec.java index d6ad0894c63f02..a9039ff9061d4f 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RepoSpec.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RepoSpec.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.bazel.bzlmod; import com.google.auto.value.AutoValue; -import com.google.common.collect.Maps; import com.ryanharter.auto.value.gson.GenerateTypeAdapter; import javax.annotation.Nullable; @@ -52,28 +51,11 @@ public static Builder builder() { public abstract static class Builder { public abstract Builder setBzlFile(String bzlFile); - abstract String bzlFile(); - public abstract Builder setRuleClassName(String name); public abstract Builder setAttributes(AttributeValues attributes); - abstract AttributeValues attributes(); - - abstract RepoSpec autoBuild(); - - public final RepoSpec build() { - // Ensure backwards compatibility with old lockfiles that still specify the 'name' attribute. - // TODO: Remove this after both the lockfile version has been bumped and Bazel is built with - // with Bazel 7.1.0. - AttributeValues attributes = attributes(); - if (attributes.attributes().containsKey("name")) { - setAttributes( - AttributeValues.create( - Maps.filterKeys(attributes.attributes(), k -> !k.equals("name")))); - } - return autoBuild(); - } + abstract RepoSpec build(); } public boolean isNativeRepoRule() { diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoRuleFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoRuleFunction.java index c3685fa323ea9c..55e4135f8a4882 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoRuleFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoRuleFunction.java @@ -67,11 +67,8 @@ public final class BzlmodRepoRuleFunction implements SkyFunction { * in unambiguous canonical form and thus require no mapping, except instances read from old * lockfiles. */ - // TODO(fmeum): Make this mapping truly empty after bumping LOCK_FILE_VERSION. private static final RepositoryMapping EMPTY_MAIN_REPO_MAPPING = - RepositoryMapping.create( - ImmutableMap.of("", RepositoryName.MAIN, "bazel_tools", RepositoryName.BAZEL_TOOLS), - RepositoryName.MAIN); + RepositoryMapping.create(ImmutableMap.of(), RepositoryName.MAIN); public BzlmodRepoRuleFunction(RuleClassProvider ruleClassProvider, BlazeDirectories directories) { this.ruleClassProvider = ruleClassProvider; diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index 37e8ab23ce636b..76b5d821792351 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -1,5 +1,6 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file") load("//:workspace_deps.bzl", "gen_workspace_stanza") +load("//src/tools/bzlmod:utils.bzl", "get_canonical_repo_name") package(default_visibility = ["//visibility:private"]) @@ -220,9 +221,7 @@ sh_test( write_file( name = "gen_rules_java_repo_name", out = "RULES_JAVA_REPO_NAME", - # TODO: Revert to the following when building with Bazel 7.1.0. - # content = [get_canonical_repo_name("@rules_java")], - content = ["rules_java~"], + content = [get_canonical_repo_name("@rules_java")], ) sh_test( diff --git a/src/tools/bzlmod/utils.bzl b/src/tools/bzlmod/utils.bzl index c8b22a93bd26db..f8398cba4daf72 100644 --- a/src/tools/bzlmod/utils.bzl +++ b/src/tools/bzlmod/utils.bzl @@ -14,7 +14,6 @@ """Helper functions for Bzlmod build""" -load("@buildozer//:buildozer.bzl", "BUILDOZER_LABEL") load(":blazel_utils.bzl", _get_canonical_repo_name = "get_canonical_repo_name") get_canonical_repo_name = _get_canonical_repo_name @@ -51,57 +50,34 @@ def parse_http_artifacts(ctx, lockfile_path, required_repos): lockfile = json.decode(ctx.read(lockfile_path)) http_artifacts = [] found_repos = [] - if "moduleDepGraph" in lockfile: - # TODO: Remove this branch after Bazel is built with 7.2.0. - for _, module in lockfile["moduleDepGraph"].items(): - if "repoSpec" in module and module["repoSpec"]["ruleClassName"] == "http_archive": - repo_spec = module["repoSpec"] - attributes = repo_spec["attributes"] - repo_name = _module_repo_name(module) - - if repo_name not in required_repos: - continue - found_repos.append(repo_name) + for url, sha256 in lockfile["registryFileHashes"].items(): + if not url.endswith("/source.json"): + continue + segments = url.split("/") + module = { + "name": segments[-3], + "version": segments[-2], + } + repo_name = _module_repo_name(module) + if repo_name not in required_repos: + continue + found_repos.append(repo_name) - http_artifacts.append({ - "integrity": attributes["integrity"], - "url": extract_url(attributes), - }) - if "remote_patches" in attributes: - for patch, integrity in attributes["remote_patches"].items(): - http_artifacts.append({ - "integrity": integrity, - "url": patch, - }) - else: - for url, sha256 in lockfile["registryFileHashes"].items(): - if not url.endswith("/source.json"): - continue - segments = url.split("/") - module = { - "name": segments[-3], - "version": segments[-2], - } - repo_name = _module_repo_name(module) - if repo_name not in required_repos: - continue - found_repos.append(repo_name) + ctx.delete("./tempfile") + ctx.download(url, "./tempfile", executable = False, sha256 = sha256) + source_json = json.decode(ctx.read("./tempfile")) - ctx.delete("./tempfile") - ctx.download(url, "./tempfile", executable = False, sha256 = sha256) - source_json = json.decode(ctx.read("./tempfile")) + http_artifacts.append({ + "integrity": source_json["integrity"], + "url": source_json["url"], + }) + for patch, integrity in source_json.get("patches", {}).items(): http_artifacts.append({ - "integrity": source_json["integrity"], - "url": source_json["url"], + "integrity": integrity, + "url": url.rsplit("/", 1)[0] + "/patches/" + patch, }) - for patch, integrity in source_json.get("patches", {}).items(): - http_artifacts.append({ - "integrity": integrity, - "url": url.rsplit("/", 1)[0] + "/patches/" + patch, - }) - for extension_id, extension_entry in lockfile["moduleExtensions"].items(): if extension_id.startswith("@@"): # @@rules_foo~//:extensions.bzl%foo --> rules_foo~ @@ -154,66 +130,10 @@ def parse_registry_files(ctx, lockfile_path, module_files): """ lockfile = json.decode(ctx.read(lockfile_path)) registry_file_hashes = lockfile.get("registryFileHashes", {}) - if registry_file_hashes: - return [ - {"sha256": sha256, "url": url} - for url, sha256 in registry_file_hashes.items() - ] - - # TODO: Remove the following code after Bazel is built with 7.2.0. - registry_files = ["https://bcr.bazel.build/bazel_registry.json"] - - # 1. Collect all source.json files of selected module versions. - for module in lockfile["moduleDepGraph"].values(): - if module["version"]: - registry_files.append(BCR_URL_SCHEME.format( - name = module["name"], - version = module["version"], - file = "source.json", - )) - - # 2. Download registry files to compute their hashes. - registry_file_artifacts = [] - downloads = { - url: ctx.download(url, "./tempdir/{}".format(i), executable = False, block = False) - for i, url in enumerate(registry_files) - } - for url, download in downloads.items(): - hash = download.wait() - registry_file_artifacts.append({"url": url, "sha256": hash.sha256}) - - # 3. Perform module resolution in Starlark to get the MODULE.bazel file URLs - # of all module versions relevant during resolution. The lockfile only - # contains the selected module versions. - module_file_stack = [ctx.path(module_file) for module_file in module_files] - seen_deps = {} - for _ in range(1000000): - if not module_file_stack: - break - bazel_deps = _extract_bazel_deps(ctx, module_file_stack.pop()) - downloads = {} - for dep in bazel_deps: - if dep in seen_deps: - continue - url = BCR_URL_SCHEME.format( - name = dep.name, - version = dep.version, - file = "MODULE.bazel", - ) - path = ctx.path("./tempdir/modules/{name}/{version}/MODULE.bazel".format( - name = dep.name, - version = dep.version, - )) - module_file_stack.append(path) - seen_deps[dep] = None - downloads[url] = ctx.download(url, path, executable = False, block = False) - - for url, download in downloads.items(): - hash = download.wait() - registry_file_artifacts.append({"url": url, "sha256": hash.sha256}) - - ctx.delete("./tempdir") - return registry_file_artifacts + return [ + {"sha256": sha256, "url": url} + for url, sha256 in registry_file_hashes.items() + ] def parse_bazel_module_repos(ctx, lockfile_path): """Parse repo names of http_archive backed Bazel modules from the given lockfile. @@ -248,30 +168,4 @@ def _module_repo_name(module): if module_name in _WELL_KNOWN_MODULES: return module_name - # TODO(pcloudy): Simplify the following logic after we upgrade to 7.1 - if get_canonical_repo_name("rules_cc").endswith("~"): - return "{}~".format(module_name) - - return "{}~{}".format(module_name, module["version"]) - -def _extract_bazel_deps(ctx, module_file): - buildozer = ctx.path(BUILDOZER_LABEL) - temp_path = "tempdir/buildozer/MODULE.bazel" - ctx.delete(temp_path) - ctx.symlink(module_file, temp_path) - result = ctx.execute([buildozer, "print name version dev_dependency", temp_path + ":%bazel_dep"]) - if result.return_code != 0: - fail("Failed to extract bazel_dep from {}:\n{}".format(module_file, result.stderr)) - deps = [] - for line in result.stdout.splitlines(): - if " " in line: - # The dep doesn't have a version specified, which is only valid in - # the root module. Ignore it. - continue - if line.endswith(" True"): - # The dep is a dev_dependency, ignore it. - continue - name, version, _ = line.split(" ") - deps.append(struct(name = name, version = version)) - - return deps + return "{}~".format(module_name)