Bazel¶
警告
This feature is experimental and subject to breaking changes. See the Conan stability section for more information.
The Bazel build helper is a wrapper around the command line invocation of bazel. It will abstract the
calls like bazel <rcpaths> build <configs> <targets> into Python method calls.
The helper is intended to be used in the conanfile.py build() method, to call Bazel commands automatically
when a package is being built directly by Conan (create, install)
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")
Reference¶
- class Bazel(conanfile)¶
- 參數:
conanfile –
< ConanFile object >The current recipe object. Always useself.
- build(args=None, target='//...', clean=True)¶
Runs 「bazel <rcpaths> build <configs> <args> <targets>」 command where:
rcpaths: adds--bazelrc=xxxxper rc-file path. It listens toBazelToolchain(--bazelrc=conan_bzl.rc), andtools.google.bazel:bazelrc_pathconf.configs: adds--config=xxxxper bazel-build configuration. It listens toBazelToolchain(--config=conan-config), andtools.google.bazel:configsconf.args: they are any extra arguments to add to thebazel buildexecution.targets: all the target labels.
- 參數:
target – It is the target label. By default, it’s 「//…」 which runs all the targets.
args – list of extra arguments to pass to the CLI.
clean – boolean that indicates to run a 「bazel clean」 before running the 「bazel build」. Notice that this is important to ensure a fresh bazel cache every
- test(target=None)¶
Runs 「bazel test <targets>」 command.
Properties¶
The following properties affect the Bazel build helper:
tools.build:skip_test=<bool>(boolean) ifTrue, it runs thebazel test <target>.
conf¶
Bazel is affected by these [conf] variables:
tools.google.bazel:bazelrc_path: List of paths to other bazelrc files to be used as bazel --bazelrc=rcpath1 ... build.tools.google.bazel:configs: List of Bazel configurations to be used as bazel build --config=config1 ....