java – 在不同的机器上运行bazel远程执行程序测试

bazel(here)的远程工作者指南解释了如何在本地启动远程工作者,然后对其运行bazel.

我尝试过它确实有效(带有错误的reported in GH)

另一种尝试是在虚拟的独立机器上创建运行远程工作器,方法是在docker容器内运行并运行bazel.但它以不同的方式失败了 – 我想这次我错了.

这是我的docker文件:

FROM openjdk:8

# install release bazel from apt
RUN echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list
RUN curl https://bazel.build/bazel-release.pub.gpg |  apt-key add -
RUN apt-get update && apt-get install -y zip bazel

# compile dev bazel from sources
RUN mkdir -p /usr/src/bazel
# "bazel" has the latest development code of bazel from github
COPY bazel /usr/src/bazel
WORKDIR /usr/src/bazel
RUN bazel build src/bazel

# compile remote_worker using latest development bazel
RUN bazel-bin/src/bazel build //src/tools/remote_worker

# prepare cache folder
RUN mkdir -p /tmp/test

# Run remote-worker
CMD ["bazel-bin/src/tools/remote_worker/remote_worker","--work_path=/tmp/test","--listen_port=3030"]

构建它之后,我只需运行将端口绑定到localhost的docker:

$docker build -t bazel-worker .
$docker run -p 3030:3030 bazel-worker

然后运行bazel java test以使用远程工作程序运行:
(可以查看我的测试报告here)

$bazel --host_jvm_args=-Dbazel.DigestFunction=SHA1 test \
      --spawn_strategy=remote \
      --remote_executor=localhost:3030 \
      --remote_cache=localhost:3030 \
      --strategy=Javac=remote \
      --remote_local_fallback=false \
      --remote_timeout=600 \
      //src/main/java/com/example/...

但我得到了这个奇怪的错误信息:

____Loading package: src/main/java/com/example
____Loading package: @bazel_tools//tools/cpp
____Loading package: @local_jdk//
____Loading package: @local_config_xcode//
____Loading package: @local_config_cc//
____Loading complete.  Analyzing...
____Loading package: tools/defaults
____Loading package: @bazel_tools//third_party/java/jdk/langtools
____Loading package: @junit//jar
____Found 1 test target...
____Building...
____[0 / 2] BazelWorkspaceStatusAction stable-status.txt
____[2 / 4] Creating source manifest for //src/main/java/com/example:my_test
____From Extracting interface @junit//jar:jar:
/tmp/test/build-80057300-ffd2-49ea-a20b-3f234d9963db/external/bazel_tools/tools/jdk/ijar/ijar: 1: /tmp/test/build-80057300-ffd2-49ea-a20b-3f234d9963db/external/bazel_tools/tools/jdk/ijar/ijar: �����0��!H__PAGEZEROx__TEXTpp__text__TEXT/��__stubs__TEXT0p�__stub_helper__TEXT���__gcc_except_tab__TEXT�: not found
/tmp/test/build-80057300-ffd2-49ea-a20b-3f234d9963db/external/bazel_tools/tools/jdk/ijar/ijar: 2: /tmp/test/build-80057300-ffd2-49ea-a20b-3f234d9963db/external/bazel_tools/tools/jdk/ijar/ijar: Syntax error: word unexpected (expecting ")")
ERROR: /private/var/tmp/_bazel_ors/719f891d5db9fd5e73ade25b0c847fd1/external/junit/jar/BUILD.bazel:2:1: output 'external/junit/jar/_ijar/jar/external/junit/jar/junit-4.12-ijar.jar' was not created.
ERROR: /private/var/tmp/_bazel_ors/719f891d5db9fd5e73ade25b0c847fd1/external/junit/jar/BUILD.bazel:2:1: not all outputs were created or valid.
____Building complete.
Target //src/main/java/com/example:my_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
____Elapsed time: 13.614s, Critical Path: 0.21s

我做错了吗?在实际(或虚拟)远程计算机上运行远程工作程序时,是否需要以不同方式运行它(而不是仅在本地运行它)?

重要提一下:我的机器是mac osx sierra. ,我相信docker openjdk:8是基于ubuntu的,我正在运行本地bazel开发版(sha 956810b6ee24289e457a4b8d0a84ff56eb32c264).

解决方法:

在与Bazel本身不同的架构/操作系统组合上运行远程工作程序尚未运行.我们在Bazel还有几个地方,我们检查当地的机器 – 它们是作为临时措施添加的,但尚未修复.

编辑:它可能在某些情况下有效,特别是对于与平台无关的代码(例如,Java或Scala).

如果您的构建测试很重,您可以尝试仅使用–test_strategy = remote远程运行测试;不过,我不确定默认的Jvm配置是否可行.

如果您想远程运行整个构建,那么您需要告诉Bazel它正在执行哪种机器/操作系统.现在,这需要设置–host_cpu,并且可能需要–crosstool_top / –host_crosstool_top来为该平台配置C编译器.

此外,平台的某些组合更多,并且一些不太可能工作.特别是,结合MacOS和Linux或不同风格的Linux比任何组合中的Windows更有可能工作.

上一篇:使用bazel从源代码编译tensorflow踩坑记录


下一篇:全志H64平台ANR重启问题分析