1
0
forked from Mirror/wren

Repaired amalgamation script

The amalgamation script now searches for files in the different
directories of src.

Also the full paths in the amalgamation were replaced by the basename
to produce the same content on all machines.

The makefile now creates the build directory for the amalgamation
if it does not exist.
This commit is contained in:
Lukas Joeressen
2018-05-12 09:14:27 +02:00
parent 40c927f440
commit abd1cf37c4
2 changed files with 21 additions and 6 deletions

View File

@ -101,7 +101,8 @@ gh-pages: docs
$(V) cp -r build/docs/. build/gh-pages
# Build amalgamation of all Wren library files.
amalgamation: src/include/wren.h src/vm/*.h src/vm/*.c
amalgamation: src/include/wren.h src/vm/*.h src/vm/*.c src/optional/*.h src/vm/*.c
mkdir -p build
./util/generate_amalgamation.py > build/wren.c
.PHONY: all amalgamation builtin clean debug docs gh-pages release test vm watchdocs ci ci_32 ci_64

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
import sys
from os.path import basename, dirname, join, realpath
from os.path import basename, dirname, join, realpath, isfile
from glob import iglob
import re
@ -12,6 +12,18 @@ WREN_DIR = dirname(dirname(realpath(__file__)))
seen_files = set()
out = sys.stdout
# Find a file in the different folders of the src dir.
def find_file(filename):
names = [
join(WREN_DIR, 'src', 'include', filename),
join(WREN_DIR, 'src', 'vm', filename),
join(WREN_DIR, 'src', 'optional', filename),
]
for f in names:
if isfile(f):
return f
raise Exception('File "{0}" not found!'.format(filename))
# Prints a plain text file, adding comment markers.
def add_comment_file(filename):
with open(filename, 'r') as f:
@ -26,19 +38,18 @@ def add_file(filename):
if bname in seen_files:
return
once = False
path = dirname(filename)
out.write('// Begin file "{0}"\n'.format(filename))
out.write('// Begin file "{0}"\n'.format(bname))
with open(filename, 'r') as f:
for line in f:
m = INCLUDE_PATTERN.match(line)
if m:
add_file(join(path, m.group(1)))
add_file(find_file(m.group(1)))
else:
out.write(line)
if GUARD_PATTERN.match(line):
once = True
out.write('// End file "{0}"\n'.format(filename))
out.write('// End file "{0}"\n'.format(bname))
# Only skip header files which use #ifndef guards.
# This is necessary because of the X Macro technique.
@ -57,3 +68,6 @@ add_file(join(WREN_DIR, 'src', 'vm', 'wren_debug.h'))
for f in iglob(join(WREN_DIR, 'src', 'vm', '*.c')):
add_file(f)
for f in iglob(join(WREN_DIR, 'src', 'optional', '*.c')):
add_file(f)