Skip to content

[libc][docs] move docgen from json to yaml #119744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions libc/utils/docgen/arpa/inet.json

This file was deleted.

18 changes: 18 additions & 0 deletions libc/utils/docgen/arpa/inet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
functions:
htonl:
posix-definition: ''
htons:
posix-definition: ''
inet_addr:
posix-definition: ''
inet_ntoa:
posix-definition: ''
inet_ntop:
posix-definition: ''
inet_pton:
posix-definition: ''
ntohl:
posix-definition: ''
ntohs:
posix-definition: ''

11 changes: 0 additions & 11 deletions libc/utils/docgen/assert.json

This file was deleted.

7 changes: 7 additions & 0 deletions libc/utils/docgen/assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
macros:
__STDC_VERSION_ASSERT_H__:
c-definition: 7.2.1
assert:
c-definition: 7.2.1
in-latest-posix: ''

102 changes: 0 additions & 102 deletions libc/utils/docgen/ctype.json

This file was deleted.

72 changes: 72 additions & 0 deletions libc/utils/docgen/ctype.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
functions:
isalnum:
c-definition: 7.4.1.1
in-latest-posix: ''
isalnum_l:
in-latest-posix: ''
isalpha:
c-definition: 7.4.1.2
in-latest-posix: ''
isalpha_l:
in-latest-posix: ''
isblank:
c-definition: 7.4.1.3
in-latest-posix: ''
isblank_l:
in-latest-posix: ''
iscntrl:
c-definition: 7.4.1.4
in-latest-posix: ''
iscntrl_l:
in-latest-posix: ''
isdigit:
c-definition: 7.4.1.5
in-latest-posix: ''
isdigit_l:
in-latest-posix: ''
isgraph:
c-definition: 7.4.1.6
in-latest-posix: ''
isgraph_l:
in-latest-posix: ''
islower:
c-definition: 7.4.1.7
in-latest-posix: ''
islower_l:
in-latest-posix: ''
isprint:
c-definition: 7.4.1.8
in-latest-posix: ''
isprint_l:
in-latest-posix: ''
ispunct:
c-definition: 7.4.1.9
in-latest-posix: ''
ispunct_l:
in-latest-posix: ''
isspace:
c-definition: 7.4.1.10
in-latest-posix: ''
isspace_l:
in-latest-posix: ''
isupper:
c-definition: 7.4.1.11
in-latest-posix: ''
isupper_l:
in-latest-posix: ''
isxdigit:
c-definition: 7.4.1.12
in-latest-posix: ''
isxdigit_l:
in-latest-posix: ''
tolower:
c-definition: 7.4.2.1
in-latest-posix: ''
tolower_l:
in-latest-posix: ''
toupper:
c-definition: 7.4.2.2
in-latest-posix: ''
toupper_l:
in-latest-posix: ''

18 changes: 9 additions & 9 deletions libc/utils/docgen/docgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from argparse import ArgumentParser, Namespace
from pathlib import Path
from typing import Dict
import json
import os
import sys
import yaml

from header import Header

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

def check_api(header: Header, api: Dict):
"""
Checks that docgen json files are properly formatted. If there are any
Checks that docgen yaml files are properly formatted. If there are any
fatal formatting errors, raises exceptions with error messages useful for
fixing formatting. Warnings are printed to stderr on non-fatal formatting
errors. The code that runs after ``check_api(api)`` is called expects that
``check_api`` executed without raising formatting exceptions so the json
``check_api`` executed without raising formatting exceptions so the yaml
matches the formatting specified here.

The json file may contain:
The yaml file may contain:
* an optional macros object
* an optional functions object

Expand All @@ -49,7 +49,7 @@ def check_api(header: Header, api: Dict):
this should be a C standard section number. For the ``"posix-definition"`` property,
this should be a link to the definition.

:param api: docgen json file contents parsed into a dict
:param api: docgen yaml file contents parsed into a dict
"""
errors = []
# We require entries to have at least one of these.
Expand Down Expand Up @@ -93,8 +93,8 @@ def check_api(header: Header, api: Dict):


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


def print_tbl_dir(name):
Expand Down Expand Up @@ -192,12 +192,12 @@ def print_impl_status_rst(header: Header, api: Dict):
print_functions_rst(header, api["functions"])


# This code implicitly relies on docgen.py being in the same dir as the json
# This code implicitly relies on docgen.py being in the same dir as the yaml
# files and is likely to need to be fixed when re-integrating docgen into
# hdrgen.
def get_choices() -> list:
choices = []
for path in Path(__file__).parent.rglob("*.json"):
for path in Path(__file__).parent.rglob("*.yaml"):
fname = path.with_suffix(".h").name
if path.parent != Path(__file__).parent:
fname = path.parent.name + os.sep + fname
Expand Down
20 changes: 0 additions & 20 deletions libc/utils/docgen/errno.json

This file was deleted.

14 changes: 14 additions & 0 deletions libc/utils/docgen/errno.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
macros:
EDOM:
c-definition: '7.5'
in-latest-posix: ''
EILSEQ:
c-definition: '7.5'
in-latest-posix: ''
ERANGE:
c-definition: '7.5'
in-latest-posix: ''
errno:
c-definition: '7.5'
in-latest-posix: ''

Loading
Loading