diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2022-05-11 09:58:42 -0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2022-05-24 20:19:46 +0300 |
commit | c88c1e7dba168e62fe52f677717ec75ceaa84d5c (patch) | |
tree | 7d9a99f4a8b2cf2f1fc8bd8edd55da1531c06569 /docs | |
parent | 5746469e45f6e380eedb62a7b030d4e3cb45b116 (diff) | |
download | meson-c88c1e7dba168e62fe52f677717ec75ceaa84d5c.zip meson-c88c1e7dba168e62fe52f677717ec75ceaa84d5c.tar.gz meson-c88c1e7dba168e62fe52f677717ec75ceaa84d5c.tar.bz2 |
doc: Generate dev release notes
Diffstat (limited to 'docs')
-rwxr-xr-x | docs/genrelnotes.py | 79 | ||||
-rw-r--r-- | docs/meson.build | 21 |
2 files changed, 69 insertions, 31 deletions
diff --git a/docs/genrelnotes.py b/docs/genrelnotes.py index 082ab45..abad3cc 100755 --- a/docs/genrelnotes.py +++ b/docs/genrelnotes.py @@ -16,10 +16,11 @@ ''' Generates release notes for new releases of Meson build system ''' +import argparse import subprocess -import sys -import os -from glob import glob +import re +import shutil +from pathlib import Path RELNOTE_TEMPLATE = '''--- title: Release {} @@ -31,43 +32,65 @@ short-description: Release notes for {} ''' -def add_to_sitemap(from_version, to_version): +def add_to_sitemap(sitemap, output_sitemap): ''' Adds release note entry to sitemap.txt. ''' - sitemapfile = '../sitemap.txt' - s_f = open(sitemapfile, encoding='utf-8') - lines = s_f.readlines() - s_f.close() - with open(sitemapfile, 'w', encoding='utf-8') as s_f: + sitemapfile = Path(sitemap) + with sitemapfile.open(encoding='utf-8') as s_f: + lines = s_f.readlines() + relnotes = None + to_version = None + output = Path(output_sitemap) + output.parent.mkdir(exist_ok=True, parents=True) + with output.open('w', encoding='utf-8') as s_f: for line in lines: - if 'Release-notes' in line and from_version in line: - new_line = line.replace(from_version, to_version) - s_f.write(new_line) + if relnotes is None: + m = re.match(r'[\s]*Release-notes-for-([0-9]+)\.([0-9]+)\.([0-9]+)\.md', line) + if m: + from_version = f'{m[1]}.{m[2]}.{m[3]}' + to_version = f'{m[1]}.{int(m[2]) + 1}.{m[3]}' + new_line = line.replace(from_version, to_version) + relnotes = new_line.strip() + s_f.write(new_line) s_f.write(line) -def generate(from_version, to_version): + if sitemapfile == output: + subprocess.check_call(['git', 'add', output]) + + return relnotes, to_version + +def generate(relnotes, to_version, source_dir, output_dir): ''' Generate notes for Meson build next release. ''' - ofilename = f'Release-notes-for-{to_version}.md' - with open(ofilename, 'w', encoding='utf-8') as ofile: - ofile.write(RELNOTE_TEMPLATE.format(to_version, to_version)) - for snippetfile in glob('snippets/*.md'): - snippet = open(snippetfile, encoding='utf-8').read() + release = f'{to_version} (in development)' if output_dir else to_version + output = Path(output_dir, relnotes) if output_dir else Path('markdown', relnotes) + output.parent.mkdir(exist_ok=True, parents=True) + with output.open('w', encoding='utf-8') as ofile: + ofile.write(RELNOTE_TEMPLATE.format(release, to_version)) + for snippetfile in Path(source_dir, 'markdown/snippets').glob('*.md'): + snippet = snippetfile.read_text(encoding='utf-8') ofile.write(snippet) if not snippet.endswith('\n'): ofile.write('\n') ofile.write('\n') - subprocess.check_call(['git', 'rm', snippetfile]) - subprocess.check_call(['git', 'add', ofilename]) - add_to_sitemap(from_version, to_version) + + if not output_dir: + subprocess.check_call(['git', 'rm', 'markdown/snippets/*.md']) + subprocess.check_call(['git', 'add', output]) if __name__ == '__main__': - if len(sys.argv) != 3: - print(sys.argv[0], 'from_version to_version') - sys.exit(1) - FROM_VERSION = sys.argv[1] - TO_VERSION = sys.argv[2] - os.chdir('markdown') - generate(FROM_VERSION, TO_VERSION) + parser = argparse.ArgumentParser(description='Generate meson docs') + parser.add_argument('--input-sitemap', default='sitemap.txt') + parser.add_argument('--output-sitemap', default='sitemap.txt') + parser.add_argument('--source-dir', default='.') + parser.add_argument('--output-dir') + + args = parser.parse_args() + + if Path(args.source_dir, 'markdown/snippets').glob('*.md'): + relnotes, to_version = add_to_sitemap(args.input_sitemap, args.output_sitemap) + generate(relnotes, to_version, args.source_dir, args.output_dir) + elif args.input_sitemap != args.output_sitemap: + shutil.copyfile(args.input_sitemap, args.output_sitemap) diff --git a/docs/meson.build b/docs/meson.build index c486103..a14055c 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -15,10 +15,12 @@ docs_gen = custom_target( build_by_default: true, install: false) +sitemap = files('sitemap.txt') + genrefman = find_program('./genrefman.py') refman_binary = custom_target( 'gen_refman_bin', - input: files('sitemap.txt'), + input: sitemap, output: 'reference_manual.bin', depfile: 'reman_dep.d', command: [ @@ -39,7 +41,7 @@ refman_md = custom_target( genrefman, '-l', 'pickle', '-g', 'md', - '-s', files('sitemap.txt'), + '-s', sitemap, '-i', '@INPUT@', '-o', '@OUTPUT0@', '--link-defs', '@OUTPUT1@', @@ -47,6 +49,7 @@ refman_md = custom_target( '--no-modules', ], ) +sitemap = refman_md[0] refman_json = custom_target( 'gen_refman_json', @@ -79,6 +82,18 @@ refman_man = custom_target( ], ) +genrelnotes = custom_target( + output: ['sitemap-genrelnotes.txt'], + build_always_stale: true, + command: [find_program('genrelnotes.py'), + '--input-sitemap', sitemap, + '--output-sitemap', '@OUTPUT0@', + '--output-dir', meson.current_build_dir(), + '--source-dir', meson.current_source_dir(), + ] +) +sitemap = genrelnotes[0] + test('validate_docs', find_program('./jsonvalidator.py'), args: [refman_json]) hotdoc_prog = find_program('hotdoc', version: '>=0.13.7') @@ -86,7 +101,7 @@ hotdoc_prog = find_program('hotdoc', version: '>=0.13.7') hotdoc = import('hotdoc') documentation = hotdoc.generate_doc(meson.project_name(), project_version: meson.project_version(), - sitemap: refman_md[0], + sitemap: sitemap, build_by_default: true, depends: docs_gen, index: 'markdown/index.md', |