Skip to content

Commit dac0d40

Browse files
Googlercopybara-github
Googler
authored andcommitted
Improve "Common Attributes" section
Creates a separate section for attributes which are added to most build rules, but not implicitly added to Starlark rules. deps, data, and licenses are moved to that section. srcs is also added to the new section, since I think that's as notable a naming convention to highlight as "deps" and "data". The section on "deps" is updated to note: * That "deps" generally should contain only specific rules and not files * How "deps" generally varies between language specific rules * The general relationship between "srcs" and "deps". Also, a bit that says "deps" are always included in runfiles is removed. That's not even usually true. Though it may be true in some cases that source code is needed at runtime and therefore should be included in runfiles (this could be the case for build rules for some interpreted languages, for example), often source code is not needed at runtime and shouldn't be included in runfiles. The section on "data" is updated to note: * That generally "data" permits arbitrary dependencies * That default outputs and runfiles from targets in data should be included in the runfiles of consumers * The general relationship between "data" and "srcs" * What Starlark rules need to do to handle data in their implementation functions The remainder of the section is updated to: * Consistently use "target" instead of "rule" to refer to rule targets. "Rule target" is unnecessary, file targets don't have attributes * Use a consistent format the type of the attribute * Consistently omit that optional list or dictionary attributes default to empty lists or dictionaries * Use False instead of 0 for the default values of attributes whose type is "boolean" And did a bit of copyediting. A line from the introduction to the "common attributes" section that mentions it's an error to list the same label twice in a label-list attribute is pruned. That's true, but it seems misplaced here, it's not very related to the rest of this section. "applicable_licenses" and "transitive_configs" are not yet documented. RELNOTES: None. PiperOrigin-RevId: 351577116
1 parent 082d987 commit dac0d40

32 files changed

+179
-134
lines changed

src/main/java/com/google/devtools/build/docgen/BuildDocCollector.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ private void processAttributeDocs(Iterable<RuleDocumentation> ruleDocEntries,
246246
ruleDoc.addAttribute(PredefinedAttributes.TEST_ATTRIBUTES.get(attrName));
247247
} else if (PredefinedAttributes.COMMON_ATTRIBUTES.containsKey(attrName)) {
248248
ruleDoc.addAttribute(PredefinedAttributes.COMMON_ATTRIBUTES.get(attrName));
249+
} else if (PredefinedAttributes.TYPICAL_ATTRIBUTES.containsKey(attrName)) {
250+
ruleDoc.addAttribute(PredefinedAttributes.TYPICAL_ATTRIBUTES.get(attrName));
249251
}
250252
}
251253
}

src/main/java/com/google/devtools/build/docgen/DocgenConsts.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public class DocgenConsts {
6262

6363
public static final String VAR_SECTION_STARLARK_BUILTIN = "SECTION_BUILTIN";
6464

65+
public static final String TYPICAL_ATTRIBUTES = "typical";
6566
public static final String COMMON_ATTRIBUTES = "common";
6667
public static final String TEST_ATTRIBUTES = "test";
6768
public static final String BINARY_ATTRIBUTES = "binary";

src/main/java/com/google/devtools/build/docgen/MultiPageBuildEncyclopediaProcessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ private void writeCommonDefinitionsPage(String outputDir, RuleLinkExpander expan
6868
throws IOException {
6969
Page page = TemplateEngine.newPage(DocgenConsts.COMMON_DEFINITIONS_TEMPLATE);
7070
page.add("expander", expander);
71+
page.add(
72+
"typicalAttributes",
73+
expandCommonAttributes(PredefinedAttributes.TYPICAL_ATTRIBUTES, expander));
7174
page.add("commonAttributes",
7275
expandCommonAttributes(PredefinedAttributes.COMMON_ATTRIBUTES, expander));
7376
page.add("testAttributes",

src/main/java/com/google/devtools/build/docgen/PredefinedAttributes.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,29 @@ public class PredefinedAttributes {
4242
"templates/attributes/test/local.html");
4343

4444
/**
45-
* List of common attributes documentation, relative to {@link com.google.devtools.build.docgen}.
45+
* List of typical (defined by most rules, but not implicitly added to all rules) attributes
46+
* documentation, relative to {@link com.google.devtools.build.docgen}.
4647
*/
48+
public static final ImmutableList<String> TYPICAL_ATTRIBUTES_DOCFILES =
49+
ImmutableList.of(
50+
"templates/attributes/typical/data.html",
51+
"templates/attributes/typical/deps.html",
52+
"templates/attributes/typical/licenses.html",
53+
"templates/attributes/typical/srcs.html");
54+
55+
/**
56+
* List of common (implicitly added to all rules) attributes documentation, relative to {@link
57+
* com.google.devtools.build.docgen}.
58+
*/
59+
// TODO(b/177233238): This should also document applicable_licenses and transitive_configs.
4760
public static final ImmutableList<String> COMMON_ATTRIBUTES_DOCFILES =
4861
ImmutableList.of(
4962
"templates/attributes/common/compatible_with.html",
50-
"templates/attributes/common/data.html",
5163
"templates/attributes/common/deprecation.html",
52-
"templates/attributes/common/deps.html",
5364
"templates/attributes/common/distribs.html",
5465
"templates/attributes/common/exec_compatible_with.html",
5566
"templates/attributes/common/exec_properties.html",
5667
"templates/attributes/common/features.html",
57-
"templates/attributes/common/licenses.html",
5868
"templates/attributes/common/restricted_to.html",
5969
"templates/attributes/common/tags.html",
6070
"templates/attributes/common/target_compatible_with.html",
@@ -74,8 +84,7 @@ public class PredefinedAttributes {
7484

7585
private static ImmutableMap<String, RuleDocumentationAttribute> generateAttributeMap(
7686
String commonType, ImmutableList<String> filenames) {
77-
ImmutableMap.Builder<String, RuleDocumentationAttribute> builder =
78-
ImmutableMap.<String, RuleDocumentationAttribute>builder();
87+
ImmutableMap.Builder<String, RuleDocumentationAttribute> builder = ImmutableMap.builder();
7988
for (String filename : filenames) {
8089
String name = Files.getNameWithoutExtension(filename);
8190
try {
@@ -92,6 +101,9 @@ private static ImmutableMap<String, RuleDocumentationAttribute> generateAttribut
92101
return builder.build();
93102
}
94103

104+
public static final ImmutableMap<String, RuleDocumentationAttribute> TYPICAL_ATTRIBUTES =
105+
generateAttributeMap(DocgenConsts.TYPICAL_ATTRIBUTES, TYPICAL_ATTRIBUTES_DOCFILES);
106+
95107
public static final ImmutableMap<String, RuleDocumentationAttribute> COMMON_ATTRIBUTES =
96108
generateAttributeMap(DocgenConsts.COMMON_ATTRIBUTES, COMMON_ATTRIBUTES_DOCFILES);
97109

src/main/java/com/google/devtools/build/docgen/SinglePageBuildEncyclopediaProcessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public void generateDocumentation(List<String> inputDirs, String outputDir, Stri
5454
page.add("expander", expander);
5555

5656
// Populate variables for Common Definitions section.
57+
page.add(
58+
"typicalAttributes",
59+
expandCommonAttributes(PredefinedAttributes.TYPICAL_ATTRIBUTES, expander));
5760
page.add("commonAttributes",
5861
expandCommonAttributes(PredefinedAttributes.COMMON_ATTRIBUTES, expander));
5962
page.add("testAttributes",

src/main/java/com/google/devtools/build/docgen/templates/attributes/binary/args.html

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,14 @@
77
</p>
88

99
<p>
10-
Command line arguments that bazel will pass to the target when it is executed
10+
Command line arguments that Bazel will passes to the target when it is executed
1111
either by the <code>run</code> command or as a test. These arguments are
1212
passed before the ones that are specified on the <code>bazel run</code> or
1313
<code>bazel test</code> command line.
1414
</p>
1515

1616
<p>
1717
<em class="harmful">NOTE: The arguments are not passed when you run the target
18-
outside of bazel (for example, by manually executing the binary in
18+
outside of Bazel (for example, by manually executing the binary in
1919
<code>bazel-bin/</code>).</em>
2020
</p>
21-
22-
<p>
23-
Most binary rules permit an <code>args</code> attribute, but where
24-
this attribute is not allowed, this fact is documented under the
25-
specific rule.
26-
</p>

src/main/java/com/google/devtools/build/docgen/templates/attributes/binary/env.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313

1414
<p>
1515
<em class="harmful">NOTE: The environment variables are not set when you run the target
16-
outside of bazel (for example, by manually executing the binary in
16+
outside of Bazel (for example, by manually executing the binary in
1717
<code>bazel-bin/</code>).</em>
1818
</p>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
<p><code>List of <a href="../build-ref.html#labels">labels</a>; optional; <a href="#configurable-attributes">nonconfigurable</a></code></p>
1+
<p><code>List of <a href="../build-ref.html#labels">labels</a>; optional;
2+
<a href="#configurable-attributes">nonconfigurable</a></code></p>
23

34
<p>
4-
The list of environments this rule can be built for, in addition to
5+
The list of environments this target can be built for, in addition to
56
default-supported environments.
67
</p>
78

89
<p>
9-
This is part of Bazel's soft-launched constraint system, which lets users
10-
declare which rules can and cannot depend on each other. For example,
11-
externally deployable binaries shouldn't depend on libraries with
12-
company-secret code. See
10+
This is part of Bazel's constraint system, which lets users declare which
11+
targets can and cannot depend on each other. For example, externally deployable
12+
binaries shouldn't depend on libraries with company-secret code. See
1313
<a href="https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java#L46">
1414
ConstraintSemantics</a> for details.
1515
</p>

src/main/java/com/google/devtools/build/docgen/templates/attributes/common/data.html

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main/java/com/google/devtools/build/docgen/templates/attributes/common/deprecation.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p><code>String; optional; <a href="#configurable-attributes">nonconfigurable</a></code></p>
22

33
<p>
4-
An explanatory warning message associated with this rule.
5-
Typically this is used to notify users that a rule has become obsolete,
4+
An explanatory warning message associated with this target.
5+
Typically this is used to notify users that a target has become obsolete,
66
or has become superseded by another rule, is private to a package, or is
77
perhaps considered harmful for some reason. It is a good idea to include
88
some reference (like a webpage, a bug number or example migration CLs) so
@@ -15,7 +15,7 @@
1515
This attribute has no effect on the way things are built, but it
1616
may affect a build tool's diagnostic output. The build tool issues a
1717
warning when a rule with a <code>deprecation</code> attribute is
18-
depended upon by another rule.
18+
depended upon by a target in another package.
1919
</p>
2020

2121
<p>
@@ -25,10 +25,10 @@
2525
</p>
2626

2727
<p>
28-
If a deprecated rule depends on another deprecated rule, no warning
28+
If a deprecated target depends on another deprecated target, no warning
2929
message is issued.
3030
</p>
3131

3232
<p>
33-
Once people have stopped using it, the package can be removed.
33+
Once people have stopped using it, the target can be removed.
3434
</p>

src/main/java/com/google/devtools/build/docgen/templates/attributes/common/deps.html

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/main/java/com/google/devtools/build/docgen/templates/attributes/common/distribs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<p><code>List of strings; optional; <a href="#configurable-attributes">nonconfigurable</a></code></p>
22

33
<p>
4-
A list of distribution-method strings to be used for this particular build rule.
4+
A list of distribution-method strings to be used for this particular target.
55

66
This is part of a deprecated licensing API that Bazel no longer uses. Don't
77
use this.
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
<p><code>List of <a href="../build-ref.html#labels">labels</a>; optional; <a href="#configurable-attributes">nonconfigurable</a></code></p>
1+
<p>
2+
<code>List of <a href="../build-ref.html#labels">labels</a>; optional;
3+
<a href="#configurable-attributes">nonconfigurable</a></code>
4+
</p>
25

36
<p>
47
A list of
58
<code><a href="platform.html#constraint_value">constraint_values</a></code>
69
that must be present in the execution platform for this target. This is in
710
addition to any constraints already set by the rule type. Constraints are used
8-
to restrict the list of available execution platforms, see the description of
9-
<a href="../toolchains.html#toolchain-resolution">toolchain resolution</a>
10-
for details.
11-
</p>
11+
to restrict the list of available execution platforms. For more details, see
12+
the description of
13+
<a href="../toolchains.html#toolchain-resolution">toolchain resolution</a>.
14+
</p>

src/main/java/com/google/devtools/build/docgen/templates/attributes/common/exec_properties.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<p><code>Dictionary of strings. Default is an empty dictionary.</code></p>
1+
<p><code>Dictionary of strings; optional</code></p>
22

33
<p> A dictionary of strings that will be added to the <code>exec_properties</code> of a platform selected for this target. See <code>exec_properties</code> of the <a href="platform.html">platform</a> rule.</p>
44

src/main/java/com/google/devtools/build/docgen/templates/attributes/common/features.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<p><code>List of <i>features</i>. Default is the empty list.</code></p>
1+
<p><code>List of <i>feature</i> strings; optional</code></p>
22

33
<p>A feature is string tag that can be enabled or disabled on a target. The
44
meaning of a feature depends on the rule itself.</p>
55

66
<p>This <code>features</code> attribute is combined with the <a href="${link
77
package}">package</a> level <code>features</code> attribute. For example, if
8-
the features ["a", "b"] are enabled on the package level, and a rule
8+
the features ["a", "b"] are enabled on the package level, and a target's
99
<code>features</code> attribute contains ["-a", "c"], the features enabled for the
1010
rule will be "b" and "c".
1111
<a href="https://github.com/bazelbuild/examples/blob/master/rules/features/BUILD">
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
<p><code>List of <a href="../build-ref.html#labels">labels</a>; optional; <a href="#configurable-attributes">nonconfigurable</a></code></p>
1+
<p><code>List of <a href="../build-ref.html#labels">labels</a>; optional;
2+
<a href="#configurable-attributes">nonconfigurable</a></code></p>
23

34
<p>
4-
The list of environments this rule can be built for, <i>instead</i> of
5+
The list of environments this target can be built for, <i>instead</i> of
56
default-supported environments.
67
</p>
78

89
<p>
9-
This is part of Bazel's soft-launched constraint system. See
10+
This is part of Bazel's constraint system. See
1011
<code><a href="#common.compatible_with">compatible_with</a></code>
1112
for details.
1213
</p>

src/main/java/com/google/devtools/build/docgen/templates/attributes/common/tags.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<p>
2-
<code>List of arbitrary text tags. Tags may be any valid string; default is
3-
the empty list; <a href="#configurable-attributes">nonconfigurable</a></code>
2+
<code>List of strings; optional; <a href="#configurable-attributes">nonconfigurable</a></code>
43
</p>
54

65
<p>
76
<i>Tags</i> can be used on any rule. <i>Tags</i> on test and
87
<code>test_suite</code> rules are useful for categorizing the tests.
9-
<i>Tags</i> on non-test rules are used to control sandboxed execution of
8+
<i>Tags</i> on non-test targets are used to control sandboxed execution of
109
<code>genrule</code>s and
1110

1211
<a href="/versions/{{ site.version }}/skylark/index.html">Starlark</a>
@@ -15,9 +14,9 @@
1514

1615
<p>
1716
Bazel modifies the behavior of its sandboxing code if it finds the following
18-
keywords in the <code>tags</code> attribute of any test rule or
19-
<code>genrule</code>, or the keys of <code>execution_requirements</code> for
20-
any Starlark action.
17+
keywords in the <code>tags</code> attribute of any test or <code>genrule</code>
18+
target, or the keys of <code>execution_requirements</code> for any Starlark
19+
action.
2120
</p>
2221

2322
<ul>
@@ -111,4 +110,4 @@
111110
</ul>
112111

113112
See <a href="../test-encyclopedia.html#tag-conventions">Tag Conventions</a> in the
114-
Test Encyclopedia for more conventions on tags attached to test rules.
113+
Test Encyclopedia for more conventions on tags attached to test targets.

src/main/java/com/google/devtools/build/docgen/templates/attributes/common/target_compatible_with.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<p>
2-
<code>List of <a href="../build-ref.html#labels">labels</a>; optional; default
3-
is the empty list</code>
2+
<code>List of <a href="../build-ref.html#labels">labels</a>; optional</code>
43
</p>
54

65
<p>
76
A list of
87
<code><a href="platform.html#constraint_value">constraint_value</a></code>s
98
that must be present in the target platform for this target to be considered
10-
"compatible". This is in addition to any constraints already set by the rule
11-
type. If the target platform does not satisfy all listed constraints then the
12-
target is considered "incompatible". Incompatible targets are skipped for
13-
building and testing when the target pattern is expanded
9+
<em>compatible</em>. This is in addition to any constraints already set by the
10+
rule type. If the target platform does not satisfy all listed constraints then
11+
the target is considered <em>incompatible</em>. Incompatible targets are
12+
skipped for building and testing when the target pattern is expanded
1413
(e.g. `//...`, `:all`). When explicitly specified on the command line,
1514
incompatible targets cause Bazel to print an error and cause a build or test
1615
failure.

src/main/java/com/google/devtools/build/docgen/templates/attributes/common/testonly.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<p><code>Boolean; optional; default False except as noted; <a href="#configurable-attributes">nonconfigurable</a></code></p>
1+
<p><code>Boolean; optional; default False except for test and test suite targets;
2+
<a href="#configurable-attributes">nonconfigurable</a></code></p>
23

34
<p>
45
If True, only testonly targets (such as tests) can depend on this target.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<p><code>List of <a href="../build-ref.html#labels">labels</a>; optional; <a href="#configurable-attributes">nonconfigurable</a></code></p>
22

33
<p>
4-
The set of targets whose <a href="${link make-variables}">Make variables</a> the rule is allowed
5-
to access. These rules are either rules that provide
6-
the <code>TemplateVariableInfo</code> provider or special targets for toolchain types built into
7-
Bazel.
8-
These include:
4+
The set of targets whose <a href="${link make-variables}">Make variables</a> this target is
5+
allowed to access. These targets are either instances of rules that provide
6+
<code>TemplateVariableInfo</code> or special targets for toolchain types built into Bazel. These
7+
include:
98

109
<ul>
1110
<li><code>@bazel_tools//tools/cpp:current_cc_toolchain</code>
@@ -16,5 +15,6 @@
1615
Note that this is distinct from the concept of
1716
<a href="../toolchains.html#toolchain-resolution">toolchain resolution</a>
1817
that is used by rule implementations for platform-dependent configuration. You cannot use this
19-
attribute to determine which specific cc_toolchain or java_toolchain a target will use.
18+
attribute to determine which specific <code>cc_toolchain</code> or <code>java_toolchain</code> a
19+
target will use.
2020
</p>

src/main/java/com/google/devtools/build/docgen/templates/attributes/common/visibility.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
otherwise; <a href="#configurable-attributes">nonconfigurable</a></code></p>
55

66
<p>
7-
The <code>visibility</code> attribute on a rule controls whether the rule can
8-
be used by other packages. See the documentation for <a href="../visibility.md">visibility</a>.
7+
The <code>visibility</code> attribute on a target controls whether the target
8+
can be used in other packages. See the documentation for
9+
<a href="../visibility.md">visibility</a>.
910
</p>

0 commit comments

Comments
 (0)