summaryrefslogtreecommitdiffstats
path: root/documentation
diff options
context:
space:
mode:
Diffstat (limited to 'documentation')
-rw-r--r--documentation/ref-manual/variables.rst6
-rwxr-xr-xdocumentation/tools/check-glossaries90
2 files changed, 96 insertions, 0 deletions
diff --git a/documentation/ref-manual/variables.rst b/documentation/ref-manual/variables.rst
index e4d5a9c97a..6c2344950b 100644
--- a/documentation/ref-manual/variables.rst
+++ b/documentation/ref-manual/variables.rst
@@ -7,6 +7,9 @@ Variables Glossary
7This chapter lists common variables used in the OpenEmbedded build 7This chapter lists common variables used in the OpenEmbedded build
8system and gives an overview of their function and contents. 8system and gives an overview of their function and contents.
9 9
10..
11 check_glossary_begin
12
10:term:`A <ABIEXTENSION>` :term:`B` :term:`C <CACHE>` 13:term:`A <ABIEXTENSION>` :term:`B` :term:`C <CACHE>`
11:term:`D` :term:`E <EFI_PROVIDER>` :term:`F <FAKEROOT>` 14:term:`D` :term:`E <EFI_PROVIDER>` :term:`F <FAKEROOT>`
12:term:`G <GCCPIE>` :term:`H <HGDIR>` :term:`I <IMAGE_BASENAME>` 15:term:`G <GCCPIE>` :term:`H <HGDIR>` :term:`I <IMAGE_BASENAME>`
@@ -16,6 +19,9 @@ system and gives an overview of their function and contents.
16:term:`U <UBOOT_BINARY>` :term:`V <VIRTUAL-RUNTIME>` 19:term:`U <UBOOT_BINARY>` :term:`V <VIRTUAL-RUNTIME>`
17:term:`W <WARN_QA>` :term:`X <XSERVER>` :term:`Z <ZSTD_THREADS>` 20:term:`W <WARN_QA>` :term:`X <XSERVER>` :term:`Z <ZSTD_THREADS>`
18 21
22..
23 check_glossary_end
24
19.. glossary:: 25.. glossary::
20 :sorted: 26 :sorted:
21 27
diff --git a/documentation/tools/check-glossaries b/documentation/tools/check-glossaries
new file mode 100755
index 0000000000..b5dfe834e5
--- /dev/null
+++ b/documentation/tools/check-glossaries
@@ -0,0 +1,90 @@
1#!/usr/bin/env python3
2
3import argparse
4import difflib
5import os
6import re
7
8from pathlib import Path
9
10
11def parse_arguments() -> argparse.Namespace:
12 parser = argparse.ArgumentParser(description="Print supported distributions")
13
14 parser.add_argument("-d", "--docs-dir",
15 type=Path,
16 default=Path(os.path.dirname(os.path.realpath(__file__))) / "documentation",
17 help="Path to documentation/ directory in yocto-docs")
18
19 return parser.parse_args()
20
21
22glossaries = (
23 'ref-manual/variables.rst',
24 'ref-manual/terms.rst',
25)
26
27
28def main():
29
30 args = parse_arguments()
31 in_glossary = False
32 # Pattern to match:
33 # :term:`A <ABIEXTENSION>` :term:`B` :term:`C <CACHE>`
34 glossary_re = re.compile(r":term:`(?P<letter>[A-Z]{1})( <(?P<varname>[A-Z_]+)>)?`")
35 entry_re = re.compile(r"^ :term:`(?P<entry>.+)`\s*$")
36
37 for rst in glossaries:
38
39 glossary = {}
40 rst_path = Path(args.docs_dir) / rst
41
42 with open(rst_path, "r") as f:
43 for line in f.readlines():
44 if "check_glossary_begin" in line:
45 in_glossary = True
46 continue
47 if in_glossary:
48 for m in re.finditer(glossary_re, line.strip()):
49 letter = m.group("letter")
50 varname = m.group("varname")
51 if varname is None:
52 varname = letter
53 glossary[letter] = varname
54 if "check_glossary_end" in line:
55 in_glossary = False
56 break
57
58 entries = []
59
60 with open(rst_path, "r") as f:
61 for line in f.readlines():
62 m = re.match(entry_re, line)
63 if m:
64 entries.append(m.group("entry"))
65
66 # We lower here because underscore (_) come before lowercase letters
67 # (the natural way) but after uppercase letters (which is not natural)
68 sorted_entries = sorted(entries, key=lambda t: t.lower())
69 diffs = list(difflib.unified_diff(entries,
70 sorted_entries,
71 fromfile="original_list",
72 tofile="sorted_list"))
73
74 if diffs:
75 print(f"WARNING: {rst}: entries are not properly sorted:")
76 print('\n'.join(diffs))
77
78 for letter in glossary:
79 try:
80 index = entries.index(glossary[letter])
81 except ValueError:
82 print(f"WARNING: {rst}: variable "
83 f"{glossary[letter]} in glossary does not exist")
84 if index > 0 and entries[index - 1].startswith(letter[0]):
85 print(f"WARNING: {rst}: The variable {glossary[letter]} shouldn't be in "
86 "the glossary.")
87
88
89if __name__ == "__main__":
90 main()