mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-12 14:48:40 +01:00
45 lines
1.1 KiB
Python
Executable File
45 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import sys
|
|
from os.path import basename, dirname, join
|
|
import re
|
|
|
|
INCLUDE_PATTERN = re.compile(r'^\s*#include "([\w.]+)"')
|
|
WREN_DIR = dirname(dirname(realpath(__file__)))
|
|
|
|
seen_files = set()
|
|
out = sys.stdout
|
|
|
|
# Prints a plain text file, adding comment markers.
|
|
def add_comment_file(filename):
|
|
with open(filename, 'r') as f:
|
|
for line in f:
|
|
out.write('// ')
|
|
out.write(line)
|
|
|
|
# Prints the given C source file, recursively resolving local #includes.
|
|
def add_file(filename):
|
|
bname = basename(filename)
|
|
# Only include each file at most once.
|
|
if bname in seen_files:
|
|
return
|
|
seen_files.add(bname)
|
|
path = dirname(filename)
|
|
|
|
out.write('// Begin file "{0}"\n'.format(filename))
|
|
with open(filename, 'r') as f:
|
|
for line in f:
|
|
m = INCLUDE_PATTERN.match(line)
|
|
if m:
|
|
add_file(join(path, m.group(1)))
|
|
else:
|
|
out.write(line)
|
|
out.write('// End file "{0}"\n'.format(filename))
|
|
|
|
# Print license on top.
|
|
add_comment_file(join(WREN_DIR, 'LICENSE'))
|
|
out.write('\n')
|
|
# Source files.
|
|
for f in sys.argv[1:]:
|
|
add_file(f)
|