Skip to content

Instantly share code, notes, and snippets.

@inoryy
Created March 18, 2018 19:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inoryy/5cbe43777d678d2074efc04113ebaa7a to your computer and use it in GitHub Desktop.
Save inoryy/5cbe43777d678d2074efc04113ebaa7a to your computer and use it in GitHub Desktop.
#!/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))
@inoryy
Copy link
Author

inoryy commented Mar 18, 2018

place BUNDLE_SYM (// ### by default) somewhere in your main.cpp where you want includes pasted in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment