Commit | Line | Data |
---|---|---|
a3dc8f46 PP |
1 | import re |
2 | ||
3 | ||
4 | class _Section: | |
5 | def __init__(self, title, filenames): | |
6 | self.title = title | |
7 | self.filenames = filenames | |
8 | ||
9 | ||
10 | def _get_sections(file): | |
11 | sections = [] | |
12 | cur_title = None | |
13 | cur_filenames = [] | |
14 | ||
15 | for line in file: | |
16 | m = re.match(r'^# (.+API.*)$', line) | |
17 | ||
18 | if m: | |
19 | if cur_filenames: | |
20 | sections.append(_Section(cur_title, cur_filenames)) | |
21 | cur_title = None | |
22 | cur_filenames = [] | |
23 | ||
24 | cur_title = m.group(1) | |
25 | continue | |
26 | ||
71c5da58 | 27 | m = re.match(r'^\s+(babeltrace2/.+\.h).*$', line) |
a3dc8f46 PP |
28 | |
29 | if m: | |
71c5da58 | 30 | if m.group(1) != 'babeltrace2/babeltrace.h': |
a3dc8f46 PP |
31 | cur_filenames.append(m.group(1)) |
32 | ||
33 | continue | |
34 | ||
35 | if re.match(r'^noinst_HEADERS.*', line): | |
36 | break | |
37 | ||
38 | if cur_filenames: | |
39 | sections.append(_Section(cur_title, cur_filenames)) | |
40 | ||
41 | return sections | |
42 | ||
43 | ||
44 | def _c_includes_from_sections(sections): | |
45 | src = '' | |
46 | ||
47 | for section in sections: | |
fb25b9e3 | 48 | # CTF writer is not part of the Babeltrace library |
bf436657 MJ |
49 | if 'ctf' in section.title.lower(): |
50 | continue | |
51 | ||
a3dc8f46 | 52 | src += '/* {} */\n'.format(section.title) |
fb25b9e3 | 53 | lines = [] |
a3dc8f46 PP |
54 | |
55 | for filename in sorted(section.filenames): | |
fb25b9e3 PP |
56 | # not part of the API |
57 | if 'func-status' in filename: | |
58 | continue | |
a3dc8f46 | 59 | |
fb25b9e3 PP |
60 | lines.append('#include <{}>\n'.format(filename)) |
61 | ||
62 | lines.sort() | |
63 | src += ''.join(lines) | |
a3dc8f46 PP |
64 | src += '\n' |
65 | ||
66 | return src[:-1] | |
67 | ||
68 | ||
69 | def _main(): | |
70 | with open('include/Makefile.am') as f: | |
71 | sections = _get_sections(f) | |
72 | ||
73 | print('''#ifndef BABELTRACE_BABELTRACE_H | |
74 | #define BABELTRACE_BABELTRACE_H | |
75 | ||
76 | /* | |
77 | * Babeltrace API | |
78 | * | |
834e9996 | 79 | * Copyright 2010-2018 EfficiOS Inc. <http://www.efficios.com/> |
a3dc8f46 PP |
80 | * |
81 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
82 | * of this software and associated documentation files (the "Software"), to deal | |
83 | * in the Software without restriction, including without limitation the rights | |
84 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
85 | * copies of the Software, and to permit persons to whom the Software is | |
86 | * furnished to do so, subject to the following conditions: | |
87 | * | |
88 | * The above copyright notice and this permission notice shall be included in | |
89 | * all copies or substantial portions of the Software. | |
90 | * | |
91 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
92 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
93 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
94 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
95 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
96 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
97 | * SOFTWARE. | |
98 | */ | |
99 | ''') | |
100 | print(_c_includes_from_sections(sections)) | |
101 | print('#endif /* BABELTRACE_BABELTRACE_H */') | |
102 | ||
fb25b9e3 | 103 | |
a3dc8f46 PP |
104 | if __name__ == '__main__': |
105 | _main() |