Bazel¶
警告
此功能是实验性的,可能会发生重大更改。有关更多信息,请参阅 Conan 稳定性 部分。
Bazel
构建助手是 Bazel 命令行调用的封装器。它将把 bazel <rcpaths> build <configs> <targets>
等调用抽象为 Python 方法调用。
此助手旨在用于 conanfile.py 的 build()
方法中,以便在 Conan 直接构建包时(创建、安装)自动调用 Bazel 命令。
from conan import ConanFile
from conan.tools.google import Bazel
class App(ConanFile):
settings = "os", "arch", "compiler", "build_type"
def build(self):
bz = Bazel(self)
bz.build(target="//main:hello-world")
参考¶
- class Bazel(conanfile)¶
- 参数:
conanfile –
< ConanFile object >
当前的配方对象。始终使用self
。
- build(args=None, target='//...', clean=True)¶
运行 “bazel <rcpaths> build <configs> <args> <targets>” 命令,其中
rcpaths
:为每个 rc-file 路径添加--bazelrc=xxxx
。它监听BazelToolchain
(--bazelrc=conan_bzl.rc
) 和tools.google.bazel:bazelrc_path
配置。configs
:为每个 bazel-build 配置添加--config=xxxx
。它监听BazelToolchain
(--config=conan-config
) 和tools.google.bazel:configs
配置。args
:它们是添加到bazel build
执行的任何额外参数。targets
:所有目标标签。
- 参数:
target – 目标标签。默认情况下,它是 “//…”,表示运行所有目标。
args – 要传递给 CLI 的额外参数列表。
clean – 布尔值,指示在运行 “bazel build” 之前运行 “bazel clean”。请注意,这对于确保每次都有一个新的 Bazel 缓存很重要。
- test(target=None)¶
运行 “bazel test <targets>” 命令。
属性¶
以下属性会影响 Bazel
构建助手
tools.build:skip_test=<bool>
(布尔值) 如果为True
,则运行bazel test <target>
。
conf¶
Bazel
受这些 [conf] 变量影响
tools.google.bazel:bazelrc_path
:其他 bazelrc 文件的路径列表,用作 bazel --bazelrc=rcpath1 ... build。tools.google.bazel:configs
:Bazel 配置列表,用作 bazel build --config=config1 ...。