Chromium Code Reviews| Index: include_rsp.py |
| diff --git a/include_rsp.py b/include_rsp.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..13f1cd4adc8cb1a16d589715ced4ea4e7d9cb9e1 |
| --- /dev/null |
| +++ b/include_rsp.py |
| @@ -0,0 +1,69 @@ |
| +import os |
| +import re |
| +import json |
| +import sys |
| + |
| + |
| +_NINJA_MSVC_WRAPPER = re.compile('ninja -t msvc -e .+? -- ') |
| +_RSP_RE = re.compile(r' (@(.+?\.rsp)) ') |
| + |
| + |
| +def process_arg(arg): |
| + if not arg.startswith('/'): |
| + return arg |
| + if arg == '/c': |
| + return '-c' |
| + if arg.startswith('/Fo'): |
| + return arg.replace('/Fo', '-o ', 1) |
| + return '' |
| + |
| + |
| +def process_entry(e): |
| + # Strip off the ninja -t msvc wrapper. |
| + e['command'] = _NINJA_MSVC_WRAPPER.sub('', e['command']) |
| + |
| + # Expand the contents of the response file, if any. |
| + try: |
| + match = _RSP_RE.search(e['command']) |
| + rsp_path = os.path.join(e['directory'], match.group(2)) |
| + rsp_contents = file(rsp_path).read() |
| + e['command'] = e['command'][:match.start(1)] + rsp_contents + e['command'][match.end(1):] |
| + except IOError: |
| + pass |
| + |
| + # TODO(dcheng): This should be implemented as an argument adjuster. |
| + # Convert a limited subset of MSVC arguments to clang-style arguments and |
| + # remove the rest. |
| + e['command'] = ' '.join([process_arg(arg) for arg in e['command'].split(' ')]) |
| + e['command'] += ' -fms-compatibility -fms-extensions' |
| + e['command'] += ' -target i686-pc-windows-msvc' |
| + # e['command'] += ' --driver-mode=cl' |
|
dcheng
2014/11/11 23:36:07
Lines 38-40 were various attempts to get clang-cl
hans
2014/11/11 23:42:44
Is it invoked as clang-cl but not getting into cl
|
| + |
| + # TODO(dcheng): This should be implemented in Clang tooling. |
| + # Finally, use slashes instead of backslashes to avoid bad escaping by the |
| + # tooling. This should really only matter for command, but we do it for all keys |
| + # for consistency. |
| + e['directory'] = e['directory'].replace('\\', '/') |
| + e['command'] = e['command'].replace('\\', '/') |
| + e['file'] = e['file'].replace('\\', '/') |
| + |
| + return e |
| + |
| + |
| +def main(argv): |
| + compile_db = json.loads(file('out/Debug/compile_commands.json').read()) |
| + print 'Read in %d entries from the compile db' % len(compile_db) |
| + compile_db = [process_entry(e) for e in compile_db] |
| + prefilter_len = len(compile_db) |
| + # Filter out entries that still have RSP in them. |
| + compile_db = [e for e in compile_db if e['command'].find('.obj.rsp') == -1] |
|
dcheng
2014/11/11 23:36:07
For some reason, the compile DB had two entries fo
|
| + print 'Filtered out %d entries' % (prefilter_len - len(compile_db)) |
| + compile_db_with_rsp = json.dumps(compile_db, indent=2) |
| + f = file('out/Debug/compile_commands_with_rsp.json', 'w') |
| + f.write(compile_db_with_rsp) |
| + print 'Wrote out new compile db with rsp inline' |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv[1:])) |
| + |