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"""
3Wrapper around docutils rst2x commands,
4converting 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
24import os
25import subprocess
26import sys
27
28
29def 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
42argv = sys.argv[1:]
43
44depfile = None
45output = argv[-1]
46
47for opt, optarg in zip(argv, argv[1:]):
48 if opt == '--record-dependencies':
49 depfile = optarg
50
51try:
52 subprocess.run(argv)
53 convert_depfile(output, depfile)
54except:
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
554file2string = find_program(join_paths(tools_directory, 'file2string.py'))554file2string = find_program(join_paths(tools_directory, 'file2string.py'))
555matroska = find_program(join_paths(tools_directory, 'matroska.py'))555matroska = find_program(join_paths(tools_directory, 'matroska.py'))
556version_py = find_program(join_paths(source_root, 'version.py'))556version_py = find_program(join_paths(source_root, 'version.py'))
557docutils_wrapper = find_program(join_paths(tools_directory, 'docutils-wrapper.py'))
557 558
558subdir('generated')559subdir('generated')
559subdir(join_paths('generated', 'etc'))560subdir(join_paths('generated', 'etc'))
@@ -1556,7 +1557,12 @@ if features['manpage-build'] · 996 unmodified lines
1556 custom_target('manpages',1557 custom_target('manpages',
1557 input: manpage,1558 input: manpage,
1558 output: 'mpv.1',1559 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',
1560 install: true,1566 install: true,
1561 install_dir: join_paths(mandir, 'man1')1567 install_dir: join_paths(mandir, 'man1')
1562 )1568 )
@@ -1569,7 +1575,11 @@ if features['html-build'] · 6 unmodified lines
1569 custom_target('html-manpages',1575 custom_target('html-manpages',
1570 input: manpage,1576 input: manpage,
1571 output: 'mpv.html',1577 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',
1573 install: true,1583 install: true,
1574 install_dir: join_paths(datadir, 'doc', 'mpv')1584 install_dir: join_paths(datadir, 'doc', 'mpv')
1575 )1585 )

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