diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-11-18 14:13:02 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-11-18 14:13:02 -0800 |
commit | 9f5a01e4785f11b2385064eed678cbfda9fa41ae (patch) | |
tree | 8a0397dd7e59443af5d2199854ca39a844db8477 | |
parent | 61de2f8971271c9412174d67932d64d228e42eaf (diff) | |
parent | e4ce6ee11b5048404c71065e8253b34e7eb8dd29 (diff) |
Merge pull request #1831 from dinibu/dependency-fix-1820
Further changes for issue #1732
-rwxr-xr-x | emcc | 11 | ||||
-rw-r--r-- | tests/test_other.py | 24 | ||||
-rw-r--r-- | tools/shared.py | 2 |
3 files changed, 35 insertions, 2 deletions
@@ -1274,7 +1274,16 @@ try: 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(uniquename(input_files[0])) + '.o'), specified_target) + temp_output_base = in_temp(unsuffixed(uniquename(input_files[0]))) + shutil.move(temp_output_base + '.o', specified_target) + 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) + 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: assert len(original_input_files) == 1 or not has_dash_c, 'fatal error: cannot specify -o with -c with multiple files' + str(sys.argv) + ':' + str(original_input_files) # We have a specified target (-o <target>), which is not JavaScript or HTML, and diff --git a/tests/test_other.py b/tests/test_other.py index 0dd0bd12..1144ec26 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2074,3 +2074,27 @@ int main() Popen([PYTHON, EMCC, path_from_root('tests', 'linpack.c'), '-O2', '-DSP', '--llvm-opts', '''['-O3', '-vectorize', '-vectorize-loops', '-bb-vectorize-vector-bits=128', '-force-vector-width=4']''']).communicate() self.assertContained('Unrolled Single Precision', run_js('a.out.js')) + def test_dependency_file(self): + # Issue 1732: -MMD (and friends) create dependency files that need to be + # copied from the temporary directory. + + open(os.path.join(self.get_dir(), 'test.cpp'), 'w').write(r''' + #include "test.hpp" + + void my_function() + { + } + ''') + open(os.path.join(self.get_dir(), 'test.hpp'), 'w').write(r''' + void my_function(); + ''') + + Popen([PYTHON, EMCC, '-MMD', '-c', os.path.join(self.get_dir(), 'test.cpp'), '-o', + os.path.join(self.get_dir(), 'test.o')]).communicate() + + assert os.path.exists(os.path.join(self.get_dir(), 'test.d')), 'No dependency file generated' + deps = open(os.path.join(self.get_dir(), 'test.d')).read() + head, tail = deps.split( ':', 2 ) + assert 'test.o' in head, 'Invalid dependency target' + assert 'test.cpp' in tail and 'test.hpp' in tail, 'Invalid dependencies generated' + diff --git a/tools/shared.py b/tools/shared.py index 0a6740b9..ba476883 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1029,7 +1029,7 @@ class Building: dirname = os.path.dirname(content) if dirname and not os.path.exists(dirname): os.makedirs(dirname) - Popen([LLVM_AR, 'x', f], stdout=PIPE).communicate() # if absolute paths, files will appear there. otherwise, in this directory + Popen([LLVM_AR, 'xo', f], stdout=PIPE).communicate() # if absolute paths, files will appear there. otherwise, in this directory contents = map(lambda content: os.path.join(temp_dir, content), contents) contents = filter(os.path.exists, map(os.path.abspath, contents)) added_contents = set() |