Skip to content

Commit

Permalink
Add docstrings/comments to the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentlb committed Dec 15, 2017
1 parent 1b1ee8b commit 464d62a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
10 changes: 10 additions & 0 deletions rules/actions_run/execute.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"""Execute a binary.
The example below executes the binary target "//actions_run:merge" with
some arguments. The binary will be automatically built by Bazel.
The rule must declare its dependencies. To do that, we pass the target to
the attribute "_merge_tool". Since it starts with an underscore, it is private
and users cannot redefine it.
"""

def _impl(ctx):
# The list of arguments we pass to the script.
args = [ctx.outputs.out.path] + [f.path for f in ctx.files.chunks]
Expand Down
7 changes: 7 additions & 0 deletions rules/actions_write/file.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""Generate a file.
In this example, the content is passed via an attribute. If you generate
large files with a lot of static content, consider using
`ctx.actions.expand_template` instead.
"""

def _impl(ctx):
output = ctx.outputs.out
ctx.actions.write(output=output, content=ctx.attr.content)
Expand Down
3 changes: 1 addition & 2 deletions rules/depsets/foo.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# A provider with one field, transitive_sources.
FooFiles = provider()
FooFiles = provider("transitive_sources")

def get_transitive_srcs(srcs, deps):
"""Obtain the source files for a target and its transitive dependencies.
Expand Down
6 changes: 6 additions & 0 deletions rules/expand_template/hello.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""Generate a file using a template.
It is much more memory-efficient to use a template file than creating the whole
content during the analysis phase.
"""

# Label of the template file to use.
_TEMPLATE = "//expand_template:hello.cc"

Expand Down
10 changes: 9 additions & 1 deletion rules/shell_command/size.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""Execute a shell command.
While convenient, Shell commands should be used carefully. Generating the
command-line can lead to escaping and injection issues. It can also create
portability problems. It is often better to declare a binary target in a
BUILD file and execute it.
"""

def _impl(ctx):
output = ctx.outputs.out
input = ctx.file.file
Expand All @@ -6,7 +14,7 @@ def _impl(ctx):
inputs=[input],
outputs=[output],
progress_message="Getting size of %s" % input.short_path,
command="stat -L -c%%s %s > %s" % (input.path, output.path))
command="stat -L -c%%s '%s' > '%s'" % (input.path, output.path))

size = rule(
implementation=_impl,
Expand Down

0 comments on commit 464d62a

Please sign in to comment.