aboutsummaryrefslogtreecommitdiffhomepage
path: root/site
diff options
context:
space:
mode:
authorGravatar laurentlb <laurentlb@google.com>2017-05-03 16:03:22 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-05-03 17:26:35 +0200
commitf13ce1517e5d6765f4e9a08fdaa0c74b89a36190 (patch)
tree00b9ec0208af3023557dba0e7db0b75a7bd0686d /site
parent474246b8318c77b3afdef4786b2bc17dd83d1ec1 (diff)
Clarification on the cookbook example "cc_and_something_else_binary"
Reorder definitions, based on user feedback. Add some comments. RELNOTES: None. PiperOrigin-RevId: 154951404
Diffstat (limited to 'site')
-rw-r--r--site/versions/master/docs/skylark/cookbook.md23
1 files changed, 13 insertions, 10 deletions
diff --git a/site/versions/master/docs/skylark/cookbook.md b/site/versions/master/docs/skylark/cookbook.md
index b71ce51c78..7793fe13d6 100644
--- a/site/versions/master/docs/skylark/cookbook.md
+++ b/site/versions/master/docs/skylark/cookbook.md
@@ -69,6 +69,19 @@ There's currently no easy way to create a rule that directly uses the
action of a native rule. You can work around this using macros:
```python
+def _impl(ctx):
+ return struct([...],
+ # When instrumenting this rule, again hide implementation from
+ # users.
+ instrumented_files(
+ source_attributes = ["srcs", "csrcs"],
+ dependency_attributes = ["deps", "cdeps"]))
+
+# This rule is private and can only be accessed from the current file.
+_cc_and_something_else_binary = rule(implementation=_impl)
+
+
+# This macro is public, it's the public interface to instantiate the rule.
def cc_and_something_else_binary(name, srcs, deps, csrcs, cdeps):
cc_binary_name = "%s.cc_binary" % name
@@ -90,16 +103,6 @@ def cc_and_something_else_binary(name, srcs, deps, csrcs, cdeps):
# were an actual rule instead of a macro.
csrcs = csrcs,
cdeps = cdeps)
-
-def _impl(ctx):
- return struct([...],
- # When instrumenting this rule, again hide implementation from
- # users.
- instrumented_files(
- source_attributes = ["srcs", "csrcs"],
- dependency_attributes = ["deps", "cdeps"]))
-
-_cc_and_something_else_binary = rule(implementation=_impl)
```