Debian Codegraph @

bin/install-headers.py

raw ◀ ▶
1 Debian patch touch this file
•1 #!/usr/bin/env python3
2
3 import argparse
4 import os, os.path
5 import re
6
7 parser = argparse.ArgumentParser()
8 parser.add_argument("--src", help="Source directory for includes", required=True)
9 parser.add_argument("--dest", help="Destination path for includes", required=True)
10 parser.add_argument("--ignore", help="Ignore files matching regex", action="append")
11 args = parser.parse_args()
12
13 filemode = 0o644
14
15 def update_file(filename):
16 global args, filemode
17
18 if not filename.endswith(".h"):
19 return
20
21 if args.ignore:
22 for i in args.ignore:
23 if re.fullmatch(i, filename):
24 return
25
26 skia_include = re.compile(r'^([ \t]*)# *include *"include/([^"]*)"[ \t]*(//.*)?\n?$')
27 skcms_include = re.compile('^([ \t]*)# *include *"modules/skcms/skcms.h"[ \t]*(//.*)?\n?$')
28
29 dstfile = os.path.join(args.dest, filename[len(args.src):])
30 os.makedirs(os.path.dirname(dstfile), exist_ok=True)
31
32 with open(filename, "r") as src:
33 with open(dstfile, "w") as dst:
34 for line in src:
35 if match := skia_include.fullmatch(line):
36 dst.write("{}#include <skia/{}>\n".format(match[1], match[2]))
37 elif match := skcms_include.fullmatch(line):
38 dst.write("{}#include <skia/skcms.h>\n".format(match[1]))
39 else:
40 dst.write(line)
41
42
43 os.chmod(dstfile, filemode)
44
45 for dirname, dirs, files in os.walk(args.src):
46 for f in files:
47 update_file(os.path.join(dirname, f))