allow multiple pre-js and post-js

This commit is contained in:
Alon Zakai 2012-06-17 13:24:22 -07:00
Родитель 8f371ae5c3
Коммит 8140488533
2 изменённых файлов: 24 добавлений и 5 удалений

10
emcc
Просмотреть файл

@ -409,8 +409,8 @@ try:
llvm_lto = None
closure = None
js_transform = None
pre_js = None
post_js = None
pre_js = ''
post_js = ''
minify_whitespace = None
preload_files = []
embed_files = []
@ -452,12 +452,12 @@ try:
newargs[i+1] = ''
elif newargs[i].startswith('--pre-js'):
check_bad_eq(newargs[i])
pre_js = open(newargs[i+1]).read()
pre_js += open(newargs[i+1]).read() + '\n'
newargs[i] = ''
newargs[i+1] = ''
elif newargs[i].startswith('--post-js'):
check_bad_eq(newargs[i])
post_js = open(newargs[i+1]).read()
post_js += open(newargs[i+1]).read() + '\n'
newargs[i] = ''
newargs[i+1] = ''
elif newargs[i].startswith('--minify'):
@ -860,7 +860,7 @@ try:
if DEBUG: print >> sys.stderr, 'emcc: applying pre/postjses'
src = open(final).read()
final += '.pp.js'
open(final, 'w').write((pre_js or '') + src + (post_js or ''))
open(final, 'w').write(pre_js + src + post_js)
if DEBUG: save_intermediate('pre-post')
# Apply a source code transformation, if requested

Просмотреть файл

@ -7028,6 +7028,25 @@ f.close()
open(os.path.join(self.get_dir(), 'a.out.js'), 'w').write(src)
assert 'hello from main' in run_js(os.path.join(self.get_dir(), 'a.out.js')), 'main should print when called manually'
def test_prepost2(self):
open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write('''
#include <stdio.h>
int main() {
printf("hello from main\\n");
return 0;
}
''')
open(os.path.join(self.get_dir(), 'pre.js'), 'w').write('''
var Module = {
preRun: function() { Module.print('pre-run') },
};
''')
open(os.path.join(self.get_dir(), 'pre2.js'), 'w').write('''
Module.postRun = function() { Module.print('post-run') };
''')
Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'pre.js', '--pre-js', 'pre2.js']).communicate()
self.assertContained('pre-run\nhello from main\npost-run\n', run_js(os.path.join(self.get_dir(), 'a.out.js')))
def test_eliminator(self):
input = open(path_from_root('tools', 'eliminator', 'eliminator-test.js')).read()
expected = open(path_from_root('tools', 'eliminator', 'eliminator-test-output.js')).read()