Skip to content

Commit a7fbd54

Browse files
authored
Merge pull request #1646 from hansu/doc-component-list
docs: HAL Component List - generate unlisted components automatically
2 parents 23db1d6 + b7196b0 commit a7fbd54

File tree

9 files changed

+450
-336
lines changed

9 files changed

+450
-336
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ build-stamp
1313
.tmp*
1414
# Ignore generated html files,
1515
/docs/src/*/*.html
16+
docs/src/hal/components_gen.adoc
1617
# docs/html/.gitignore is for the html directory
1718
debian/*.debhelper.log
1819
rtlib/Module.symvers

docs/po4a.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
[type: AsciiDoc_def] src/hal/canonical-devices.adoc $lang:src/$lang/hal/canonical-devices.adoc
112112
[type: AsciiDoc_def] src/hal/comp.adoc $lang:src/$lang/hal/comp.adoc
113113
[type: AsciiDoc_def] src/hal/components.adoc $lang:src/$lang/hal/components.adoc
114+
[type: AsciiDoc_def] src/hal/components_gen.adoc $lang:src/$lang/hal/components_gen.adoc
114115
[type: AsciiDoc_def] src/hal/general-ref.adoc $lang:src/$lang/hal/general-ref.adoc
115116
[type: AsciiDoc_def] src/hal/hal-examples.adoc $lang:src/$lang/hal/hal-examples.adoc
116117
[type: AsciiDoc_def] src/hal/halmodule.adoc $lang:src/$lang/hal/halmodule.adoc

docs/src/Submakefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,15 @@ pdfdocs: svgs_made_from_dots $(PDF_TARGETS)
350350

351351
htmldocs: svgs_made_from_dots .htmldoc-stamp checkref_en
352352

353-
.htmldoc-stamp: copy_asciidoc_files $(HTML_TARGETS) .images-stamp .include-stamp
353+
.htmldoc-stamp: copy_asciidoc_files gen_complist $(HTML_TARGETS) .images-stamp .include-stamp
354354
touch $@
355355

356-
.PHONY: copy_asciidoc_files
357-
copy_asciidoc_files:
358-
cp -f /etc/asciidoc/stylesheets/*.css $(DOC_DIR)/html
359-
cp -f /etc/asciidoc/javascripts/*.js $(DOC_DIR)/html
356+
copy_asciidoc_files: $(wildcard /etc/asciidoc/stylesheets/*.css) $(wildcard /etc/asciidoc/javascripts/*.js)
357+
cp -f $^ $(DOC_DIR)/html
358+
359+
gen_complist: $(DOC_SRCDIR)/gen_complist.py $(DOC_SRCDIR)/hal/components.adoc $(MAN_HTML_TARGETS)
360+
mkdir -p $(DOC_DIR)/html/hal
361+
python3 $(DOC_SRCDIR)/gen_complist.py $(DOC_SRCDIR)/hal/components.adoc
360362

361363
checkref: checkref_en checkref_de checkref_es checkref_fr checkref_hu checkref_nb checkref_vi checkref_zh_CN
362364

docs/src/asciideps

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ includes () {
99
DIR=`dirname "$1"`
1010

1111
for f in `sed -ne "s|^include::\(.*\)\[\]$|$DIR/\1|p" "$1"`; do
12+
# components_gen.adoc will contain only generated content
13+
case "$f" in
14+
*/components_gen.adoc)
15+
touch "$f"
16+
;;
17+
esac
1218
echo "$f"
1319
includes "$f"
1420
done

docs/src/gen_complist.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env python3
2+
# generate_complist()
3+
# Compares the entries in the component list (components.adoc) with the
4+
# available man pages and adds tables for missing components.
5+
# generate_links()
6+
# Generates a copy of components.adoc with added links to the man pages for the components.
7+
8+
import os
9+
import re
10+
import sys
11+
12+
man1_path = '../docs/man/man1'
13+
man1_files = {f for f in os.listdir(man1_path) if os.path.isfile(os.path.join(man1_path, f))}
14+
man9_path = '../docs/man/man9'
15+
man9_files = {f for f in os.listdir(man9_path) if os.path.isfile(os.path.join(man9_path, f))}
16+
man_files = man1_files.union(man9_files)
17+
complist_doc = set()
18+
miss_in_man = set()
19+
# complist_path = '../docs/src/hal/components.adoc'
20+
21+
def generate_complist(complist_path):
22+
file1 = open(complist_path, 'r')
23+
for line in file1:
24+
if line[0] == '|' and line[1] != '=':
25+
splitted = line.split('|')
26+
if splitted[1].strip() != '':
27+
if 'link:' in splitted[1]:
28+
link = re.search('(?<=link:).*(?=\\[)', splitted[1]).group()
29+
comp_man = re.search("[a-zA-Z0-9-_\\.]+(?=\\.html)", link).group()
30+
if os.path.isfile(os.path.join('../docs/html/hal',link)):
31+
complist_doc.add(comp_man)
32+
else:
33+
print('gen_complist: Broken link:', link, file=sys.stderr)
34+
miss_in_man.add(comp_man.split(".")[0])
35+
else:
36+
print("gen_complist: Component \"" + splitted[1].strip() + "\" without link")
37+
miss_in_man.add(splitted[1])
38+
file1.close()
39+
miss_in_list = man_files.difference(complist_doc)
40+
41+
gen_filename = '../docs/src/hal/components_gen.adoc'
42+
file2 = open(gen_filename, 'w')
43+
if len(miss_in_list) > 0:
44+
file2.write('=== Not categorized (auto generated from man pages)\n')
45+
file2.write('[{tab_options}]\n|=======================\n')
46+
for i in sorted(miss_in_list):
47+
file2.write('| ' + i + ' |||\n')
48+
file2.write('|=======================\n')
49+
if len(miss_in_man) > 0:
50+
file2.write('\n=== Without man page or broken link (auto generated from component list)\n')
51+
file2.write('[{tab_options}]\n|=======================\n')
52+
for i in sorted(miss_in_man):
53+
file2.write('| ' + i + ' |||\n')
54+
file2.write('|=======================\n')
55+
file2.close()
56+
57+
generate_links(gen_filename, False, True)
58+
print('gen_complist: Added {} uncategorized and {} potentially obsolete entrie(s) to hal component list'.format(len(miss_in_list), len(miss_in_man)))
59+
60+
61+
def generate_links(filename, create_backup=True, add_descr=False):
62+
file = open(filename, 'r')
63+
file_links = []
64+
links_added = 0
65+
for line in file:
66+
if line[0] == '|' and line[1] != '=':
67+
splitted = line.split('|')
68+
69+
if 'link:' in splitted[1]:
70+
link = re.search('(?<=link:).*(?=\[)', splitted[1]).group()
71+
if not os.path.isfile(os.path.join('../docs/html/hal',link)):
72+
print('gen_complist: Broken link:', link)
73+
else:
74+
comp_man = splitted[1].strip(' ')
75+
if comp_man in man_files:
76+
comp, man = comp_man.split(".")
77+
line = line.replace(comp_man, 'link:../man/man'+man+'/'+comp_man+'.html['+comp+']', 1)
78+
links_added += 1
79+
if add_descr:
80+
splitted = line.split('|')
81+
splitted[2] = extract_descr('../docs/man/man'+man+'/'+comp_man)\
82+
.replace(comp + ' ', ' ',1).strip('\n -')
83+
line = '|'.join(splitted)
84+
file_links.append(line)
85+
file.close()
86+
87+
if links_added:
88+
if create_backup:
89+
os.rename(filename, filename+'~')
90+
file = open(filename, 'w')
91+
for line in file_links:
92+
file.write(line)
93+
file.close()
94+
print('gen_complist: Added {} link(s) to {}'.format(links_added, filename))
95+
96+
97+
def extract_descr(filename):
98+
file = open(filename, 'r')
99+
descr = ''
100+
in_descr = False
101+
102+
for line in file:
103+
if '.SH NAME' in line or '.SH "NAME' in line:
104+
in_descr = True
105+
elif '.SH' in line:
106+
break
107+
elif in_descr:
108+
descr += line
109+
file.close()
110+
return re.sub(r'\\fB|\\fR|\\fI|\\', '', descr)
111+
112+
if __name__ == "__main__":
113+
114+
if len(sys.argv) > 1:
115+
if 'links' in sys.argv:
116+
generate_links(sys.argv[1])
117+
else:
118+
generate_complist(sys.argv[1])

docs/src/hal/basic-hal.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ follow a 'Truth Table' that states what the output is for any given
377377
input. Typically these are bit manipulators and follow electrical logic
378378
gate truth tables.
379379

380-
For further components see <<sec:realtime-components,Realtime Components List>>
380+
For further components see <<sec:hal-components,HAL Components List>>
381381
or the man pages.
382382

383383
[[sub:hal-and2]]

0 commit comments

Comments
 (0)