Skip to content

Commit 563061e

Browse files
committed
bazel: add api description
1 parent 5943e45 commit 563061e

3 files changed

Lines changed: 122 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The Python implementation can be used for several purposes:
3232
### For normal users
3333

3434
* [Tutorial](documentation/TUTORIAL.md) (read this as a first introduction)
35+
* [Bazel integration](documentation/TUTORIAL-BAZEL.md) (how to use TRLC inside a Bazel build)
3536
* [User manual: TRLC linter](documentation/linter.md) (the user manual for the TRLC static analysis and linter)
3637
* [Release Notes](CHANGELOG.md) (read this to find out whats new)
3738
* [License](LICENSE)

api-examples/filename-check/BUILD

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
1-
load("//:trlc.bzl", "trlc_requirements", "trlc_requirements_test", "trlc_specification")
1+
load("//:trlc.bzl", "trlc_requirements", "trlc_requirements_test", "trlc_specification", "trlc_specification_test")
22

3+
# Run all passing tests in this package: bazel test //api-examples/filename-check
4+
test_suite(
5+
name = "filename-check",
6+
tests = [
7+
":spec_check",
8+
":validate",
9+
],
10+
)
11+
12+
13+
# 1. Gather the RSL schema
314
trlc_specification(
415
name = "spec",
516
srcs = ["example.rsl"],
617
visibility = ["//api-examples:__subpackages__"],
718
)
819

20+
# 2. Gather the requirements
921
trlc_requirements(
1022
name = "reqs",
1123
srcs = ["example.trlc"],
1224
spec = [":spec"],
1325
)
1426

27+
# 3. Validate that the RSL schema itself is consistent
28+
trlc_specification_test(
29+
name = "spec_check",
30+
reqs = [":reqs"],
31+
)
32+
33+
# 4. Standard built-in validation (trlc --verify)
1534
trlc_requirements_test(
16-
name = "foo",
35+
name = "validate",
1736
reqs = [
1837
":reqs",
1938
],
2039
)
2140

41+
# 5. Custom validation script: checks that illustration filenames exist on disk
2242
trlc_requirements_test(
23-
name = "bar",
43+
name = "filename_check",
2444
srcs = [":filename-3.py"],
2545
main = "filename-3.py",
2646
reqs = [

documentation/TUTORIAL-BAZEL.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Using TRLC with Bazel
2+
3+
TRLC ships Bazel macros in [`trlc.bzl`](@trlc//trlc.bzl)
4+
5+
## Setup
6+
7+
```python
8+
# MODULE.bazel
9+
bazel_dep(name = "trlc", version = "x.x.x")
10+
```
11+
12+
```python
13+
# BUILD
14+
load("@trlc//:trlc.bzl",
15+
"trlc_specification",
16+
"trlc_requirements",
17+
"trlc_requirements_test",
18+
"trlc_specification_test")
19+
```
20+
21+
It includes the pre-built CVC5 binary for Linux, macOS, and Windows.
22+
23+
---
24+
25+
## Public API
26+
27+
### `trlc_specification(name, srcs)`
28+
29+
Collects `.rsl` schema files into a bazel target.
30+
31+
| Attribute | Description |
32+
|-----------|-------------|
33+
| `name` | Target name. |
34+
| `srcs` | `*.rsl` files. |
35+
36+
---
37+
38+
### `trlc_requirements(name, srcs, spec=[], deps=[])`
39+
40+
Collects `.trlc` requirement files, wired to their schema and any
41+
imported packages.
42+
43+
| Attribute | Description |
44+
|-----------|-------------|
45+
| `name` | Target name. |
46+
| `srcs` | `*.trlc` files. |
47+
| `spec` | Direct `trlc_specification` targets. |
48+
| `deps` | Other `trlc_requirements` targets whose packages are imported. |
49+
50+
---
51+
52+
### `trlc_requirements_test(name, reqs, srcs=…, main=…)`
53+
54+
Runs `trlc --verify`. The test passes when TRLC reports no errors.
55+
Pass a custom `srcs`/`main` to run your own Python script instead
56+
of the built-in CLI (see [TUTORIAL-API.md](TUTORIAL-API.md)).
57+
58+
| Attribute | Description |
59+
|-----------|-------------|
60+
| `name` | Target name. |
61+
| `reqs` | `trlc_requirements` targets to validate. |
62+
| `srcs` | Override the entry-point script (optional). |
63+
| `main` | Filename of the entry point (required when `srcs` is set). |
64+
65+
---
66+
67+
### `trlc_specification_test(name, reqs)`
68+
69+
Like `trlc_requirements_test` but passes `--skip-trlc-files`. Use
70+
this to check the RSL schema is consistent before any `.trlc` data
71+
files exist.
72+
73+
---
74+
75+
## Example — `api-examples/filename-check/`
76+
77+
See the complete working example in
78+
[`api-examples/filename-check/`](../api-examples/filename-check/).
79+
80+
---
81+
82+
## Multi-package layout
83+
84+
Chain packages with `deps` when one `.trlc` file imports another:
85+
86+
```python
87+
# base/BUILD
88+
trlc_specification(name = "spec", srcs = ["base.rsl"])
89+
trlc_requirements(name = "reqs", srcs = ["base_reqs.trlc"], spec = [":spec"])
90+
91+
# feature/BUILD
92+
trlc_requirements(
93+
name = "reqs",
94+
srcs = ["feature_reqs.trlc"],
95+
spec = [":feature_spec"],
96+
deps = ["//base:reqs"], # pulls in base.rsl + base_reqs.trlc
97+
)
98+
```

0 commit comments

Comments
 (0)