History

meson: dynamically compute dependencies for manpage and html build

This allows us to rebuild the manpages and html documentation only when necessary. It is not necessary to manually keep the list of dependencies up to date. Unfortunately rst2pdf does not yet support this feature, see https://github.com/rst2pdf/rst2pdf/issues/1108

Thomas Weißschuh committed 3 years ago

Commit 8a0fa621 parent c8a90002 files · +68 −2Browse files

Unified · Split

2 files
  1. TOOLS/docutils-wrapper.py +56 −0
  2. meson.build +12 −2
TOOLS/docutils-wrapper.py+56−0
@@ -0,0 +1,56 @@
1+#!/usr/bin/env python3
2+"""
3+Wrapper around docutils rst2x commands,
4+converting their dependency files to a format understood by meson/ninja.
5+"""
6+
7+#
8+# This file is part of mpv.
9+#
10+# mpv is free software; you can redistribute it and/or
11+# modify it under the terms of the GNU Lesser General Public
12+# License as published by the Free Software Foundation; either
13+# version 2.1 of the License, or (at your option) any later version.
14+#
15+# mpv is distributed in the hope that it will be useful,
16+# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+# GNU Lesser General Public License for more details.
19+#
20+# You should have received a copy of the GNU Lesser General Public
21+# License along with mpv. If not, see <http://www.gnu.org/licenses/>.
22+#
23+
24+import os
25+import subprocess
26+import sys
27+
28+
29+def convert_depfile(output, depfile):
30+ with open(depfile, 'r') as f:
31+ deps = f.readlines()
32+
33+ with open(depfile, 'w') as f:
34+ f.write(os.path.abspath(output))
35+ f.write(': \\\n')
36+ for dep in deps:
37+ dep = dep[:-1]
38+ f.write('\t')
39+ f.write(os.path.abspath(dep))
40+ f.write(' \\\n')
41+
42+argv = sys.argv[1:]
43+
44+depfile = None
45+output = argv[-1]
46+
47+for opt, optarg in zip(argv, argv[1:]):
48+ if opt == '--record-dependencies':
49+ depfile = optarg
50+
51+try:
52+ subprocess.run(argv)
53+ convert_depfile(output, depfile)
54+except:
55+ os.remove(output)
56+ os.remove(depfile)
meson.build+12−2
@@ -554,6 +554,7 @@ tools_directory = join_paths(source_root, 'TOOLS') · 553 unmodified lines
554554 file2string = find_program(join_paths(tools_directory, 'file2string.py'))
555555 matroska = find_program(join_paths(tools_directory, 'matroska.py'))
556556 version_py = find_program(join_paths(source_root, 'version.py'))
557+docutils_wrapper = find_program(join_paths(tools_directory, 'docutils-wrapper.py'))
557558
558559 subdir('generated')
559560 subdir(join_paths('generated', 'etc'))
@@ -1556,7 +1557,12 @@ if features['manpage-build'] · 996 unmodified lines
15561557 custom_target('manpages',
15571558 input: manpage,
15581559 output: 'mpv.1',
1559− command: [rst2man, '--strip-elements-with-class=contents', '@INPUT@', '@OUTPUT@'],
1560+ command: [
1561+ docutils_wrapper, rst2man,
1562+ '--record-dependencies', '@DEPFILE@',
1563+ '--strip-elements-with-class=contents',
1564+ '@INPUT@', '@OUTPUT@'],
1565+ depfile: 'mpv.1.dep',
15601566 install: true,
15611567 install_dir: join_paths(mandir, 'man1')
15621568 )
@@ -1569,7 +1575,11 @@ if features['html-build'] · 6 unmodified lines
15691575 custom_target('html-manpages',
15701576 input: manpage,
15711577 output: 'mpv.html',
1572− command: [rst2html, '@INPUT@', '@OUTPUT@'],
1578+ command: [
1579+ docutils_wrapper, rst2html,
1580+ '--record-dependencies', '@DEPFILE@',
1581+ '@INPUT@', '@OUTPUT@'],
1582+ depfile: 'mpv.html.dep',
15731583 install: true,
15741584 install_dir: join_paths(datadir, 'doc', 'mpv')
15751585 )

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t