Bazel sha256校验和

Bazel sha256 checksum

我正在努力将我们的项目迁移到 Bazel。

工作空间

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")


RULES_JVM_EXTERNAL_TAG = "2.10"
RULES_JVM_EXTERNAL_SHA = "1bbf2e48d07686707dd85357e9a94da775e1dbd7c464272b3664283c9c716d26"
 
http_archive(
    name = "rules_jvm_external",
    strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
    sha256 = RULES_JVM_EXTERNAL_SHA,
    url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)

load("@rules_jvm_external//:defs.bzl", "maven_install")
 
maven_install(
    name = "maven",
    artifacts = [
        "com.foo:bar:1.0.0-SNAPSHOT"
        "org.apache.commons:commons-lang3:3.9",
    ], 
    repositories = [ 

        "https://our-maven-repo",
    ],
    resolve_timeout = 200,
    fail_on_missing_checksum = False,
    fetch_sources = True
    
)

建造

java_library(
    name = "our-name",
    srcs = glob([
        "src/main/java/**/*.java"
    ]),
    resources = glob([
        "src/main/resources/**",
    ]),
    deps = [
        "@maven//:com.foo_bar",
        "@maven//:org.apache.commons_commons-lang3"
    ],
)

当我运行:

PS> bazel fetch //:our-name

输出

INFO: Call stack for the definition of repository 'maven' which is a coursier_fetch (rule definition at C:/users/name/_bazel_name/73nyktky/external/rules_jvm_external/coursier.bzl:620:18):
 - C:/users/name/_bazel_name/73nyktky/external/rules_jvm_external/defs.bzl:89:5
 - C:/project/WORKSPACE:19:1
INFO: Repository 'maven' used the following cache hits instead of downloading the corresponding file.
 * Hash '8f35f92fb8e021f96b3aa8145c66c3b2e29295baabb28ff50569e613438afcbd' for https://github.com/coursier/coursier/releases/download/v2.0.0-RC3-4/coursier.jar
If the definition of 'maven' was updated, verify that the hashes were also updated.
ERROR: An error occurred during the fetch of repository 'maven':
   Error while obtaining the sha256 checksum of v1/https/our-repo/prod/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar: java.io.IOException: ERROR: src/main/native/windows/process.cc(199): CreateProcessW("python" C:/users/name/_bazel_name/73nyktky/external/bazel_tools/tools/build_defs/hash/sha256.py C:/users/name/_bazel_name/73nyktky/external/maven/v1/https/ourrepo/prod/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar artifact.sha256): The system cannot find the file specified.
 (error: 2)
ERROR: C:/project/BUILD:1:1: no such package '@maven//': Error while obtaining the sha256 checksum of v1/https/our-repo/prod/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar: java.io.IOException: ERROR: src/main/native/windows/process.cc(199): CreateProcessW("python" C:/users/name/_bazel_name/73nyktky/external/bazel_tools/tools/build_defs/hash/sha256.py C:/users/name/_bazel_name/73nyktky/external/maven/v1/https/ourrepo/prod/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar artifact.sha256): The system cannot find the file specified.
 (error: 2) and referenced by '//:our-name'
ERROR: Evaluation of query "deps(//:our-name)" failed: errors were encountered while computing transitive closure
Loading: 0 packages loaded

org.apache.commons:commons-lang3:3.9 jar 连同 sha1 和 md5 哈希一起下载。 com.foo:bar:1.0.0-SNAPSHOT jar 未下载。确实下载了 sha1 和 md5。

我认为我的问题是我们的存储库没有任何 sha256 哈希值可供下载,因此获取(或构建)失败并出现该错误。但是,当我查看实际的 rules_jvm_external https://github.com/bazelbuild/rules_jvm_external#checksum-verification 时,似乎 sha256 不是强制性的?

对我做错了什么有什么想法吗?

巴泽尔 1.1.0 Windows10 企业版,版本 1803,OS 内部版本 17134.1069

rules_jvm_external 这里是维护者。

ERROR: C:/project/BUILD:1:1: no such package '@maven//': Error while obtaining the sha256 checksum of v1/https/our-repo/prod/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar: java.io.IOException: ERROR: src/main/native/windows/process.cc(199): CreateProcessW("python" C:/users/name/_bazel_name/73nyktky/external/bazel_tools/tools/build_defs/hash/sha256.py C:/users/name/_bazel_name/73nyktky/external/maven/v1/https/ourrepo/prod/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar artifact.sha256): The system cannot find the file specified.

这是真正的错误,Windows' CreateProcessW 抱怨 python 不可用。之前也有报道 in this issue。我们在 2.3 中添加了 SHA256 检查,不幸的是这取决于 Python.

你有python安装吗?有一个出色的 PR drops the dependency here.