背景介绍
在红帽 源码安装Bazel时,执行指令:
env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk --tool_java_runtime_version=local_jdk" bash ./compile.sh
执行指令报错(github的issue地址):
ERROR: /var/tmp/bazel_ypZaJyXq/out/external/com_github_grpc_grpc/BUILD:1254:16: Compiling src/core/lib/iomgr/resolve_address_custom.cc failed: (Exit 1): gcc failed: error executing command
(cd /var/tmp/bazel_ypZaJyXq/out/execroot/io_bazel &&
exec env -
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/builddir/.local/bin:/builddir/bin
PWD=/proc/self/cwd
/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 ‘-D_FORTIFY_SOURCE=1’ -DNDEBUG -ffunction-sections -fdata-sections ‘-std=c++0x’ -MD -MF bazel-out/ppc-opt/bin/external/com_github_grpc_grpc/objs/grpc_base_c/resolve_address_custom.d '-frandom-seed=bazel-out/ppc-opt/bin/external/com_github_grpc_grpc/objs/grpc_base_c/resolve_address_custom.o’ -iquote external/com_github_grpc_grpc -iquote bazel-out/ppc-opt/bin/external/com_github_grpc_grpc -iquote external/upb -iquote bazel-out/ppc-opt/bin/external/upb -iquote external/com_google_protobuf -iquote bazel-out/ppc-opt/bin/external/com_google_protobuf -iquote external/com_google_absl -iquote bazel-out/ppc-opt/bin/external/com_google_absl -iquote . -iquote bazel-out/ppc-opt/bin -isystem external/com_github_grpc_grpc/include -isystem bazel-out/ppc-opt/bin/external/com_github_grpc_grpc/include -isystem external/com_github_grpc_grpc/src/core/ext/upb-generated -isystem bazel-out/ppc-opt/bin/external/com_github_grpc_grpc/src/core/ext/upb-generated -isystem external/com_github_grpc_grpc/src/core/ext/upbdefs-generated -isystem bazel-out/ppc-opt/bin/external/com_github_grpc_grpc/src/core/ext/upbdefs-generated -isystem third_party/zlib -isystem bazel-out/ppc-opt/bin/third_party/zlib -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE=“redacted”’ ‘-D__TIMESTAMP__=“redacted”’ ‘-D__TIME__=“redacted”’ -c external/com_github_grpc_grpc/src/core/lib/iomgr/resolve_address_custom.cc -o bazel-out/ppc-opt/bin/external/com_github_grpc_grpc/_objs/grpc_base_c/resolve_address_custom.o)
# Configuration: cb266f3995a6d05424d5d5f9027f493b1e9335e0a601bb71bcd48f86902f55b7
# Execution platform: //:default_host_platform
In file included from external/com_github_grpc_grpc/src/core/lib/iomgr/closure.h:33:0,
from external/com_github_grpc_grpc/src/core/lib/iomgr/exec_ctx.h:35,
from external/com_github_grpc_grpc/src/core/lib/iomgr/pollset.h:27,
from external/com_github_grpc_grpc/src/core/lib/iomgr/pollset_set.h:24,
from external/com_github_grpc_grpc/src/core/lib/iomgr/resolve_address.h:36,
from external/com_github_grpc_grpc/src/core/lib/iomgr/resolve_address_custom.h:25,
from external/com_github_grpc_grpc/src/core/lib/iomgr/resolve_address_custom.cc:21:
external/com_github_grpc_grpc/src/core/lib/iomgr/resolve_address_custom.cc: In function ‘grpc_error* try_split_host_port(const char*, const char*, std::string*, std::string*)’:
external/com_github_grpc_grpc/src/core/lib/iomgr/resolve_address_custom.cc:97:60: error: no matching function for call to ‘StrFormat(const char [28], const char*&)’
absl::StrFormat(“unparseable host:port: ‘%s’”, name));
解决办法:
修改StrFormat函数,让其可以匹配到调用的位置。
1、获取StrFormat函数源码
将下列文件拷贝到单独目录:
- bazel-5.0.0-dist/derived/distdir/997aaf3a28308eba1b9156aa35ab7bca9688e9f6.tar.gz
- bazel-5.0.0-dist/derived/distdir/v1.41.0.tar.gz
2、修改StrFormat函数
执行以下命令解包:
tar -zxvf 997aaf3a28308eba1b9156aa35ab7bca9688e9f6.tar.gz
得到:abseil-cpp-997aaf3a28308eba1b9156aa35ab7bca9688e9f6目录。编辑abseil-cpp-997aaf3a28308eba1b9156aa35ab7bca9688e9f6/absl/strings/str_format.h 修改StrFormat函数。修改如下:
// 原函数
template <typename... Args>
ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec<Args...>& format,
const Args&... args) {
return str_format_internal::FormatPack(
str_format_internal::UntypedFormatSpecImpl::Extract(format),
{str_format_internal::FormatArgImpl(args)...});
}
// 将上面函数修改为:
template <typename... Args>
ABSL_MUST_USE_RESULT std::string StrFormat(const char* pformat,
const Args&... args) {
str_format_internal::UntypedFormatSpecImpl format(pformat);
return str_format_internal::FormatPack(
format,
{str_format_internal::FormatArgImpl(args)...});
}
修改完后重新打包,并获取新包的sha256值。
tar -zcvf 997aaf3a28308eba1b9156aa35ab7bca9688e9f6.tar.gz abseil-cpp-997aaf3a28308eba1b9156aa35ab7bca9688e9f6
sha256sum 997aaf3a28308eba1b9156aa35ab7bca9688e9f6.tar.gz
编辑Bazel源码工程的 bazel-5.0.0-dist/distdir_deps.bzl 文件165行。将上面命令获取到的sha256的值替换到abseil-cpp模块的sha256属性位置。
将新打包好的997aaf3a28308eba1b9156aa35ab7bca9688e9f6.tar.gz压缩文件拷贝到Bazel工程的derived/distdir目录下进行替换。
3、重新打包grpc模块
执行以下命令解压grpc包:
tar -zxvf v1.41.0.tar.gz
解压后得到grpc-1.41.0目录。编辑:grpc-1.41.0/bazel/grpc_deps.bzl 文件的第286行
将第二步获取的sha256的值替换到com_google_absl模块的sha256属性位置。
重新打包并计算sha256值:
tar -zcvf v1.41.0.tar.gz grpc-1.41.0
sha256sum v1.41.0.tar.gz
编辑Bazel源码工程的 bazel-5.0.0-dist/distdir_deps.bzl 文件124行。将上面命令获取到的sha256的值替换到com_github_grpc_grpc模块的sha256属性位置。
将新打包好的v1.41.0.tar.gz压缩文件拷贝到Bazel工程的derived/distdir目录下进行替换。
4、重新执行编译脚本即可修复该报错:
env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk --tool_java_runtime_version=local_jdk" bash ./compile.sh