aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/preprocess.py
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /build/scripts/preprocess.py
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'build/scripts/preprocess.py')
-rw-r--r--build/scripts/preprocess.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/build/scripts/preprocess.py b/build/scripts/preprocess.py
new file mode 100644
index 00000000000..4657bef732e
--- /dev/null
+++ b/build/scripts/preprocess.py
@@ -0,0 +1,48 @@
+import sys
+import os
+
+
+def load_file(p):
+ with open(p, 'r') as f:
+ return f.read()
+
+
+def step(base, data, hh):
+ def flt():
+ for l in data.split('\n'):
+ if l in hh:
+ pp = os.path.join(base, hh[l])
+
+ yield '\n\n' + load_file(pp) + '\n\n'
+
+ os.unlink(pp)
+ else:
+ yield l
+
+ return '\n'.join(flt())
+
+
+def subst_headers(path, headers):
+ hh = dict()
+
+ for h in headers:
+ hh['# include "' + h + '"'] = h
+
+ data = load_file(path)
+ prev = data
+
+ while True:
+ ret = step(os.path.dirname(path), prev, hh)
+
+ if ret == prev:
+ break
+
+ prev = ret
+
+ if data != prev:
+ with open(path, 'w') as f:
+ f.write(prev)
+
+
+if __name__ == '__main__':
+ subst_headers(sys.argv[1], ['stack.hh', 'position.hh', 'location.hh'])