Skip to content

Commit c88c1e7

Browse files
xclaessejpakkane
authored andcommitted
doc: Generate dev release notes
1 parent 5746469 commit c88c1e7

File tree

2 files changed

+69
-31
lines changed

2 files changed

+69
-31
lines changed

docs/genrelnotes.py

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
'''
1717
Generates release notes for new releases of Meson build system
1818
'''
19+
import argparse
1920
import subprocess
20-
import sys
21-
import os
22-
from glob import glob
21+
import re
22+
import shutil
23+
from pathlib import Path
2324

2425
RELNOTE_TEMPLATE = '''---
2526
title: Release {}
@@ -31,43 +32,65 @@
3132
'''
3233

3334

34-
def add_to_sitemap(from_version, to_version):
35+
def add_to_sitemap(sitemap, output_sitemap):
3536
'''
3637
Adds release note entry to sitemap.txt.
3738
'''
38-
sitemapfile = '../sitemap.txt'
39-
s_f = open(sitemapfile, encoding='utf-8')
40-
lines = s_f.readlines()
41-
s_f.close()
42-
with open(sitemapfile, 'w', encoding='utf-8') as s_f:
39+
sitemapfile = Path(sitemap)
40+
with sitemapfile.open(encoding='utf-8') as s_f:
41+
lines = s_f.readlines()
42+
relnotes = None
43+
to_version = None
44+
output = Path(output_sitemap)
45+
output.parent.mkdir(exist_ok=True, parents=True)
46+
with output.open('w', encoding='utf-8') as s_f:
4347
for line in lines:
44-
if 'Release-notes' in line and from_version in line:
45-
new_line = line.replace(from_version, to_version)
46-
s_f.write(new_line)
48+
if relnotes is None:
49+
m = re.match(r'[\s]*Release-notes-for-([0-9]+)\.([0-9]+)\.([0-9]+)\.md', line)
50+
if m:
51+
from_version = f'{m[1]}.{m[2]}.{m[3]}'
52+
to_version = f'{m[1]}.{int(m[2]) + 1}.{m[3]}'
53+
new_line = line.replace(from_version, to_version)
54+
relnotes = new_line.strip()
55+
s_f.write(new_line)
4756
s_f.write(line)
4857

49-
def generate(from_version, to_version):
58+
if sitemapfile == output:
59+
subprocess.check_call(['git', 'add', output])
60+
61+
return relnotes, to_version
62+
63+
def generate(relnotes, to_version, source_dir, output_dir):
5064
'''
5165
Generate notes for Meson build next release.
5266
'''
53-
ofilename = f'Release-notes-for-{to_version}.md'
54-
with open(ofilename, 'w', encoding='utf-8') as ofile:
55-
ofile.write(RELNOTE_TEMPLATE.format(to_version, to_version))
56-
for snippetfile in glob('snippets/*.md'):
57-
snippet = open(snippetfile, encoding='utf-8').read()
67+
release = f'{to_version} (in development)' if output_dir else to_version
68+
output = Path(output_dir, relnotes) if output_dir else Path('markdown', relnotes)
69+
output.parent.mkdir(exist_ok=True, parents=True)
70+
with output.open('w', encoding='utf-8') as ofile:
71+
ofile.write(RELNOTE_TEMPLATE.format(release, to_version))
72+
for snippetfile in Path(source_dir, 'markdown/snippets').glob('*.md'):
73+
snippet = snippetfile.read_text(encoding='utf-8')
5874
ofile.write(snippet)
5975
if not snippet.endswith('\n'):
6076
ofile.write('\n')
6177
ofile.write('\n')
62-
subprocess.check_call(['git', 'rm', snippetfile])
63-
subprocess.check_call(['git', 'add', ofilename])
64-
add_to_sitemap(from_version, to_version)
78+
79+
if not output_dir:
80+
subprocess.check_call(['git', 'rm', 'markdown/snippets/*.md'])
81+
subprocess.check_call(['git', 'add', output])
6582

6683
if __name__ == '__main__':
67-
if len(sys.argv) != 3:
68-
print(sys.argv[0], 'from_version to_version')
69-
sys.exit(1)
70-
FROM_VERSION = sys.argv[1]
71-
TO_VERSION = sys.argv[2]
72-
os.chdir('markdown')
73-
generate(FROM_VERSION, TO_VERSION)
84+
parser = argparse.ArgumentParser(description='Generate meson docs')
85+
parser.add_argument('--input-sitemap', default='sitemap.txt')
86+
parser.add_argument('--output-sitemap', default='sitemap.txt')
87+
parser.add_argument('--source-dir', default='.')
88+
parser.add_argument('--output-dir')
89+
90+
args = parser.parse_args()
91+
92+
if Path(args.source_dir, 'markdown/snippets').glob('*.md'):
93+
relnotes, to_version = add_to_sitemap(args.input_sitemap, args.output_sitemap)
94+
generate(relnotes, to_version, args.source_dir, args.output_dir)
95+
elif args.input_sitemap != args.output_sitemap:
96+
shutil.copyfile(args.input_sitemap, args.output_sitemap)

docs/meson.build

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ docs_gen = custom_target(
1515
build_by_default: true,
1616
install: false)
1717

18+
sitemap = files('sitemap.txt')
19+
1820
genrefman = find_program('./genrefman.py')
1921
refman_binary = custom_target(
2022
'gen_refman_bin',
21-
input: files('sitemap.txt'),
23+
input: sitemap,
2224
output: 'reference_manual.bin',
2325
depfile: 'reman_dep.d',
2426
command: [
@@ -39,14 +41,15 @@ refman_md = custom_target(
3941
genrefman,
4042
'-l', 'pickle',
4143
'-g', 'md',
42-
'-s', files('sitemap.txt'),
44+
'-s', sitemap,
4345
'-i', '@INPUT@',
4446
'-o', '@OUTPUT0@',
4547
'--link-defs', '@OUTPUT1@',
4648
'--force-color',
4749
'--no-modules',
4850
],
4951
)
52+
sitemap = refman_md[0]
5053

5154
refman_json = custom_target(
5255
'gen_refman_json',
@@ -79,14 +82,26 @@ refman_man = custom_target(
7982
],
8083
)
8184

85+
genrelnotes = custom_target(
86+
output: ['sitemap-genrelnotes.txt'],
87+
build_always_stale: true,
88+
command: [find_program('genrelnotes.py'),
89+
'--input-sitemap', sitemap,
90+
'--output-sitemap', '@OUTPUT0@',
91+
'--output-dir', meson.current_build_dir(),
92+
'--source-dir', meson.current_source_dir(),
93+
]
94+
)
95+
sitemap = genrelnotes[0]
96+
8297
test('validate_docs', find_program('./jsonvalidator.py'), args: [refman_json])
8398

8499
hotdoc_prog = find_program('hotdoc', version: '>=0.13.7')
85100

86101
hotdoc = import('hotdoc')
87102
documentation = hotdoc.generate_doc(meson.project_name(),
88103
project_version: meson.project_version(),
89-
sitemap: refman_md[0],
104+
sitemap: sitemap,
90105
build_by_default: true,
91106
depends: docs_gen,
92107
index: 'markdown/index.md',

0 commit comments

Comments
 (0)