#!/usr/bin/env python3 import argparse import os, os.path import re parser = argparse.ArgumentParser() parser.add_argument("--src", help="Source directory for includes", required=True) parser.add_argument("--dest", help="Destination path for includes", required=True) parser.add_argument("--ignore", help="Ignore files matching regex", action="append") args = parser.parse_args() filemode = 0o644 def update_file(filename): global args, filemode if not filename.endswith(".h"): return if args.ignore: for i in args.ignore: if re.fullmatch(i, filename): return skia_include = re.compile(r'^([ \t]*)# *include *"include/([^"]*)"[ \t]*(//.*)?\n?$') skcms_include = re.compile('^([ \t]*)# *include *"modules/skcms/skcms.h"[ \t]*(//.*)?\n?$') dstfile = os.path.join(args.dest, filename[len(args.src):]) os.makedirs(os.path.dirname(dstfile), exist_ok=True) with open(filename, "r") as src: with open(dstfile, "w") as dst: for line in src: if match := skia_include.fullmatch(line): dst.write("{}#include \n".format(match[1], match[2])) elif match := skcms_include.fullmatch(line): dst.write("{}#include \n".format(match[1])) else: dst.write(line) os.chmod(dstfile, filemode) for dirname, dirs, files in os.walk(args.src): for f in files: update_file(os.path.join(dirname, f))