gpt4 book ai didi

bazel - 强制 Bazel 仅使用本地 java

转载 作者:行者123 更新时间:2023-12-04 13:41:57 24 4
gpt4 key购买 nike

我想在一个没有不受控制的互联网访问的锁定环境中使用 bazel。我想强制 bazel 使用本地安装的 java,而不是下载一个。我无法弄清楚所需的标志组合 - 这是我尝试过的:

$ java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
$ javac -version
javac 1.8.0_171
$ bazel clean --expunge
$ bazel info release
release 0.24.1
$ bazel build //hello
# This builds a 'hello world' cpp file.
# This rule also downloads some rules, would be nice to avoid it as
INFO: Build completed successfully, 6 total actions well
$ bazel test --nofetch //hello:hello_test
ERROR: /home/erenon/.cache/bazel/_bazel_erenon/afacf41c7e3fc3f4ea7510d344b4de38/external/bazel_tools/tools/jdk/BUILD:218:1: no such package '@remote_java_tools//': to fix, run
bazel fetch //...
External repository @remote_java_tools not found and fetching repositories is disabled. and referenced by '@bazel_tools//tools/jdk:JacocoCoverageRunner'
ERROR: Analysis of target '//hello:hello_test' failed; build aborted: no such package '@remote_java_tools//': to fix, run
bazel fetch //...
External repository @remote_java_tools not found and fetching repositories is disabled.
INFO: Elapsed time: 0.160s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (3 packages loaded, 27 targets configured)
FAILED: Build did NOT complete successfully (3 packages loaded, 27 targets configured)

我使用更复杂的命令行得到相同的结果:
$ bazel test --nofetch --define=ABSOLUTE_JAVABASE=/usr/lib/jvm/java-8-openjdk-amd64 --host_javabase=@local_jdk//:jdk --javabase=@local_jdk//:jdk --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 //hello:hello_test
INFO: Build options --define, --host_java_toolchain, --host_javabase, and 2 more have changed, discarding analysis cache.
ERROR: /home/erenon/.cache/bazel/_bazel_erenon/afacf41c7e3fc3f4ea7510d344b4de38/external/bazel_tools/tools/jdk/BUILD:218:1: no such package '@remote_java_tools//': to fix, run
bazel fetch //...
External repository @remote_java_tools not found and fetching repositories is disabled. and referenced by '@bazel_tools//tools/jdk:JacocoCoverageRunner'
ERROR: Analysis of target '//hello:hello_test' failed; build aborted: no such package '@remote_java_tools//': to fix, run
bazel fetch //...
External repository @remote_java_tools not found and fetching repositories is disabled.
INFO: Elapsed time: 0.215s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 50 targets configured)
FAILED: Build did NOT complete successfully (0 packages loaded, 50 targets configured)

我尝试了 java 标志的所有组合,但没有运气。我还尝试启用每个不兼容的更改( --all_incompatible_changes ),这会产生不同的结果:
INFO: Build options --incompatible_allow_python_version_transitions, --incompatible_auto_configure_host_platform, --incompatible_cc_coverage, and 24 more have changed, discarding analysis cache.
ERROR: While resolving toolchains for target //hello:hello_test: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package '@local_config_platform//': to fix, run
bazel fetch //...
External repository @local_config_platform not found and fetching repositories is disabled.
ERROR: Analysis of target '//hello:hello_test' failed; build aborted: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package '@local_config_platform//': to fix, run
bazel fetch //...
External repository @local_config_platform not found and fetching repositories is disabled.
INFO: Elapsed time: 0.228s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)

它现在寻找 @local_config_platform .
  • 是否有我可以从源代码构建并包含这些依赖项的 bazel 目标?
  • 是否有不同的命令行,可以启用 bazel test --nofetch ?
  • 最佳答案

    看来从源代码引导 bazel 可以解决这个问题。下载后bazel-<version>-dist.zip来自 GitHub , 在解压后的文件夹中:

    env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" bash ./compile.sh

    The compiled output is placed into output/bazel. This is a self-contained Bazel binary, without an embedded JDK.



    https://docs.bazel.build/versions/master/install-compile-source.html

    关于bazel - 强制 Bazel 仅使用本地 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55888483/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com