summaryrefslogtreecommitdiff
path: root/etc/gen_readme.py
blob: 4dc2cf9bd6335f7f8a96ac7e228469aef84245b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import json
import os
from typing import List

config_vars = {}


def lines(doc: List[str]):
    return "\n".join(doc)


def gen_doc(dir: str, f):

    with open(os.path.join(dir, "RULES")) as r:
        rules = json.load(r)

    for k, v in sorted(rules.items()):
        global config_vars
        config_vars.update(v.get("config_doc", {}))
        print(
            f"### `[\"{os.path.basename(dir)}\", \"{k}\"]`\n\n {lines(v['doc'])}\n",
            file=f,
        )
        print("| Field | Description |", file=f)
        print("| ----- | ----------- |", file=f)
        for field, doc in sorted(v["field_doc"].items()):
            print(f"| `\"{field}\"` | {' '.join(doc)} |", file=f)
        print(file=f)


def print_config_vars(f):
    print(
        f"### Configuration variables\n",
        file=f,
    )
    print("| Variable | Description |", file=f)
    print("| -------- | ----------- |", file=f)
    for v, doc in sorted(config_vars.items()):
        print(f"| `\"{v}\"` | {' '.join(doc)} |", file=f)
    print(file=f)


def main():
    with open("README.md", "w") as f:
        print(
            """# Rust rules for the [`just`](https://github.com/just-buildsystem/justbuild) build system

A collection of rules for building Rust libraries, binaries and unit tests.

## How to use this repository
There are two ways to import this repository. You can generate your
`repos.json` from a template (`repos.template.json`) by importing
the `rules-rust` repository with the tool `just-import-git`

```sh
$ just-import-git -C repos.template.json --as rules-rust -b master https://github.com/just-buildsystem/rules-rust > repos.json
```

Alternatively, the `rules-rust` repository can be added manually to
your `repos.json`.

``` jsonc
...
  , "rules-rust":
    { "repository":
      { "type": "git"
      , "branch": "master"
      , "repository": "https://github.com/just-buildsystem/rules-rust"
      , "commit": "ed652442176aea086104479bb31aced501df48a2"
      , "subdir": "rules"
      }
    }
...
```

""",
            file=f,
        )
        gen_doc("rules/rust", f)
        gen_doc("rules/cargo", f)
        print_config_vars(f)


main()