aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-04-07 20:42:02 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-04-07 20:42:02 -0700
commitae1cb6d7eca0bffcfae0f923dd2dd6d7ed8037ca (patch)
treea3ab3df08a53fc41f93d42aac748670c2355067c
parent7af9a2d81c1c3fe1711c1d6a9b702aaab44ef67a (diff)
handle identical basenames in emcc properly; fixes #287
-rwxr-xr-xemcc17
-rwxr-xr-xtests/runner.py33
2 files changed, 45 insertions, 5 deletions
diff --git a/emcc b/emcc
index 2aea1d4f..fb215a60 100755
--- a/emcc
+++ b/emcc
@@ -341,6 +341,13 @@ def unsuffixed(name):
def unsuffixed_basename(name):
return os.path.basename(unsuffixed(name))
+seen_names = {}
+def unsuffixed_uniquename(name):
+ ret = unsuffixed_basename(name)
+ if name not in seen_names:
+ seen_names[name] = str(len(seen_names))
+ return ret + '_' + seen_names[name]
+
# ---------------- End configs -------------
if len(sys.argv) == 1 or sys.argv[1] in ['x', 't']:
@@ -641,7 +648,7 @@ try:
for input_file in input_files:
if input_file.endswith(SOURCE_SUFFIXES):
if DEBUG: print >> sys.stderr, 'emcc: compiling source file: ', input_file
- output_file = in_temp(unsuffixed_basename(input_file) + '.o')
+ output_file = in_temp(unsuffixed_uniquename(input_file) + '.o')
temp_files.append(output_file)
args = newargs + ['-emit-llvm', '-c', input_file, '-o', output_file]
if DEBUG: print >> sys.stderr, "emcc running:", call, ' '.join(args)
@@ -652,7 +659,7 @@ try:
else: # bitcode
if input_file.endswith(BITCODE_SUFFIXES):
if DEBUG: print >> sys.stderr, 'emcc: copying bitcode file: ', input_file
- temp_file = in_temp(unsuffixed_basename(input_file) + '.o')
+ temp_file = in_temp(unsuffixed_uniquename(input_file) + '.o')
shutil.copyfile(input_file, temp_file)
temp_files.append(temp_file)
elif input_file.endswith(DYNAMICLIB_SUFFIXES) or shared.Building.is_ar(input_file):
@@ -665,7 +672,7 @@ try:
# Note that by assembling the .ll file, then disassembling it later, we will
# remove annotations which is a good thing for compilation time
if DEBUG: print >> sys.stderr, 'emcc: assembling assembly file: ', input_file
- temp_file = in_temp(unsuffixed_basename(input_file) + '.o')
+ temp_file = in_temp(unsuffixed_uniquename(input_file) + '.o')
shared.Building.llvm_as(input_file, temp_file)
temp_files.append(temp_file)
@@ -677,10 +684,10 @@ try:
print >> sys.stderr, 'emcc: warning: -Ox flags ignored, since not generating JavaScript'
if not specified_target:
for input_file in input_files:
- shutil.move(in_temp(unsuffixed_basename(input_file) + '.o'), unsuffixed_basename(input_file) + '.' + final_suffix)
+ shutil.move(in_temp(unsuffixed_uniquename(input_file) + '.o'), unsuffixed_basename(input_file) + '.' + final_suffix)
else:
if len(input_files) == 1:
- shutil.move(in_temp(unsuffixed_basename(input_files[0]) + '.o'), specified_target)
+ shutil.move(in_temp(unsuffixed_uniquename(input_files[0]) + '.o'), specified_target)
else:
assert not has_dash_c, 'fatal error: cannot specify -o with -c with multiple files' + str(sys.argv)
# We have a specified target (-o <target>), which is not JavaScript or HTML, and
diff --git a/tests/runner.py b/tests/runner.py
index 7479aaf0..03ec803f 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -6366,6 +6366,39 @@ f.close()
Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), os.path.join(self.get_dir(), 'subdir', 'libfile.so'), '-L.']).communicate()
self.assertContained('hello from lib', run_js(os.path.join(self.get_dir(), 'a.out.js')))
+ def test_identical_basenames(self):
+ # Issue 287: files in different dirs but with the same basename get confused as the same,
+ # causing multiply defined symbol errors
+ try:
+ os.makedirs(os.path.join(self.get_dir(), 'foo'));
+ except:
+ pass
+ try:
+ os.makedirs(os.path.join(self.get_dir(), 'bar'));
+ except:
+ pass
+ open(os.path.join(self.get_dir(), 'foo', 'main.cpp'), 'w').write('''
+ extern void printey();
+ int main() {
+ printey();
+ return 0;
+ }
+ ''')
+ open(os.path.join(self.get_dir(), 'bar', 'main.cpp'), 'w').write('''
+ #include<stdio.h>
+ void printey() { printf("hello there\\n"); }
+ ''')
+
+ Popen(['python', EMCC, os.path.join(self.get_dir(), 'foo', 'main.cpp'), os.path.join(self.get_dir(), 'bar', 'main.cpp')]).communicate()
+ self.assertContained('hello there', run_js(os.path.join(self.get_dir(), 'a.out.js')))
+
+ # ditto with first creating .o files
+ try_delete(os.path.join(self.get_dir(), 'a.out.js'))
+ Popen(['python', EMCC, os.path.join(self.get_dir(), 'foo', 'main.cpp'), '-o', os.path.join(self.get_dir(), 'foo', 'main.o')]).communicate()
+ Popen(['python', EMCC, os.path.join(self.get_dir(), 'bar', 'main.cpp'), '-o', os.path.join(self.get_dir(), 'bar', 'main.o')]).communicate()
+ Popen(['python', EMCC, os.path.join(self.get_dir(), 'foo', 'main.o'), os.path.join(self.get_dir(), 'bar', 'main.o')]).communicate()
+ self.assertContained('hello there', 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'''