Skip to content

Commit 88bcf72

Browse files
[libc][docs] move docgen from json to yaml (#119744)
That way it can more easily be integrated into hdrgen.
1 parent 9b65b1e commit 88bcf72

39 files changed

+1320
-1872
lines changed

libc/utils/docgen/arpa/inet.json

Lines changed: 0 additions & 28 deletions
This file was deleted.

libc/utils/docgen/arpa/inet.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
functions:
2+
htonl:
3+
posix-definition: ''
4+
htons:
5+
posix-definition: ''
6+
inet_addr:
7+
posix-definition: ''
8+
inet_ntoa:
9+
posix-definition: ''
10+
inet_ntop:
11+
posix-definition: ''
12+
inet_pton:
13+
posix-definition: ''
14+
ntohl:
15+
posix-definition: ''
16+
ntohs:
17+
posix-definition: ''
18+

libc/utils/docgen/assert.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

libc/utils/docgen/assert.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
macros:
2+
__STDC_VERSION_ASSERT_H__:
3+
c-definition: 7.2.1
4+
assert:
5+
c-definition: 7.2.1
6+
in-latest-posix: ''
7+

libc/utils/docgen/ctype.json

Lines changed: 0 additions & 102 deletions
This file was deleted.

libc/utils/docgen/ctype.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
functions:
2+
isalnum:
3+
c-definition: 7.4.1.1
4+
in-latest-posix: ''
5+
isalnum_l:
6+
in-latest-posix: ''
7+
isalpha:
8+
c-definition: 7.4.1.2
9+
in-latest-posix: ''
10+
isalpha_l:
11+
in-latest-posix: ''
12+
isblank:
13+
c-definition: 7.4.1.3
14+
in-latest-posix: ''
15+
isblank_l:
16+
in-latest-posix: ''
17+
iscntrl:
18+
c-definition: 7.4.1.4
19+
in-latest-posix: ''
20+
iscntrl_l:
21+
in-latest-posix: ''
22+
isdigit:
23+
c-definition: 7.4.1.5
24+
in-latest-posix: ''
25+
isdigit_l:
26+
in-latest-posix: ''
27+
isgraph:
28+
c-definition: 7.4.1.6
29+
in-latest-posix: ''
30+
isgraph_l:
31+
in-latest-posix: ''
32+
islower:
33+
c-definition: 7.4.1.7
34+
in-latest-posix: ''
35+
islower_l:
36+
in-latest-posix: ''
37+
isprint:
38+
c-definition: 7.4.1.8
39+
in-latest-posix: ''
40+
isprint_l:
41+
in-latest-posix: ''
42+
ispunct:
43+
c-definition: 7.4.1.9
44+
in-latest-posix: ''
45+
ispunct_l:
46+
in-latest-posix: ''
47+
isspace:
48+
c-definition: 7.4.1.10
49+
in-latest-posix: ''
50+
isspace_l:
51+
in-latest-posix: ''
52+
isupper:
53+
c-definition: 7.4.1.11
54+
in-latest-posix: ''
55+
isupper_l:
56+
in-latest-posix: ''
57+
isxdigit:
58+
c-definition: 7.4.1.12
59+
in-latest-posix: ''
60+
isxdigit_l:
61+
in-latest-posix: ''
62+
tolower:
63+
c-definition: 7.4.2.1
64+
in-latest-posix: ''
65+
tolower_l:
66+
in-latest-posix: ''
67+
toupper:
68+
c-definition: 7.4.2.2
69+
in-latest-posix: ''
70+
toupper_l:
71+
in-latest-posix: ''
72+

libc/utils/docgen/docgen.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from argparse import ArgumentParser, Namespace
1111
from pathlib import Path
1212
from typing import Dict
13-
import json
1413
import os
1514
import sys
15+
import yaml
1616

1717
from header import Header
1818

@@ -23,14 +23,14 @@ class DocgenAPIFormatError(Exception):
2323

2424
def check_api(header: Header, api: Dict):
2525
"""
26-
Checks that docgen json files are properly formatted. If there are any
26+
Checks that docgen yaml files are properly formatted. If there are any
2727
fatal formatting errors, raises exceptions with error messages useful for
2828
fixing formatting. Warnings are printed to stderr on non-fatal formatting
2929
errors. The code that runs after ``check_api(api)`` is called expects that
30-
``check_api`` executed without raising formatting exceptions so the json
30+
``check_api`` executed without raising formatting exceptions so the yaml
3131
matches the formatting specified here.
3232
33-
The json file may contain:
33+
The yaml file may contain:
3434
* an optional macros object
3535
* an optional functions object
3636
@@ -49,7 +49,7 @@ def check_api(header: Header, api: Dict):
4949
this should be a C standard section number. For the ``"posix-definition"`` property,
5050
this should be a link to the definition.
5151
52-
:param api: docgen json file contents parsed into a dict
52+
:param api: docgen yaml file contents parsed into a dict
5353
"""
5454
errors = []
5555
# We require entries to have at least one of these.
@@ -93,8 +93,8 @@ def check_api(header: Header, api: Dict):
9393

9494

9595
def load_api(header: Header) -> Dict:
96-
api = header.docgen_json.read_text(encoding="utf-8")
97-
return json.loads(api)
96+
api = header.docgen_yaml.read_text(encoding="utf-8")
97+
return yaml.safe_load(api)
9898

9999

100100
def print_tbl_dir(name):
@@ -192,12 +192,12 @@ def print_impl_status_rst(header: Header, api: Dict):
192192
print_functions_rst(header, api["functions"])
193193

194194

195-
# This code implicitly relies on docgen.py being in the same dir as the json
195+
# This code implicitly relies on docgen.py being in the same dir as the yaml
196196
# files and is likely to need to be fixed when re-integrating docgen into
197197
# hdrgen.
198198
def get_choices() -> list:
199199
choices = []
200-
for path in Path(__file__).parent.rglob("*.json"):
200+
for path in Path(__file__).parent.rglob("*.yaml"):
201201
fname = path.with_suffix(".h").name
202202
if path.parent != Path(__file__).parent:
203203
fname = path.parent.name + os.sep + fname

libc/utils/docgen/errno.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

libc/utils/docgen/errno.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
macros:
2+
EDOM:
3+
c-definition: '7.5'
4+
in-latest-posix: ''
5+
EILSEQ:
6+
c-definition: '7.5'
7+
in-latest-posix: ''
8+
ERANGE:
9+
c-definition: '7.5'
10+
in-latest-posix: ''
11+
errno:
12+
c-definition: '7.5'
13+
in-latest-posix: ''
14+

0 commit comments

Comments
 (0)