diff options
-rw-r--r-- | emlink.py | 15 | ||||
-rwxr-xr-x | tests/runner.py | 17 |
2 files changed, 25 insertions, 7 deletions
@@ -56,7 +56,7 @@ class AsmModule(): self.imports = {} for imp in js_optimizer.import_sig.finditer(self.imports_js): key, value = imp.group(0).split('var ')[1][:-1].split('=', 1) - self.imports[key] = value + self.imports[key.strip()] = value.strip() #print >> sys.stderr, 'imports', self.imports # funcs @@ -124,19 +124,20 @@ class AsmModule(): del all_sendings[key] # import of external value no longer needed main.imports_js = '\n'.join(['var %s = %s;' % (key, value) for key, value in all_imports.iteritems()]) + '\n' - if added_sending: - sendings_js = ', '.join(['%s: %s' % (key, value) for key, value in all_sendings.iteritems()]) - sendings_start = main.post_js.find('}, { ')+5 - sendings_end = main.post_js.find(' }, buffer);') - main.post_js = main.post_js[:sendings_start] + sendings_js + main.post_js[sendings_end:] - # check for undefined references to global variables def check_import(key, value): if value.startswith('+') or value.endswith('|0'): # ignore functions if key not in all_sendings: print >> sys.stderr, 'warning: external variable %s is still not defined after linking' % key + all_sendings[key] = '0' for key, value in all_imports.iteritems(): check_import(key, value) + if added_sending: + sendings_js = ', '.join(['%s: %s' % (key, value) for key, value in all_sendings.iteritems()]) + sendings_start = main.post_js.find('}, { ')+5 + sendings_end = main.post_js.find(' }, buffer);') + main.post_js = main.post_js[:sendings_start] + sendings_js + main.post_js[sendings_end:] + # tables f_bases = {} f_sizes = {} diff --git a/tests/runner.py b/tests/runner.py index c813a921..a4b396f2 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -11034,6 +11034,23 @@ f.close() std::string side() { return "and hello from side"; } ''', ['hello from main and hello from side\n']) + # followup to iostream test: a second linking + print 'second linking of a linking output' + open('moar.cpp', 'w').write(r''' + #include <iostream> + struct Moar { + Moar() { std::cout << "moar!" << std::endl; } + }; + Moar m; + ''') + Popen([PYTHON, EMCC, 'moar.cpp', '-o', 'moar.js', '-s', 'SIDE_MODULE=1', '-O2']).communicate() + Popen([PYTHON, EMLINK, 'together.js', 'moar.js', 'triple.js'], stdout=PIPE).communicate() + assert os.path.exists('triple.js') + for engine in JS_ENGINES: + out = run_js('triple.js', engine=engine, stderr=PIPE, full_output=True) + self.assertContained('moar!\nhello from main and hello from side\n', out) + if engine == SPIDERMONKEY_ENGINE: self.validate_asmjs(out) + # zlib compression library. tests function pointers in initializers and many other things test('zlib', '', open(path_from_root('tests', 'zlib', 'example.c'), 'r').read(), self.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a']), |