Skip to content

Commit 1f0c5b1

Browse files
Nero5023facebook-github-bot
authored andcommitted
Generate all rules per page
Summary: # This diff stack Separate the rules at https://buck2.build/docs/prelude/globals/ into separate pages. Each page will have it's own page. With such change it will be more clean and it will be faster to open the page. # This diff This diff generate each page for each rule in prelude and change the side bar config. Update the broken link in the next diff Reviewed By: scottcao Differential Revision: D73704334 fbshipit-source-id: 3004207f6aa0a0edde8de7f286a5465172d525e7
1 parent c21d1fa commit 1f0c5b1

File tree

10 files changed

+57
-38
lines changed

10 files changed

+57
-38
lines changed

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ for most purposes it can be considered a subset of Python. There are three main
66
places you can write Starlark in Buck2:
77

88
- In `BUCK` files, where you can define the rules. The most interesting
9-
functions are [the rules themselves](../prelude/globals), but you will often
9+
functions are [the rules themselves](../prelude/rules/), but you will often
1010
use the [builtin Starlark functions](starlark) (most of which are the same as
1111
in Python), and a few of the [build functions](build) (e.g. `glob`).
1212
- In rule definitions, where you can use the same Starlark standard functions,

docs/concepts/build_rule.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ Buck2 comes with a collection of built-in build rules for many common build
1919
procedures. For example:
2020

2121
- Compiling Java code against the Android SDK is a common procedure, so Buck2
22-
provides the [`android_library`](../../prelude/globals#android_library) build
22+
provides the [`android_library`](../../prelude/rules/android_library) build
2323
rule
2424
- The final product of most Android development is an APK, so you can use the
25-
[`android_binary`](../../prelude/globals#android_binary) build rule to create
26-
an APK
25+
[`android_binary`](../../prelude/rules/android_binary) build rule to create an
26+
APK
2727

2828
## Source files as inputs to build rules
2929

3030
Most build rules specify source files as inputs. For example, a
31-
[`cxx_library`](../../prelude/globals#cxx_library) rule would specify `.cpp`
32-
files as inputs.
31+
[`cxx_library`](../../prelude/rules/cxx_library) rule would specify `.cpp` files
32+
as inputs.
3333

3434
To support specifying these files:
3535

@@ -61,13 +61,13 @@ Buck2 enforces these rules regarding source file access:
6161

6262
- The other package explicitly _exports_ those header files
6363
- This is done using the `exported_headers` argument
64-
- See the [`cxx_library`](../../prelude/globals#cxx_library) documentation
65-
for details
64+
- See the [`cxx_library`](../../prelude/rules/cxx_library) documentation for
65+
details
6666

6767
3. **Accessing Functionality**: To use code from other packages:
6868
- Use the artifacts produced by build rules in those packages
6969
- Specify those build rules as _dependencies_
70-
- Example: A [`cxx_binary`](../../prelude/globals/#cxx_binary) can use a
70+
- Example: A [`cxx_binary`](../../prelude/rules/cxx_binary) can use a
7171
`cxx_library` from another package by taking it as a dependency
7272

7373
#### Using Symlinks (Not Recommended)
@@ -99,12 +99,12 @@ Dependencies are specified in several ways:
9999

100100
### Examples:
101101

102-
The output of a [`java_library`](../../prelude/globals/#java_library) rule is a
103-
JAR file. If a `java_library` rule specifies another `java_library` rule as a
102+
The output of a [`java_library`](../../prelude/rules/java_library) rule is a JAR
103+
file. If a `java_library` rule specifies another `java_library` rule as a
104104
dependency, the JAR file produced by the specified rule is added to the
105105
classpath for the `java_library` that depends on it.
106106

107-
If a [`java_binary`](../../prelude/globals/#java_binary) rule specifies a
107+
If a [`java_binary`](../../prelude/rules/java_binary) rule specifies a
108108
`java_library` rule as a dependency, the JAR file for the specified
109109
`java_library` is available on the classpath for the `java_binary`.
110110

@@ -121,7 +121,7 @@ Buck2 guarantees that any dependencies that a rule lists that are required to
121121
build that rule are built successfully _before_ Buck2 builds the rule itself.
122122

123123
Note that there can be special cases—such as
124-
[`apple_bundle`](../../prelude/globals/#apple_bundle)—where a rule's listed
124+
[`apple_bundle`](../../prelude/rules/apple_bundle)—where a rule's listed
125125
dependencies do not actually need to be built before the rule.
126126

127127
### Visibility
@@ -150,11 +150,11 @@ category of generic build rules called _genrules_.
150150
With genrules, you can perform arbitrary operations using shell scripts. The
151151
genrules supported by Buck2 are:
152152

153-
- [`genrule`](../../prelude/globals/#genrule)
154-
- [`apk_genrule`](../../prelude/globals/#apk_genrule)
155-
- [`cxx_genrule`](../../prelude/globals/#cxx_genrule)
156-
- [`jar_genrule`](../../prelude/globals/#jar_genrule)
157-
- [`js_bundle_genrule`](../../prelude/globals/#js_bundle_genrule)
153+
- [`genrule`](../../prelude/rules/genrule)
154+
- [`apk_genrule`](../../prelude/rules/apk_genrule)
155+
- [`cxx_genrule`](../../prelude/rules/cxx_genrule)
156+
- [`jar_genrule`](../../prelude/rules/jar_genrule)
157+
- [`js_bundle_genrule`](../../prelude/rules/js_bundle_genrule)
158158

159159
### Multiple output files with genrules
160160

docs/concepts/key_concepts.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ Buck2 has a number of fundamental concepts:
1212
- A [**_build rule_**](build_rule.md) describes how to produce an output file
1313
from a set of input files. Most build rules are specific to a particular
1414
language or platform. For example, you would use the
15-
[`cxx_binary`](../../prelude/globals/#cxx_binary) rule to create a C++ binary,
16-
but you would use the
17-
[`android_binary`](../../prelude/globals/#android_binary) rule to create an
18-
Android APK.
15+
[`cxx_binary`](../../prelude/rules/cxx_binary) rule to create a C++ binary,
16+
but you would use the [`android_binary`](../../prelude/rules/android_binary)
17+
rule to create an Android APK.
1918
- A [**_build target_**](build_target.md) is a string that uniquely identifies a
2019
build rule. It can be thought of as a URI for the build rule within the Buck2
2120
project.

docs/rule_authors/writing_toolchains.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ instead explicitly downloads and tracks them as part of the build.
134134
Doing is typically as follows:
135135

136136
- Download the tools, e.g. using the
137-
[`http_archive`](../../prelude/globals/#http_archive) rule (see the
137+
[`http_archive`](../../prelude/rules/http_archive) rule (see the
138138
[Zig-based C++ toolchain in the prelude](https://github.com/facebook/buck2/tree/main/prelude/toolchains/cxx/zig)
139139
as an example).
140140
- Expose those tools as [`RunInfo`](../../api/build/RunInfo/) providers in rules

docs/users/cheatsheet.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ $(query_targets_and_outputs [SEPARATOR] "queryfunction(:foo)")
9191
```
9292

9393
Note, however, that the query macros are supported only for rule attributes of
94-
type `attrs.arg`, such as [`genrule`](../../prelude/globals/#genrule) and
95-
[`apk_genrule`](../../prelude/globals/#apk_genrule).
94+
type `attrs.arg`, such as [`genrule`](../../prelude/rules/genrule) and
95+
[`apk_genrule`](../../prelude/rules/apk_genrule).
9696

9797
### How do I find the dependencies for a target?
9898

prelude/docs/rules.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010

1111
load("@prelude//:rules.bzl", _rules = "rules")
1212

13-
load_symbols(_rules)
13+
load_symbols({name: namespace(name = r) for name, r in _rules.items()})

website/config_impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const themeConfig: ClassicPresetConfig = ({
6060
activeBaseRegex: '/docs/api',
6161
},
6262
{
63-
to: '/docs/prelude/globals',
63+
to: '/docs/prelude/rules',
6464
position: 'left',
6565
label: 'Rules',
6666
activeBasePath: '/docs/prelude',

website/gen_docs.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def copy_starlark_docs() -> None:
6464
write_file(base_path / (name + ".generated.md"), prefix + read_file(x))
6565

6666

67-
def generate_api_docs(buck: str) -> None:
67+
def generate_prelude_rules_docs(buck: str) -> None:
6868
with tempfile.TemporaryDirectory() as tmp:
69-
base_dir = Path("docs") / "prelude"
69+
base_dir = Path("docs") / "prelude" / "rules"
7070
setup_gen_dir(base_dir)
7171
# Actually generate the docs
7272
print("Running Buck...")
@@ -79,16 +79,23 @@ def generate_api_docs(buck: str) -> None:
7979
check=True,
8080
)
8181

82-
src = read_file(Path(tmp) / "prelude" / "docs" / "rules.bzl.md")
83-
dest = base_dir / "globals.generated.md"
82+
# Copy the files under Path(tmp) / prelude / docs / rules to base_dir
83+
folder = Path(tmp) / "prelude" / "docs" / "rules.bzl"
84+
for orig in folder.glob("*.md"):
85+
path = orig.relative_to(folder)
86+
dest = base_dir.joinpath(path)
87+
dest.parent.mkdir(parents=True, exist_ok=True)
88+
shutil.copyfile(orig, dest)
89+
90+
index_file_content = (
91+
"# Rules\n\nThese rules are available as standard in Buck2.\n"
92+
)
8493

85-
prefix = "---\nid: globals\n---\n"
86-
prefix += "# Rules\n\nThese rules are available as standard in Buck2.\n"
87-
src = "\n".join(src.splitlines()[1:])
94+
os.makedirs(base_dir, exist_ok=True)
95+
write_file(base_dir / "index.md", index_file_content)
8896

89-
os.makedirs(dest.parent, exist_ok=True)
90-
write_file(dest, prefix + src)
9197

98+
def generate_api_docs(buck: str) -> None:
9299
with tempfile.TemporaryDirectory() as tmp:
93100
base_dir = Path("docs") / "api"
94101
setup_gen_dir(base_dir)
@@ -254,6 +261,7 @@ def main() -> None:
254261

255262
buck = buck_command(args)
256263
copy_starlark_docs()
264+
generate_prelude_rules_docs(buck)
257265
generate_api_docs(buck)
258266
generate_bxl_utils_api_docs(buck)
259267
generate_help_docs(buck)

website/redirects.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ const baseRedirects = [
2727
from: '/docs/bootstrapping',
2828
},
2929
{
30-
to: '/docs/prelude/globals',
30+
to: '/docs/prelude/rules',
3131
from: '/docs/api/rules',
3232
},
33+
{
34+
to: '/docs/prelude/rules',
35+
from: '/docs/prelude/globals',
36+
}
3337
];
3438

3539
// Redirects that need to be introduced following changes to the generated API docs in D61778036

website/sidebars.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export const sidebars: SidebarsConfig = {
243243
},
244244
{
245245
type: 'doc',
246-
id: 'prelude/globals',
246+
id: 'prelude/rules/index',
247247
label: 'Rules',
248248
},
249249
{
@@ -274,6 +274,14 @@ export const sidebars: SidebarsConfig = {
274274
],
275275
}
276276
],
277+
'ruleSidebar': [
278+
{
279+
type: 'category',
280+
label: 'Rules',
281+
items: [{ type: 'autogenerated', dirName: 'prelude/rules' }],
282+
link: { type: 'doc', id: 'prelude/rules/index' },
283+
}
284+
],
277285
};
278286

279287
export function postProcessItems(items) {

0 commit comments

Comments
 (0)