aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-07-23 16:47:02 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-07-23 16:47:02 -0700
commit80a58685b5b3c1b9eac75615fcfde3169ed79eb2 (patch)
tree8be6daabb222e508d9358f898fabf981e463973a
parent463a7b1af8320da72c2b32289c911f25ccf54330 (diff)
always look for main in .a files
-rwxr-xr-xtests/runner.py28
-rw-r--r--tools/shared.py2
2 files changed, 29 insertions, 1 deletions
diff --git a/tests/runner.py b/tests/runner.py
index af910b2a..26110b59 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -7046,6 +7046,34 @@ f.close()
err = Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), os.path.join(self.get_dir(), 'side.cpp'), '--remove-duplicates'], stderr=PIPE).communicate()[1]
self.assertContained('bye bye', run_js(os.path.join(self.get_dir(), 'a.out.js')))
+ def test_main_a(self):
+ # if main() is in a .a, we need to pull in that .a
+
+ main_name = os.path.join(self.get_dir(), 'main.c')
+ open(main_name, 'w').write(r'''
+ #include <stdio.h>
+ extern int f();
+ int main() {
+ printf("result: %d.\n", f());
+ return 0;
+ }
+ ''')
+
+ other_name = os.path.join(self.get_dir(), 'other.c')
+ open(other_name, 'w').write(r'''
+ #include <stdio.h>
+ int f() { return 12346; }
+ ''')
+
+ Popen(['python', EMCC, main_name, '-c', '-o', main_name+'.bc']).communicate()
+ Popen(['python', EMCC, other_name, '-c', '-o', other_name+'.bc']).communicate()
+
+ Popen(['python', EMAR, 'cr', main_name+'.a', main_name+'.bc']).communicate()
+
+ Popen(['python', EMCC, other_name+'.bc', main_name+'.a']).communicate()
+
+ self.assertContained('result: 12346.', run_js(os.path.join(self.get_dir(), 'a.out.js')))
+
def test_embed_file(self):
open(os.path.join(self.get_dir(), 'somefile.txt'), 'w').write('''hello from a file with lots of data and stuff in it thank you very much''')
open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(r'''
diff --git a/tools/shared.py b/tools/shared.py
index 3ddf6f47..a74e64b2 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -557,7 +557,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
@staticmethod
def link(files, target, remove_duplicates=False):
actual_files = []
- unresolved_symbols = set() # necessary for .a linking, see below
+ unresolved_symbols = set(['main']) # tracking unresolveds is necessary for .a linking, see below. (and main is always a necessary symbol)
resolved_symbols = set()
temp_dir = None
for f in files: