diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-03-26 10:43:07 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-03-26 10:43:07 -0700 |
commit | c4038a1fc9adba8c1a833717ec3145da98365c09 (patch) | |
tree | 0b6a8d5faabe385a8a100a21e566a50943306b02 | |
parent | bffcb8c7fe594af93749c7313d784b2341ed7532 (diff) |
handle --default-object-ext properly, and other emcc fixes
-rwxr-xr-x | emcc | 30 | ||||
-rw-r--r-- | tests/test_other.py | 15 |
2 files changed, 24 insertions, 21 deletions
@@ -1147,6 +1147,7 @@ try: assert has_source_inputs or has_header_inputs, 'Must have source code or header inputs to use -c' target = target_basename + '.o' final_suffix = 'o' + final_ending = ('.' + final_suffix) if len(final_suffix) > 0 else '' # Find library files for lib in libs: @@ -1353,14 +1354,17 @@ try: sys.exit(1) def get_bitcode_file(input_file): - if final_suffix == 'o': + if final_suffix not in JS_CONTAINING_SUFFIXES: # no need for a temp file, just emit to the right place if len(input_files) == 1: # can just emit directly to the target - if specified_target: return specified_target - return unsuffixed(input_file) + '.' + final_suffix - return unsuffixed(input_file) + '.o' - return in_temp(unsuffixed(uniquename(input_file)) + '.o') + if specified_target: + if specified_target.endswith('/') or specified_target.endswith('\\') or os.path.isdir(specified_target): + return os.path.join(specified_target, os.path.basename(unsuffixed(input_file))) + default_object_extension + return specified_target + return unsuffixed(input_file) + final_ending + return unsuffixed(input_file) + default_object_extension + return in_temp(unsuffixed(uniquename(input_file)) + default_object_extension) # First, generate LLVM bitcode. For each input file, we get base.o with bitcode for input_file in input_files: @@ -1419,26 +1423,18 @@ try: if final_suffix not in JS_CONTAINING_SUFFIXES: if not specified_target: for input_file in input_files: - safe_move(get_bitcode_file(input_file), unsuffixed_basename(input_file) + '.' + final_suffix) + safe_move(get_bitcode_file(input_file), unsuffixed_basename(input_file) + final_ending) else: if len(input_files) == 1: temp_output_base = unsuffixed(get_bitcode_file(input_files[0])) - if specified_target.endswith('/') or specified_target.endswith('\\') or os.path.isdir(specified_target): # User passed '-o <directory' as the location to output to. - obj_output_name = os.path.join(specified_target, os.path.splitext(os.path.basename(input_file))[0] + default_object_extension) - logging.debug('User specified -o <directoryname> as the location of the output. Generating output file ' + obj_output_name) - try: - safe_move(temp_output_base + '.o', obj_output_name) - except IOError, e: - logging.error('Could not write to output file ' + obj_output_name + '. Perhaps the output directory does not exist?') - exit(1) - else: # User passed '-o <filename>' as the location to output to. - safe_move(temp_output_base + '.o', specified_target) + if not specified_target: + safe_move(get_bitcode_file(input_file), unsuffixed_basename(input_file) + final_ending) if os.path.exists(temp_output_base + '.d'): # There was a .d file generated, from -MD or -MMD and friends, save a copy of it to where the output resides, # adjusting the target name away from the temporary file name to the specified target. # It will be deleted with the rest of the temporary directory. deps = open(temp_output_base + '.d').read() - deps = deps.replace(temp_output_base + '.o', specified_target) + deps = deps.replace(temp_output_base + default_object_ext, specified_target) with open(os.path.join(os.path.dirname(specified_target), os.path.basename(unsuffixed(input_files[0]) + '.d')), "w") as out_dep: out_dep.write(deps) else: diff --git a/tests/test_other.py b/tests/test_other.py index 21c9ed25..e5fe49d7 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -65,6 +65,7 @@ Options that are modified or new in %s include: # emcc src.cpp -c and emcc src.cpp -o src.[o|bc] ==> should give a .bc file # regression check: -o js should create "js", with bitcode content for args in [['-c'], ['-o', 'src.o'], ['-o', 'src.bc'], ['-o', 'src.so'], ['-o', 'js']]: + print '-c stuff', args target = args[1] if len(args) == 2 else 'hello_world.o' self.clear() Popen([PYTHON, compiler, path_from_root('tests', 'hello_world' + suffix)] + args, stdout=PIPE, stderr=PIPE).communicate() @@ -943,11 +944,12 @@ This pointer might make sense in another type signature: i: 0 args=['-I' + path_from_root('tests', 'zlib')], suffix='c') def test_symlink(self): + self.clear() if os.name == 'nt': return self.skip('Windows FS does not need to be tested for symlinks support, since it does not have them.') open(os.path.join(self.get_dir(), 'foobar.xxx'), 'w').write('int main(){ return 0; }') os.symlink(os.path.join(self.get_dir(), 'foobar.xxx'), os.path.join(self.get_dir(), 'foobar.c')) - Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'foobar.c'), '-o', os.path.join(self.get_dir(), 'foobar')], stdout=PIPE, stderr=PIPE).communicate() + Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'foobar.c'), '-o', os.path.join(self.get_dir(), 'foobar')]).communicate() assert os.path.exists(os.path.join(self.get_dir(), 'foobar')) try_delete(os.path.join(self.get_dir(), 'foobar')) try_delete(os.path.join(self.get_dir(), 'foobar.xxx')) @@ -955,7 +957,7 @@ This pointer might make sense in another type signature: i: 0 open(os.path.join(self.get_dir(), 'foobar.c'), 'w').write('int main(){ return 0; }') os.symlink(os.path.join(self.get_dir(), 'foobar.c'), os.path.join(self.get_dir(), 'foobar.xxx')) - Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'foobar.xxx'), '-o', os.path.join(self.get_dir(), 'foobar')], stdout=PIPE, stderr=PIPE).communicate() + Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'foobar.xxx'), '-o', os.path.join(self.get_dir(), 'foobar')]).communicate() assert os.path.exists(os.path.join(self.get_dir(), 'foobar')) try_delete(os.path.join(self.get_dir(), 'foobar')) try_delete(os.path.join(self.get_dir(), 'foobar.xxx')) @@ -2294,11 +2296,16 @@ mergeInto(LibraryManager.library, { def test_default_obj_ext(self): outdir = os.path.join(self.get_dir(), 'out_dir') + '/' + + self.clear() os.mkdir(outdir) - process = Popen([PYTHON, EMCC, '-c', path_from_root('tests', 'hello_world.c'), '-o', outdir], stdout=PIPE, stderr=PIPE) + process = Popen([PYTHON, EMCC, '-c', path_from_root('tests', 'hello_world.c'), '-o', outdir]) process.communicate() assert(os.path.isfile(outdir + 'hello_world.o')) - process = Popen([PYTHON, EMCC, '-c', path_from_root('tests', 'hello_world.c'), '-o', outdir, '--default-obj-ext', 'obj'], stdout=PIPE, stderr=PIPE) + + self.clear() + os.mkdir(outdir) + process = Popen([PYTHON, EMCC, '-c', path_from_root('tests', 'hello_world.c'), '-o', outdir, '--default-obj-ext', 'obj']) process.communicate() assert(os.path.isfile(outdir + 'hello_world.obj')) |