Skip to content

Commit e071f45

Browse files
authored
Fix docs for sh_test and sh_binary (#40)
These rules incorrectly shared rule and attr-level docs. Work towards bazelbuild/bazel#24473
1 parent 94c1e66 commit e071f45

3 files changed

Lines changed: 49 additions & 27 deletions

File tree

shell/private/sh_binary.bzl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,27 @@ load(":sh_executable.bzl", "make_sh_executable_rule")
1919
# For doc generation only.
2020
visibility("public")
2121

22-
sh_binary = make_sh_executable_rule(executable = True)
22+
sh_binary = make_sh_executable_rule(
23+
doc = """
24+
<p>
25+
The <code>sh_binary</code> rule is used to declare executable shell scripts.
26+
(<code>sh_binary</code> is a misnomer: its outputs aren't necessarily binaries.) This rule ensures
27+
that all dependencies are built, and appear in the <code>runfiles</code> area at execution time.
28+
We recommend that you name your <code>sh_binary()</code> rules after the name of the script minus
29+
the extension (e.g. <code>.sh</code>); the rule name and the file name must be distinct.
30+
<code>sh_binary</code> respects shebangs, so any available interpreter may be used (eg.
31+
<code>#!/bin/zsh</code>)
32+
</p>
33+
<h4 id="sh_binary_examples">Example</h4>
34+
<p>For a simple shell script with no dependencies and some data files:
35+
</p>
36+
<pre class="code">
37+
sh_binary(
38+
name = "foo",
39+
srcs = ["foo.sh"],
40+
data = glob(["datafiles/*.txt"]),
41+
)
42+
</pre>
43+
""",
44+
executable = True,
45+
)

shell/private/sh_executable.bzl

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -169,39 +169,20 @@ def _launcher_for_windows(ctx, primary_output, main_file):
169169

170170
return _create_windows_exe_launcher(ctx, sh_toolchain, primary_output)
171171

172-
def make_sh_executable_rule(extra_attrs = {}, **kwargs):
172+
def make_sh_executable_rule(doc, extra_attrs = {}, **kwargs):
173173
return rule(
174174
_sh_executable_impl,
175-
doc = """
176-
<p>
177-
The <code>sh_binary</code> rule is used to declare executable shell scripts.
178-
(<code>sh_binary</code> is a misnomer: its outputs aren't necessarily binaries.) This rule ensures
179-
that all dependencies are built, and appear in the <code>runfiles</code> area at execution time.
180-
We recommend that you name your <code>sh_binary()</code> rules after the name of the script minus
181-
the extension (e.g. <code>.sh</code>); the rule name and the file name must be distinct.
182-
<code>sh_binary</code> respects shebangs, so any available interpreter may be used (eg.
183-
<code>#!/bin/zsh</code>)
184-
</p>
185-
<h4 id="sh_binary_examples">Example</h4>
186-
<p>For a simple shell script with no dependencies and some data files:
187-
</p>
188-
<pre class="code">
189-
sh_binary(
190-
name = "foo",
191-
srcs = ["foo.sh"],
192-
data = glob(["datafiles/*.txt"]),
193-
)
194-
</pre>
195-
""",
175+
doc = doc,
196176
attrs = {
197177
"srcs": attr.label_list(
198178
allow_files = True,
199179
doc = """
200-
The list of input files.
180+
The file containing the shell script.
201181
<p>
202-
This attribute should be used to list shell script source files that belong to
203-
this library. Scripts can load other scripts using the shell's <code>source</code>
204-
or <code>.</code> command.
182+
This attribute must be a singleton list, whose element is the shell script.
183+
This script must be executable, and may be a source file or a generated file.
184+
All other files required at runtime (whether scripts or data) belong in the
185+
<code>data</code> attribute.
205186
</p>
206187
""",
207188
),

shell/private/sh_test.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ load(":sh_executable.bzl", "make_sh_executable_rule")
2020
visibility("public")
2121

2222
sh_test = make_sh_executable_rule(
23+
doc = """
24+
<p>A <code>sh_test()</code> rule creates a test written as a Bourne shell script.</p>
25+
26+
<p>See the <a href="${link common-definitions#common-attributes-tests}">
27+
attributes common to all test rules (*_test)</a>.</p>
28+
29+
<h4 id="sh_test_examples">Examples</h4>
30+
31+
<pre class="code">
32+
sh_test(
33+
name = "foo_integration_test",
34+
size = "small",
35+
srcs = ["foo_integration_test.sh"],
36+
deps = [":foo_sh_lib"],
37+
data = glob(["testdata/*.txt"]),
38+
)
39+
</pre>
40+
""",
2341
test = True,
2442
fragments = ["coverage"],
2543
extra_attrs = {

0 commit comments

Comments
 (0)