编译报错
执行:bash apollo.sh build_opt_gpu
报错:
Error downloading https://github.com/bazelbuild/rules_java/archive/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz] to /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/rules_java/temp14928806253694828933/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz:
也就是rules_java
这个包因为服务器无法访问github的原因下不下来;另外也没有proxy可用(学校的服务器);解决方法是自己本地手动下载 -> WinSCP上传服务器 -> 复制到docker -> 修改bazel的.bzl文件中的url。
虽然很麻烦,但是总共只有三个包需要这么干,工作量比想象的少很多了。
参考
https://github.com/ApolloAuto/apollo/issues/14289
解决方法
step1:
三个包分别是 rules_java
和rules_swift
,以及cpython
,下载连接为
https://github.com/bazelbuild/rules_java/archive/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz
# 下载为rules_java-981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz
https://github.com/bazelbuild/rules_swift/releases/download/0.12.1/rules_swift.0.12.1.tar.gz
# 下载为rules_swift.0.12.1.tar.gz
https://github.com/cython/cython/archive/c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz
# 下载为 cython-c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz
step2
上传服务器过程略。
修改bzl中urls
- 对于
rules_java
,rules_swift
,可以直接在apollo/WORKSPACE
下增加如下代码,可以直接覆盖掉不知道在哪里的下载链接:
> pwd
# /apollo
> vi WORKSPACE
### 直接在文件的最后添加:
http_archive(
name = "rules_java",
sha256 = "f5a3e477e579231fca27bf202bb0e8fbe4fc6339d63b38ccb87c2760b533d1c3",
strip_prefix = "rules_java-981f06c3d2bd10225e85209904090eb7b5fb26bd",
urls = [
"file:///tmp/tmp_mapping/rules_java-981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz"
],
)
http_archive(
name = "build_bazel_rules_swift",
sha256 = "bf2861de6bf75115288468f340b0c4609cc99cc1ccc7668f0f71adfd853eedb3",
#strip_prefix = "rules_java-981f06c3d2bd10225e85209904090eb7b5fb26bd",
urls = [
"file:///tmp/tmp_mapping/rules_swift.0.12.1.tar.gz"
],
)
其中/tmp/tmp_mapping/
是docker下的文件夹;
文件复制命令:/usr/bin/docker cp 本地文件路径 ID全称:容器路径
;
docker的ID查看指令:docker ps
,第一列的数字字母混合字符串为ID。
- 对于
cpython
,个人直接用如上的方式修改,但是失败了;于是先grep
找到包含下载链接的bzl文件,修改urls
:
> grep -r "https://github.com/cython/cython/archive/c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz" /apollo/.cache/bazel/
# 匹配结果
# /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/com_github_grpc_grpc/bazel/grpc_python_deps.bzl:
> vi /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/com_github_grpc_grpc/bazel/grpc_python_deps.bzl:
# 修改:
###########
if "cython" not in native.existing_rules():
http_archive(
name = "cython",
build_file = "@com_github_grpc_grpc//third_party:cython.BUILD",
sha256 = "d68138a2381afbdd0876c3cb2a22389043fa01c4badede1228ee073032b07a27",
strip_prefix = "cython-c2b80d87658a8525ce091cbe146cb7eaa29fed5c",
urls = [
# "https://github.com/cython/cython/archive/c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz",
"file:///tmp/tmp_mapping/cython-c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz",
],
)
后记
对bzl不熟悉,找下载url的过程被迫浅浅学习了一通bazel的逻辑,可真是麻烦啊。