1

我试图引用一个规则的输出,该规则嵌套在另一个规则的输出目录中genrule

例如,我使用rules_foreign_cc来构建 boost:

boost_build(
    name = "boost",
    lib_source = "@boost//:all",
    linkopts = [
        "-lpthread",
    ],
    shared_libraries = [
        "libboost_chrono.so.1.72.0",
        "libboost_program_options.so.1.72.0",
        "libboost_filesystem.so.1.72.0",
        "libboost_system.so.1.72.0",
        "libboost_thread.so.1.72.0",
        "libboost_timer.so.1.72.0",
    ],
    user_options = [
        "cxxstd=17",
        "--with-chrono",
        "--with-filesystem",
        "--with-program_options",
        "--with-system",
        "--with-thread",
        "--with-timer",
        "-j4",
    ],
)

当我构建它时,我看到了输出:

bazel build //:boost
INFO: Invocation ID: 36440de3-15f2-4ca0-8802-0a95f75ed926
INFO: Analyzed target //:boost (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:boost up-to-date:
  bazel-bin/boost/include
  bazel-bin/boost/lib/libboost_chrono.so.1.72.0
  bazel-bin/boost/lib/libboost_program_options.so.1.72.0
  bazel-bin/boost/lib/libboost_filesystem.so.1.72.0
  bazel-bin/boost/lib/libboost_system.so.1.72.0
  bazel-bin/boost/lib/libboost_thread.so.1.72.0
  bazel-bin/boost/lib/libboost_timer.so.1.72.0
  bazel-bin/copy_boost/boost
  bazel-bin/boost/logs/BuildBoost_script.sh
  bazel-bin/boost/logs/BuildBoost.log
  bazel-bin/boost/logs/wrapper_script.sh
INFO: Elapsed time: 0.758s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action

Boost 工作正常,我可以在cc_library目标中引用它,并且二进制文件运行良好。

现在,我想引用一个 genrule 中的输出之一。我要引用的文件嵌套在boost/lib/目录中。我会期待类似的东西:$(location :boost/lib/libboost_program_options.so.1.72.0),但这不起作用。

引用目录中的输出的正确方法是什么?

4

1 回答 1

0

这就是我所做的,希望它有所帮助。在你的内部genrule,创建一个变量来保存你的 boost 规则的输出数组,使用$(locations)而不是$(location). 然后循环遍历数组,找到以后要使用的路径。

BOOST_OUTPUTS=( $(locations boost) )
LIBBOOST_CHRONO_SO=

for i in "$${{BOOST_OUTPUTS[@]}}"
do
    if [[ "$$i" == *"libboost_chrono.so.1.72.0"* ]]; then
        LIBBOOST_CHRONO_SO="$$i"
    fi
done

# Do something with LIBBOOST_CHRONO_SO

请注意$$and {{and}}用于转义特殊字符。

于 2020-04-26T12:34:09.690 回答