Skip to content

Commit c104164

Browse files
committed
fix xrefs, docs, expand docs
1 parent 0fdf1b2 commit c104164

File tree

7 files changed

+50
-11
lines changed

7 files changed

+50
-11
lines changed

docs/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ sphinx_stardocs(
100100
"//python:py_test_bzl",
101101
"//python:repositories_bzl",
102102
"//python/api:api_bzl",
103+
"//python/api:executables_bzl",
104+
"//python/api:libraries_bzl",
103105
"//python/cc:py_cc_toolchain_bzl",
104106
"//python/cc:py_cc_toolchain_info_bzl",
105107
"//python/entry_points:py_console_script_binary_bzl",

docs/extending.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,29 @@ for the development of APIs to support custom derived rules.
3131
Custom rules can be created using the core rules as a basis by using their rule
3232
builder APIs.
3333

34-
* {bzl:obj}`//python/apis:executables.bzl%executables` for builders for executables
35-
* {bzl:obj}`//python/apis:libraries.bzl%libraries` for builders for libraries
34+
* [`//python/apis:executables.bzl`](#python-apis-executables-bzl): builders for
35+
executables.
36+
* [`//python/apis:libraries.bzl`](#python-apis-libraries-bzl): builders for
37+
libraries.
3638

3739
These builders create {bzl:obj}`ruleb.Rule` objects, which are thin
3840
wrappers around the keyword arguments eventually passed to the `rule()`
3941
function. These builder APIs give access to the _entire_ rule definition and
4042
allow arbitrary modifications.
4143

42-
### Example: validating a source file
44+
This is level of control is powerful, but also volatile. A rule definition
45+
contains many details that _must_ change as the implementation changes. What
46+
is more or less likely to change isn't known in advance, but some general
47+
rules are:
48+
49+
* Additive behavior to public attributes will be less prone to breaking.
50+
* Internal attributes that directly support a public attribute are likely
51+
reliable.
52+
* Internal attributes that support an action are more likely to change.
53+
* Rule toolchains are moderately stable (toolchains are mostly internal to
54+
how a rule works, but custom toolchains are supported).
55+
56+
## Example: validating a source file
4357

4458
In this example, we derive from `py_library` a custom rule that verifies source
4559
code contains the word "snakes". It does this by:
@@ -95,7 +109,7 @@ def create_has_snakes_rule():
95109
has_snakes_library = create_has_snakes_rule()
96110
```
97111

98-
### Example: adding transitions
112+
## Example: adding transitions
99113

100114
In this example, we derive from `py_binary` to force building for a particular
101115
platform. We do this by:

python/api/BUILD.bazel

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ bzl_library(
2525
deps = ["//python/private/api:api_bzl"],
2626
)
2727

28+
bzl_library(
29+
name = "executables_bzl",
30+
srcs = ["executables.bzl"],
31+
visibility = ["//visibility:public"],
32+
deps = [
33+
"//python/private:py_binary_rule_bzl",
34+
"//python/private:py_executable_bzl",
35+
"//python/private:py_test_rule_bzl",
36+
],
37+
)
38+
39+
bzl_library(
40+
name = "libraries_bzl",
41+
srcs = ["libraries.bzl"],
42+
visibility = ["//visibility:public"],
43+
deps = [
44+
"//python/private:py_library_bzl",
45+
],
46+
)
47+
2848
filegroup(
2949
name = "distribution",
3050
srcs = glob(["**"]),

python/api/executables.bzl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Loading-phase APIs specific to executables (binaries/tests).
15+
"""
16+
{#python-apis-executables-bzl}
17+
Loading-phase APIs specific to executables (binaries/tests).
1618
1719
:::{versionadded} VERSION_NEXT_FEATURE
1820
:::
1921
"""
2022

2123
load("//python/private:py_binary_rule.bzl", "create_py_binary_rule_builder")
2224
load("//python/private:py_executable.bzl", "create_executable_rule_builder")
23-
load("//python/private:py_test_rule.bzl", "create_test_rule_builder")
25+
load("//python/private:py_test_rule.bzl", "create_py_test_rule_builder")
2426

2527
executables = struct(
2628
py_binary_rule_builder = create_py_binary_rule_builder,
27-
py_test_rule_builder = create_test_rule_builder,
29+
py_test_rule_builder = create_py_test_rule_builder,
2830
executable_rule_builder = create_executable_rule_builder,
2931
)

python/api/libraries.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Loading-phase APIs specific to executables (binaries/tests).
15+
"""
16+
{#python-apis-libraries-bzl}
17+
Loading-phase APIs specific to executables (binaries/tests).
1618
1719
:::{versionadded} VERSION_NEXT_FEATURE
1820
:::

python/private/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ bzl_library(
427427
":attributes_bzl",
428428
":common_bzl",
429429
":flags_bzl",
430+
":precompile_bzl",
430431
":py_cc_link_params_info_bzl",
431432
":py_internal_bzl",
432433
":rule_builders_bzl",
@@ -446,8 +447,6 @@ bzl_library(
446447
name = "py_library_rule_bzl",
447448
srcs = ["py_library_rule.bzl"],
448449
deps = [
449-
":common_bzl",
450-
":precompile_bzl",
451450
":py_library_bzl",
452451
],
453452
)

python/private/py_test_rule.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def create_py_test_rule_builder():
4242
4343
Returns:
4444
{type}`ruleb.Rule` with the necessary settings
45-
for creating a `py_binary` rule.
45+
for creating a `py_test` rule.
4646
"""
4747
builder = create_executable_rule_builder(
4848
implementation = _py_test_impl,

0 commit comments

Comments
 (0)