我很困惑:
我正在将一个非常复杂的嵌入式系统的Makefile移植到Bazel,我遇到了一些奇怪的依赖关系问题。
一些背景,所以你知道我为什么要做这些奇怪的事情:我正在用我开发的交叉编译器工具链来构建TI C6000系列处理器。TI为处理器提供了一个可配置的BIOS,您可以使用他们提供的java工具进行配置。这将创建一组文件,包括链接器命令文件和编译器命令文件。它们有一个非标准的扩展名,而Bazel对扩展名很挑剔,所以我在genrule中复制扩展名为genrule的命令文件。
我可以直接构建它,但是当我试图构建一个依赖于正在构建的BIOS的cc_library (因此命令文件是可用的)时,它不会首先构建BIOS。
这是相关的genrule。我逐字地包含了代码,因为我想知道是否有一些微妙的语法错误导致了这个问题。当我尝试调试时,shell部分变得越来越复杂。一旦事情成功,我可能会把它变成一个单独的shell脚本。
genrule(
name = "libs",
srcs = [
":deps",
"ti_bios_without_edma3.cfg",
],
outs = [
"compiler.opt",
"compiler.opt.lds",
"linker.cmd",
"linker.cmd.lds",
"package/package.defs.h",
"package/cfg/ti_bios_without_edma3_pe66.h",
"package/cfg/ti_bios_without_edma3_pe66.oe66",
"package/cfg/ti_bios_without_edma3_pe66.src/utils/utils.ae66",
"package/cfg/ti_bios_without_edma3_pe66.src/sysbios/sysbios.ae66",
"package/cfg/ti_bios_without_edma3_pe66.src/ipc/ipc.ae66",
],
cmd = """
rm -rf "$(@D)" \
&& $(location //phy/platform/ti_bios_common:xdc_parser.sh) \
$(location ti_bios_without_edma3.cfg) \
"/workspace/output/bazel_output_base/execroot/cap/$(location linker.cmd)" \
"$(@D)" > /dev/null \
&& cp $(location linker.cmd) $(location linker.cmd).lds \
&& cp $(location compiler.opt) $(location compiler.opt).lds
""",
tools = ["//phy/platform/ti_bios_common:xdc_parser.sh"],
visibility = ["//visibility:public"],
) 这是取决于它的规则
# TI optimized math library
cc_library(
name = "math_ti",
srcs = [
"src/ti_c66x/multiply_cmplx_mat_vec.c",
"src/ti_c66x/add_cmplx_vec.c",
"src/ti_c66x/add_real_vec.c",
"src/ti_c66x/calc_abs_val_vec.c",
"src/ti_c66x/calc_positive_real_vec_log.c",
"src/ti_c66x/calc_positive_real_vec_sqrt.c",
"src/ti_c66x/calc_vec_cos.c",
"src/ti_c66x/calc_real_vec_exp.c",
"src/ti_c66x/calc_real_vec_alog.c",
"src/ti_c66x/div_real_vec.c",
"src/ti_c66x/multiply_cmplx_mat.c",
"src/ti_c66x/multiply_real_mat.c",
"src/ti_c66x/multiply_real_vec.c",
"src/ti_c66x/multiply_cmplx_vec.c",
"src/ti_c66x/tw_alog.c",
"src/ti_c66x/tw_log.c",
],
hdrs = [
"math_generic.h",
],
copts = [
"--cmd_file=$(location //phy/platform/ti_bios_without_edma3:compiler.opt.lds)"
],
linkopts = [
"-@$(location //phy/platform/ti_bios_without_edma3:linker.cmd.lds)"
],
visibility = [
"//visibility:private",
],
deps = [
":math_generic",
":math_generic_novla",
"//phy/include:common",
"//phy/platform/ti_bios_without_edma3:compiler.opt.lds",
"//phy/platform/ti_bios_without_edma3:linker.cmd.lds",
],
data = [
"//phy/platform/ti_bios_without_edma3:libs",
]
)对于我来说,在构建math库之前,我无法让它构建BIOS。如果我先手动构建BIOS,然后构建math库,那么我的构建就成功了,但是在一个干净的构建中,math库构建失败了,因为还没有构建BIOS。
我在x86上的Ubuntu16.04码头上使用Bazel1.1.0
很抱歉写了本小说。任何帮助都是非常感谢的!
编辑:
$ bazel query "deps(//phy/lib/math:math_ti)"给我的查询
...
//phy/platform/ti_bios_without_edma3:linker.cmd.lds
//phy/platform/ti_bios_without_edma3:compiler.opt.lds
//phy/platform/ti_bios_without_edma3:libs
//phy/platform/ti_bios_without_edma3:ti_bios_without_edma3.cfg
//phy/platform/ti_bios_without_edma3:deps
...因此,它确实认识到//phy/platform/ti_bios_without_edma3:libs是一个依赖项,但它在构建我的库之前并没有构建它:
SUBCOMMAND: # //phy/lib/math:math_ti [action 'Compiling phy/lib/math/src/ti_c66x/multiply_cmplx_mat_vec.c', configuration: 04904b24bebbf24a56366c3e37012771]
...
ERROR: /twbuild/rj/2work/tarana3/cpu/applications/src/phy/lib/math/BUILD:192:1: C++ compilation of rule '//phy/lib/math:math_ti' failed (Exit 1)
>> ERROR: Cannot open command file 'bazel-out/ti_c6000-opt-bn_c10/bin/phy/platform/ti_bios_without_edma3/compiler.opt.lds': No such file or directory
...没有一个子命令显示它试图构建//phy/platform/ti_bios_without_edma3:libs。
在这些命令之后,我可以运行一个find,并且看不到任何生成的文件:
$ find -L . -name compiler.opt.lds
$如果我直接构建//phy/platform/ti_bios_without_edma3:libs,那么我确实会看到生成的文件:
$ find -L . -name compiler.opt.lds
./bazel-src/bazel-out/ti_c6000-opt-bn_c10/bin/phy/platform/ti_bios_without_edma3/compiler.opt.lds
./bazel-bin/phy/platform/ti_bios_without_edma3/compiler.opt.lds
./bazel-out/ti_c6000-opt-null for //phy/lib/math:math_ti
Mnemonic: Middleman
Target: //phy/lib/math:math_ti
Configuration: ti_c6000-opt-bn_c10
ActionKey: 5c25f976e1ff1473093bcd3508178109
Inputs: [bazel-out/ti_c6000-opt-bn_c10/internal/_middlemen/_S_Sphy_Sinclude_Ccommon-null, bazel-out/ti_c6000-opt-bn_c10/internal/_middlemen/_S_Sphy_Slib_Smath_Cmath_Ugeneric-null, bazel-out/ti_c6000-opt-bn_c10/internal/_middlemen/_S_Sphy_Slib_Smath_Cmath_Ugeneric_Unovla-null, phy/lib/math/math_generic.h]
Outputs: [bazel-out/ti_c6000-opt-bn_c10/internal/_middlemen/_S_Sphy_Slib_Smath_Cmath_Uti-null]
action 'Compiling phy/lib/math/src/ti_c66x/multiply_cmplx_mat_vec.c'
Mnemonic: CppCompile
Target: //phy/lib/math:math_ti
Configuration: ti_c6000-opt-bn_c10
ActionKey: 92f17fb0219b9758ba79e3c77721e5c7
Inputs: [bazel-out/host/internal/_middlemen/tools_Sti_Ucompiler_Cempty, bazel-out/ti_c6000-opt-bn_c10/internal/_middlemen/_S_Sphy_Slib_Smath_Cmath_Uti-null, external/bazel_tools/tools/cpp/grep-includes.sh, phy/lib/math/src/ti_c66x/multiply_cmplx_mat_vec.c]
Outputs: [bazel-out/ti_c6000-opt-bn_c10/bin/phy/lib/math/_objs/math_ti/multiply_cmplx_mat_vec.d, bazel-out/ti_c6000-opt-bn_c10/bin/phy/lib/math/_objs/math_ti/multiply_cmplx_mat_vec.o]
Command Line: (exec tools/ti_compiler/wrapper_scripts/cl6x \
-ppa \
-k \
-pden \
-pdv \
-pdew \
-c \
--c99 \
'--diag_error=225' \
-O3 \
phy/lib/math/src/ti_c66x/multiply_cmplx_mat_vec.c \
--output_file \
bazel-out/ti_c6000-opt-bn_c10/bin/phy/lib/math/_objs/math_ti/multiply_cmplx_mat_vec.o \
'-ppd=bazel-out/ti_c6000-opt-bn_c10/bin/phy/lib/math/_objs/math_ti/multiply_cmplx_mat_vec.d' \
-I. \
-Ibazel-out/ti_c6000-opt-bn_c10/bin \
-Iexternal/ti_toolchain/include \
-Ithird_party/ti/dsplib_c66x/packages \
-Ithird_party/ti/mathlib_c66x/packages \
-DPLATFORM_C10 \
-DROLE_BN \
'-DPLATFORM=B10' \
'-DROLE=BN' \
--verbose \
'--cmd_file=bazel-out/ti_c6000-opt-bn_c10/bin/phy/platform/ti_bios_without_edma3/compiler.opt.lds')
bn_c10/bin/phy/platform/ti_bios_without_edma3/compiler.opt.lds编辑:
我没有意识到bazel aquery是一件事。我看到那条线了
action 'Executing genrule //phy/platform/ti_bios_without_edma3:libs'在aquery输出的底部,我认为这意味着Bazel希望在编译完之后而不是之前执行它。
以下是aquery结果的顶部
null for //phy/lib/math:math_ti
Mnemonic: Middleman
Target: //phy/lib/math:math_ti
Configuration: ti_c6000-opt-bn_c10
ActionKey: 5c25f976e1ff1473093bcd3508178109
Inputs: [bazel-out/ti_c6000-opt-bn_c10/internal/_middlemen/_S_Sphy_Sinclude_Ccommon-null, bazel-out/ti_c6000-opt-bn_c10/internal/_middlemen/_S_Sphy_Slib_Smath_Cmath_Ugeneric-null, bazel-out/ti_c6000-opt-bn_c10/internal/_middlemen/_S_Sphy_Slib_Smath_Cmath_Ugeneric_Unovla-null, phy/lib/math/math_generic.h]
Outputs: [bazel-out/ti_c6000-opt-bn_c10/internal/_middlemen/_S_Sphy_Slib_Smath_Cmath_Uti-null]
action 'Compiling phy/lib/math/src/ti_c66x/multiply_cmplx_mat_vec.c'
Mnemonic: CppCompile
Target: //phy/lib/math:math_ti
Configuration: ti_c6000-opt-bn_c10
ActionKey: 92f17fb0219b9758ba79e3c77721e5c7
Inputs: [bazel-out/host/internal/_middlemen/tools_Sti_Ucompiler_Cempty, bazel-out/ti_c6000-opt-bn_c10/internal/_middlemen/_S_Sphy_Slib_Smath_Cmath_Uti-null, external/bazel_tools/tools/cpp/grep-includes.sh, phy/lib/math/src/ti_c66x/multiply_cmplx_mat_vec.c]
Outputs: [bazel-out/ti_c6000-opt-bn_c10/bin/phy/lib/math/_objs/math_ti/multiply_cmplx_mat_vec.d, bazel-out/ti_c6000-opt-bn_c10/bin/phy/lib/math/_objs/math_ti/multiply_cmplx_mat_vec.o]
Command Line: (exec tools/ti_compiler/wrapper_scripts/cl6x \
-ppa \
-k \
-pden \
-pdv \
-pdew \
-c \
--c99 \
'--diag_error=225' \
-O3 \
phy/lib/math/src/ti_c66x/multiply_cmplx_mat_vec.c \
--output_file \
bazel-out/ti_c6000-opt-bn_c10/bin/phy/lib/math/_objs/math_ti/multiply_cmplx_mat_vec.o \
'-ppd=bazel-out/ti_c6000-opt-bn_c10/bin/phy/lib/math/_objs/math_ti/multiply_cmplx_mat_vec.d' \
-I. \
-Ibazel-out/ti_c6000-opt-bn_c10/bin \
-Iexternal/ti_toolchain/include \
-Ithird_party/ti/dsplib_c66x/packages \
-Ithird_party/ti/mathlib_c66x/packages \
-DPLATFORM_C10 \
-DROLE_BN \
'-DPLATFORM=B10' \
'-DROLE=BN' \
--verbose \
'--cmd_file=bazel-out/ti_c6000-opt-bn_c10/bin/phy/platform/ti_bios_without_edma3/compiler.opt.lds')因此,它实际上并没有将compiler.opt.lds或linker.cmd.lds视为输入。
发布于 2020-06-25 22:21:48
我正在为后人写下我的问题的答案:
在编译期间,Bazel没有将libs目标识别为依赖项,原因是Bazel似乎(可以理解)将带有.lds扩展名的文件解释为在链接阶段使用的文件。因此,它将不会构建libs目标,直到它需要它来链接(例如编译之后)。
为了解决这个问题,我向我的math_ti目标添加了一个不必要的头依赖项,然后在编译阶段而不是仅仅在链接阶段触发构建。
感谢百万@啊哈!他帮我理清了发生了什么,我在这个过程中学到了很多关于巴泽尔的事情!
https://stackoverflow.com/questions/62567632
复制相似问题