Skip to content

Commit c18a971

Browse files
authored
Hotdoc: use template for Commands.md instead of generating the entire file (mesonbuild#8154)
* doc: fix hotdoc misuse for dynamically generated content hotdoc has a native include feature for including files inline. Use this to generate one file for each dynamically generated code block, and include that file in Commands.md; see: https://hotdoc.github.io/syntax-extensions.html#smart-file-inclusion-syntax This permits us to move back to using the in-tree version of the hotdoc *.md sources, thus fixing the incorrect inclusion of "builddir/" in the "Edit on github" links which resulted from using copies as the source. Fixes mesonbuild#8061 * doc: call the dummy file a "stamp" as it is a better known term
1 parent 832bcac commit c18a971

File tree

4 files changed

+38
-102
lines changed

4 files changed

+38
-102
lines changed
Lines changed: 22 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ For the full list of all available options for a specific command use the follow
1616

1717
### configure
1818

19-
```
20-
{{ cmd_help['configure']['usage'] }}
21-
```
19+
{{ configure_usage.inc }}
2220

2321
Changes options of a configured meson project.
2422

25-
```
26-
{{ cmd_help['configure']['arguments'] }}
27-
```
23+
{{ configure_arguments.inc }}
2824

2925
Most arguments are the same as in [`setup`](#setup).
3026

@@ -46,15 +42,11 @@ meson configure builddir -Doption=new_value
4642

4743
*(since 0.54.0)*
4844

49-
```
50-
{{ cmd_help['compile']['usage'] }}
51-
```
45+
{{ compile_usage.inc }}
5246

5347
Builds a default or a specified target of a configured meson project.
5448

55-
```
56-
{{ cmd_help['compile']['arguments'] }}
57-
```
49+
{{ compile_arguments.inc }}
5850

5951
`--verbose` argument is available since 0.55.0.
6052

@@ -115,15 +107,11 @@ meson compile coverage-html
115107

116108
*(since 0.52.0)*
117109

118-
```
119-
{{ cmd_help['dist']['usage'] }}
120-
```
110+
{{ dist_usage.inc }}
121111

122112
Generates a release archive from the current source tree.
123113

124-
```
125-
{{ cmd_help['dist']['arguments'] }}
126-
```
114+
{{ dist_arguments.inc }}
127115

128116
See [notes about creating releases](Creating-releases.md) for more info.
129117

@@ -138,15 +126,11 @@ meson dist -C builddir
138126

139127
*(since 0.45.0)*
140128

141-
```
142-
{{ cmd_help['init']['usage'] }}
143-
```
129+
{{ init_usage.inc }}
144130

145131
Creates a basic set of build files based on a template.
146132

147-
```
148-
{{ cmd_help['init']['arguments'] }}
149-
```
133+
{{ init_arguments.inc }}
150134

151135
#### Examples:
152136

@@ -157,15 +141,11 @@ meson init -C sourcedir
157141

158142
### introspect
159143

160-
```
161-
{{ cmd_help['introspect']['usage'] }}
162-
```
144+
{{ introspect_usage.inc }}
163145

164146
Displays information about a configured meson project.
165147

166-
```
167-
{{ cmd_help['introspect']['arguments'] }}
168-
```
148+
{{ introspect_arguments.inc }}
169149

170150
#### Examples:
171151

@@ -178,15 +158,11 @@ meson introspect builddir
178158

179159
*(since 0.47.0)*
180160

181-
```
182-
{{ cmd_help['install']['usage'] }}
183-
```
161+
{{ install_usage.inc }}
184162

185163
Installs the project to the prefix specified in [`setup`](#setup).
186164

187-
```
188-
{{ cmd_help['install']['arguments'] }}
189-
```
165+
{{ install_arguments.inc }}
190166

191167
See [the installation documentation](Installing.md) for more info.
192168

@@ -206,31 +182,23 @@ DESTDIR=/path/to/staging/area meson install -C builddir
206182

207183
*(since 0.50.0)*
208184

209-
```
210-
{{ cmd_help['rewrite']['usage'] }}
211-
```
185+
{{ rewrite_usage.inc }}
212186

213187
Modifies the meson project.
214188

215-
```
216-
{{ cmd_help['rewrite']['arguments'] }}
217-
```
189+
{{ rewrite_arguments.inc }}
218190

219191
See [the meson file rewriter documentation](Rewriter.md) for more info.
220192

221193
### setup
222194

223-
```
224-
{{ cmd_help['setup']['usage'] }}
225-
```
195+
{{ setup_usage.inc }}
226196

227197
Configures a build directory for the meson project.
228198

229199
This is the default meson command (invoked if there was no COMMAND supplied).
230200

231-
```
232-
{{ cmd_help['setup']['arguments'] }}
233-
```
201+
{{ setup_arguments.inc }}
234202

235203
See [meson introduction page](Running-Meson.md#configuring-the-build-directory) for more info.
236204

@@ -245,27 +213,19 @@ meson setup builddir
245213

246214
*(since 0.49.0)*
247215

248-
```
249-
{{ cmd_help['subprojects']['usage'] }}
250-
```
216+
{{ subprojects_usage.inc }}
251217

252218
Manages subprojects of the meson project.
253219

254-
```
255-
{{ cmd_help['subprojects']['arguments'] }}
256-
```
220+
{{ subprojects_arguments.inc }}
257221

258222
### test
259223

260-
```
261-
{{ cmd_help['test']['usage'] }}
262-
```
224+
{{ test_usage.inc }}
263225

264226
Run tests for the configure meson project.
265227

266-
```
267-
{{ cmd_help['test']['arguments'] }}
268-
```
228+
{{ test_arguments.inc }}
269229

270230
See [the unit test documentation](Unit-tests.md) for more info.
271231

@@ -283,14 +243,10 @@ meson test -C builddir specific_test_1 specific_test_2
283243

284244
### wrap
285245

286-
```
287-
{{ cmd_help['wrap']['usage'] }}
288-
```
246+
{{ wrap_usage.inc }}
289247

290248
An utility to manage WrapDB dependencies.
291249

292-
```
293-
{{ cmd_help['wrap']['arguments'] }}
294-
```
250+
{{ wrap_arguments.inc }}
295251

296252
See [the WrapDB tool documentation](Using-wraptool.md) for more info.

docs/meson.build

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@ project('Meson documentation', version: '1.0')
22

33
cur_bdir = meson.current_build_dir()
44

5-
# Copy all files to build dir, since HotDoc uses relative paths
6-
run_command(
7-
files('../tools/copy_files.py'),
8-
'-C', meson.current_source_dir(),
9-
'--output-dir', cur_bdir,
10-
'markdown', 'theme', 'sitemap.txt',
11-
check: true)
12-
135
# Only the script knows which files are being generated
146
docs_gen = custom_target(
157
'gen_docs',
168
input: files('markdown/index.md'),
17-
output: 'gen_docs.dummy',
9+
output: 'gen_docs.stamp',
1810
command: [
1911
files('../tools/regenerate_docs.py'),
20-
'--output-dir', join_paths(cur_bdir, 'markdown'),
12+
'--output-dir', cur_bdir,
2113
'--dummy-output-file', '@OUTPUT@',
2214
],
2315
build_by_default: true,
@@ -26,15 +18,15 @@ docs_gen = custom_target(
2618
hotdoc = import('hotdoc')
2719
documentation = hotdoc.generate_doc(meson.project_name(),
2820
project_version: meson.project_version(),
29-
sitemap: join_paths(cur_bdir, 'sitemap.txt'),
21+
sitemap: 'sitemap.txt',
3022
build_by_default: true,
3123
depends: docs_gen,
32-
index: join_paths(cur_bdir, 'markdown/index.md'),
24+
index: 'markdown/index.md',
3325
install: false,
3426
extra_assets: ['images/'],
35-
include_paths: [join_paths(cur_bdir, 'markdown')],
27+
include_paths: ['markdown', cur_bdir],
3628
default_license: 'CC-BY-SAv4.0',
37-
html_extra_theme: join_paths(cur_bdir, 'theme', 'extra'),
29+
html_extra_theme: join_paths('theme', 'extra'),
3830
git_upload_repository: 'git@github.com:jpakkane/jpakkane.github.io.git',
3931
edit_on_github_repository: 'https://github.com/mesonbuild/meson',
4032
syntax_highlighting_activate: true,

run_unittests.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4915,7 +4915,7 @@ def test_commands_documented(self):
49154915
# The docs directory is not in release tarballs.
49164916
if not os.path.isdir('docs'):
49174917
raise unittest.SkipTest('Doc directory does not exist.')
4918-
doc_path = 'docs/markdown_dynamic/Commands.md'
4918+
doc_path = 'docs/markdown/Commands.md'
49194919

49204920
md = None
49214921
with open(doc_path, encoding='utf-8') as f:
@@ -4944,13 +4944,9 @@ def test_commands_documented(self):
49444944

49454945
def get_data_pattern(command):
49464946
return re.compile(
4947-
r'^```[\r\n]'
4948-
r'{{ cmd_help\[\'' + command + r'\'\]\[\'usage\'\] }}[\r\n]'
4949-
r'^```[\r\n]'
4947+
r'{{ ' + command + r'_usage.inc }}[\r\n]'
49504948
r'.*?'
4951-
r'^```[\r\n]'
4952-
r'{{ cmd_help\[\'' + command + r'\'\]\[\'arguments\'\] }}[\r\n]'
4953-
r'^```',
4949+
r'{{ ' + command + r'_arguments.inc }}[\r\n]',
49544950
flags = re.MULTILINE|re.DOTALL)
49554951

49564952
for command in md_commands:
@@ -7533,7 +7529,7 @@ def test_pkg_config_option(self):
75337529
'-Dbuild.pkg_config_path=' + os.path.join(testdir, 'build_extra_path'),
75347530
'-Dpkg_config_path=' + os.path.join(testdir, 'host_extra_path'),
75357531
])
7536-
7532+
75377533
def test_run_native_test(self):
75387534
'''
75397535
https://github.com/mesonbuild/meson/issues/7997

tools/regenerate_docs.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
'''
2121

2222
import argparse
23-
import jinja2
2423
import os
2524
import re
2625
import subprocess
@@ -108,20 +107,13 @@ def clean_dir_arguments(text: str) -> str:
108107

109108
return cmd_data
110109

111-
def regenerate_commands(root_dir: Path, output_dir: Path) -> None:
112-
with open(root_dir/'docs'/'markdown_dynamic'/'Commands.md') as f:
113-
template = f.read()
114-
110+
def generate_hotdoc_includes(root_dir: Path, output_dir: Path) -> None:
115111
cmd_data = get_commands_data(root_dir)
116112

117-
t = jinja2.Template(template, undefined=jinja2.StrictUndefined, keep_trailing_newline=True)
118-
content = t.render(cmd_help=cmd_data)
119-
120-
output_file = output_dir/'Commands.md'
121-
with open(output_file, 'w') as f:
122-
f.write(content)
123-
124-
print(f'`{output_file}` was regenerated')
113+
for cmd, parsed in cmd_data.items():
114+
for typ in parsed.keys():
115+
with open(output_dir / (cmd+'_'+typ+'.inc'), 'w') as f:
116+
f.write(parsed[typ])
125117

126118
def regenerate_docs(output_dir: PathLike,
127119
dummy_output_file: T.Optional[PathLike]) -> None:
@@ -133,7 +125,7 @@ def regenerate_docs(output_dir: PathLike,
133125

134126
root_dir = Path(__file__).resolve().parent.parent
135127

136-
regenerate_commands(root_dir, output_dir)
128+
generate_hotdoc_includes(root_dir, output_dir)
137129

138130
if dummy_output_file:
139131
with open(output_dir/dummy_output_file, 'w') as f:

0 commit comments

Comments
 (0)