aboutsummaryrefslogtreecommitdiffhomepage
path: root/site/docs/skylark
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-04-11 11:19:19 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-11 11:20:27 -0700
commita2e5ae96d710fa2db363f1b29ab5a7b8425520f1 (patch)
treebfaacbc833f13c1d01a910a9911aba2e0fcb66ce /site/docs/skylark
parent4baafaca73cee2d3237999048acfc0d5f5f59a5b (diff)
Update ctx.action.args() docs.
RELNOTES: None PiperOrigin-RevId: 192479130
Diffstat (limited to 'site/docs/skylark')
-rw-r--r--site/docs/skylark/performance.md15
1 files changed, 9 insertions, 6 deletions
diff --git a/site/docs/skylark/performance.md b/site/docs/skylark/performance.md
index 9b77a01433..80937affe1 100644
--- a/site/docs/skylark/performance.md
+++ b/site/docs/skylark/performance.md
@@ -100,12 +100,12 @@ def _impl(ctx):
# Bad, has to iterate over entire depset to get length
if len(files) == 0:
args.add("--files")
- args.add(files)
+ args.add_all(files)
# Good, O(1)
if files:
args.add("--files")
- args.add(files)
+ args.add_all(files)
```
## Use `ctx.actions.args()` for command lines
@@ -154,15 +154,18 @@ def _impl(ctx):
args.add("--foo")
args.add(file)
+ # Use format if you prefer ["--foo=<file path>"] to ["--foo", <file path>]
+ args.add(format="--foo=%s", value=file)
+
# Bad, makes a giant string of a whole depset
args.add(" ".join(["-I%s" % file.short_path for file in files])
# Good, only stores a reference to the depset
- args.add(files, format="-I%s", map_fn=_to_short_path)
+ args.add_all(files, format_each="-I%s", map_each=_to_short_path)
-# Function passed to map_fn above
-def _to_short_path(files):
- return [file.short_path for file in files]
+# Function passed to map_each above
+def _to_short_path(f):
+ return f.short_path
```
## Transitive action inputs should be depsets