Created
March 18, 2018 19:57
-
-
Save inoryy/5cbe43777d678d2074efc04113ebaa7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, re, os | |
DEFAULT_MAIN = 'main.cpp' | |
DEFAULT_OUT = 'arena.cpp' | |
BUNDLE_SYM = '// ###' | |
def bundle(flname, main = False): | |
base = os.path.dirname(flname) | |
if len(base) > 0: base += "/" | |
out = "" | |
with open(flname, 'r') as fl: | |
code = fl.read() | |
includes = re.findall("#include \"(.*\.cpp)\"", code) | |
for inc in includes: | |
code = code.replace("#include \"%s\"\n" % inc, "") | |
inc = base + inc | |
out += bundle(inc) + "\n" | |
if main: | |
out = code.replace(BUNDLE_SYM + "\n", out) | |
else: | |
out += code | |
return out | |
if __name__ == '__main__': | |
args = sys.argv[1:] | |
main = args[0] if len(args) > 0 else DEFAULT_MAIN | |
out = args[1] if len(args) > 0 else DEFAULT_OUT | |
with open(out, 'w') as of: | |
of.write(bundle(main, True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
place
BUNDLE_SYM
(// ###
by default) somewhere in yourmain.cpp
where you want includes pasted in.