MakeSingleHeader.py
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# Requires Python 3.6
from plumbum import local, cli, FG
import re
includes_local = re.compile(r"""^#include "(.*)"$""", re.MULTILINE)
includes_system = re.compile(r"""^#include \<(.*)\>$""", re.MULTILINE)
DIR = local.path(__file__).dirname
BDIR = DIR / '../include'
class MakeHeader(cli.Application):
def main(self, out : cli.NonexistentPath = BDIR / 'CLI11.hpp'):
main_header = BDIR / 'CLI/CLI.hpp'
header = main_header.read()
include_files = includes_local.findall(header)
headers = set()
output = ''
with open('output.hpp', 'w') as f:
for inc in include_files:
inner = (BDIR / inc).read()
headers |= set(includes_system.findall(inner))
output += f'\n// From {inc}\n\n'
output += inner[inner.find('namespace'):]
header_list = '\n'.join(f'#include <{h}>' for h in headers)
output = f'''\
#pragma once
// Distributed under the LGPL version 3.0 license. See accompanying
// file LICENSE or https://github.com/henryiii/CLI11 for details.
// This file was generated using MakeSingleHeader.py in CLI11/scripts
// This has the complete CLI library in one file.
{header_list}
{output}'''
with out.open('w') as f:
f.write(output)
print(f"Created {out}")
if __name__ == '__main__':
MakeHeader()