里面的一些规则简单了解一下:
BUILD的一般规则:
Attribute
Description | |
---|---|
features |
Features on a rule modify the features currently enabled on thepackage level via the features attribute. |
licenses |
A list of license-type strings to be used for this particular build rule.Overrides the |
data |
The list of files needed by this rule at runtime. Targets named in the Almost all rules permit a |
visibility |
The There are five forms (and one temporary form) a visibility label can take:
The visibility specifications of If a rule does not specify the visibility attribute,the If the default visibility for the package is not specified,the rule is private. Example: File # This rule is visible to everyone cc_binary( name = "executable", visibility = ["//visibility:public"], deps = [":library"], ) # This rule is visible only to rules declared in the same package cc_library( name = "library", visibility = ["//visibility:private"], ) # This rule is visible to rules in package //object and //noun cc_library( name = "subject", visibility = [ "//noun:__pkg__", "//object:__pkg__", ], ) # See package group "//frobber:friends" (below) for who can # access this rule. cc_library( name = thingy, visibility = ["//frobber:friends"], ) File # This is the package group declaration to which rule # //frobber/bin:thingy refers. # # Our friends are packages //frobber, //fribber and any # subpackage of //fribber. package_group( name = "friends", packages = [ "//fribber/...", "//frobber", ], ) |
compatible_with |
The list of environments this rule can be built for, in addition todefault-supported environments. This is part of Bazel's soft-launched constraint system, which lets usersdeclare which rules can and cannot depend on each other. For example,externally deployable binaries shouldn't depend on libraries withcompany-secret code. SeeConstraintSemantics for details. |
distribs |
A list of distribution-method strings to be used for this particular build rule.Overrides the |
deps |
A list of dependencies of this rule. The precise semantics of what it means for this rule to depend onanother using Most often, a Almost all rules permit a |
deprecation |
An explanatory warning message associated with this rule.Typically this is used to notify users that a rule has become obsolete,or has become superseded by another rule, is private to a package, or isperhaps considered harmful for some reason. It is a good idea to includesome reference (like a webpage, a bug number or example migration CLs) sothat one can easily find out what changes are required to avoid the message.If there is a new target that can be used as a drop in replacement, it is agood idea to just migrate all users of the old target. This attribute has no effect on the way things are built, but itmay affect a build tool's diagnostic output. The build tool issues awarning when a rule with a Intra-package dependencies are exempt from this warning, so that,for example, building the tests of a deprecated rule does notencounter a warning. If a deprecated rule depends on another deprecated rule, no warningmessage is issued. Once people have stopped using it, the package can be removed. |
restricted_to |
The list of environments this rule can be built for, instead ofdefault-supported environments. This is part of Bazel's soft-launched constraint system. See |
tags |
Tags can be used on any rule. Tags on test and Bazel modifies the behavior of its sandboxing code if it finds the following keywords in the
Tags on tests are generally used to annotate a test's role in your debug and release process. Typically, tags are most useful for C++ and Python tests, which lack any runtime annotation ability. The use of tags and size elements gives flexibility in assembling suites of tests based around codebase check-in policy. Bazel modifies test running behavior if it finds the following keywords in the
|
testonly |
If 1, only testonly targets (such as tests) can depend on this target. Equivalently, a rule that is not Tests ( This attribute is intended to mean that the target should not becontained in binaries that are released to production. Because testonly is enforced at build time, not run time, and propagatesvirally through the dependency tree, it should be applied judiciously. Forexample, stubs and fakes thatare useful for unit tests may also be useful for integration testsinvolving the same binaries that will be released to production, andtherefore should probably not be marked testonly. Conversely, rules thatare dangerous to even link in, perhaps because they unconditionallyoverride normal behavior, should definitely be marked testonly. |
visibility是一个重要参数。
有几个函数:
例如:
1、load("//tools/build_rules:build_test.bzl", "build_test")
build_test(name = ...)
2、package(default_deprecation, default_testonly, default_visibility, features)
package(default_visibility = ["//foo:target"])
3、package_group(name, packages, includes)
package_group(
name = "tropical",
packages = [
"//fruits/mango",
"//fruits/orange",
"//fruits/papaya/...",
],
)
The following declarations specify the package groups of a fictionalapplication:
package_group(
name = "fooapp",
includes = [
":controller",
":model",
":view",
],
)
package_group(
name = "model",
packages = ["//fooapp/database"],
)
package_group(
name = "view",
packages = [
"//fooapp/swingui",
"//fooapp/webui",
],
)
package_group(
name = "controller",
packages = ["//fooapp/algorithm"],
)
4、licenses(license_types)-
restricted
- Requires mandatory source distribution. reciprocal
- Allows usage of software freely inunmodified form. Any modifications must be made freely available. notice
- Original or modified third-party software may beshipped without danger nor encumbering other sources. All of the licenses in thiscategory do, however, have an \"original Copyright notice\" or\"advertising clause\", wherein any external distributions must include the noticeor clause specified in the license. permissive
- Code that is under a license but does notrequire a notice. unencumbered
- Public domain, free for any use.
exports_files(["golden.txt"])
6、glob(include, exclude=[], exclude_directories=1)java_library(
name = "mylib",
srcs = glob(["*.java"]) + [":gen_java_srcs"],
deps = "...",
)
genrule(
name = "gen_java_srcs",
outs = [
"Foo.java",
"Bar.java",
],
...
)
sh_test(
name = "mytest",
srcs = ["mytest.sh"],
data = glob(
["testdata/*.txt"],
exclude = ["testdata/experimental.txt"],
),
)
java_library(
name = "mylib",
srcs = glob(
["**/*.java"],
exclude = ["**/testing/**"],
),
)
sh_test(
name = "mytest",
srcs = ["mytest.sh"],
data = glob(["testdata/**/*.txt"]),
)
# Conveniently, the build language supports list comprehensions.
[genrule(
name = "count_lines_" + f[:-3], # strip ".cc"
srcs = [f],
outs = ["%s-linecount.txt" % f[:-3]],
cmd = "wc -l $< >$@",
) for f in glob(["*_test.cc"])]
$ bazel query '//foo:all' | sort
//foo:count_lines_a_test
//foo:count_lines_b_test
//foo:count_lines_c_test
7、
select(
{conditionA: valuesA, conditionB: valuesB, ...},
no_match_error = "custom message"
)
sh_binary(
name = "myrule",
srcs = select({
":conditionA": ["myrule_a.sh"],
":conditionB": ["myrule_b.sh"],
"//conditions:default": ["myrule_default.sh"]
})
)
config_setting(
name = "windows",
values = {
"crosstool_top": "//crosstools/windows",
},
)
cc_binary(
name = "multiplatform_app",
...
linkopts = select({
":windows": [
"-Wl,windows_support1.lib",
"-Wl,windows_support2.lib",
],
"//conditions:default": [],
...
)
8、workspace(name = "com_example_project")