除非明确指定,否则不要包含默认构建的 cc_library
Don't include a cc_library to be built by default unless explicitly specified
我有一些目标,我不想在默认情况下执行 bazel build ...
时包括在内。我怎样才能以这样的方式标记它们,除非通过`bazel build //a/b/c:foo?
明确构建,否则它们不会被构建
您可以为每个可选目标添加一个标签,并使用 --build_tag_fitlers。 bazel help build --long
是这样说的:
--build_tag_filters (comma-separated list of options; default: "")
Specifies a comma-separated list of tags. Each tag can be optionally
preceded with '-' to specify excluded tags. Only those targets will be
built that contain at least one included tag and do not contain any
excluded tags. This option does not affect the set of tests executed with
the 'test' command; those are be governed by the test filtering options,
for example '--test_tag_filters'
假设这是您的 BUILD 文件:
cc_library(
name = "target1",
hdrs = [...],
srcs = [...],
)
cc_library(
name = "target2",
hdrs = [...],
srcs = [...],
tags = [
"optional"
],
)
cc_library(
name = "target3",
hdrs = [...],
srcs = [...],
tags = [
"optional"
],
)
您可以通过在标签名称前添加 -
来排除带有可选标签的所有目标。
bazel build ... --build_tag_filters=-optional
如果您希望这是项目的默认行为,您可以将其添加到您的 .bazelrc
。
build --build_tag_filters=-optional
编辑:
有几个标签具有特殊含义。一个标签是 manual。默认情况下,它会执行我上面描述的操作,但由于 common definitions documentation 仅提及测试目标,因此它可能是一个错误或未记录。
manual keyword will force the test target to not be included in target pattern wildcards (...
, :*
, :all
, etc); the test target will be neither built nor run. It will also be ignored by the test_suite
rules that do not mention this test explicitly. The only way to build or run such a test is to specify it via an explicit target pattern on the command line.
我有一些目标,我不想在默认情况下执行 bazel build ...
时包括在内。我怎样才能以这样的方式标记它们,除非通过`bazel build //a/b/c:foo?
您可以为每个可选目标添加一个标签,并使用 --build_tag_fitlers。 bazel help build --long
是这样说的:
--build_tag_filters (comma-separated list of options; default: "")
Specifies a comma-separated list of tags. Each tag can be optionally preceded with '-' to specify excluded tags. Only those targets will be built that contain at least one included tag and do not contain any excluded tags. This option does not affect the set of tests executed with the 'test' command; those are be governed by the test filtering options, for example '--test_tag_filters'
假设这是您的 BUILD 文件:
cc_library(
name = "target1",
hdrs = [...],
srcs = [...],
)
cc_library(
name = "target2",
hdrs = [...],
srcs = [...],
tags = [
"optional"
],
)
cc_library(
name = "target3",
hdrs = [...],
srcs = [...],
tags = [
"optional"
],
)
您可以通过在标签名称前添加 -
来排除带有可选标签的所有目标。
bazel build ... --build_tag_filters=-optional
如果您希望这是项目的默认行为,您可以将其添加到您的 .bazelrc
。
build --build_tag_filters=-optional
编辑:
有几个标签具有特殊含义。一个标签是 manual。默认情况下,它会执行我上面描述的操作,但由于 common definitions documentation 仅提及测试目标,因此它可能是一个错误或未记录。
manual keyword will force the test target to not be included in target pattern wildcards (
...
,:*
,:all
, etc); the test target will be neither built nor run. It will also be ignored by thetest_suite
rules that do not mention this test explicitly. The only way to build or run such a test is to specify it via an explicit target pattern on the command line.