Skip to content

Commit a47773c

Browse files
committed
Update make_headers.py
1 parent 96c2659 commit a47773c

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

tools/make_headers.py

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
from pathlib import Path, PurePosixPath
2+
from collections import defaultdict
23

4+
include_root = Path('include')
5+
sampapi_includes = include_root / 'sampapi'
36

4-
base_path = Path('sampapi')
5-
src_path = base_path / 'src'
7+
includes = defaultdict(lambda: [])
8+
for dir in sampapi_includes.iterdir():
9+
for path in dir.glob('**/*.h'):
10+
header_path = sampapi_includes / path.name
11+
include_str = str(PurePosixPath(path.relative_to(include_root)))
12+
includes[header_path].append(f'#include "{include_str}"\n')
613

7-
def add_include(header_path, include_path):
8-
header_exists = header_path.exists()
9-
with open(header_path, 'a') as f:
10-
if not header_exists:
11-
f.write('#pragma once\n\n')
12-
include_str = str(PurePosixPath(include_path.relative_to(base_path)))
13-
f.write(f'#include "{include_str}"\n')
14+
for path in sampapi_includes.glob('*.h'):
15+
if path not in includes:
16+
print('[common]', path)
1417

15-
for f in base_path.glob('*.h'):
16-
f.unlink()
17-
18-
add_include(base_path / 'sampapi.h', src_path / 'common/sampapi.h')
19-
for path in src_path.glob('**/*.h'):
20-
if path.name == 'sampapi.h':
21-
continue
22-
header_path = base_path / path.name
23-
add_include(header_path, path)
18+
for path, inc_list in includes.items():
19+
with path.open('w') as f:
20+
f.write('#pragma once\n' + ''.join(inc_list))

0 commit comments

Comments
 (0)