OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import optparse | 6 import optparse |
7 import os | 7 import os |
8 import re | 8 import re |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
11 | 11 |
12 def compile(clang_path, source_files, src_dir): | |
Sébastien Marchand
2017/06/21 19:51:37
Add a comment to describe what this function do.
njanevsk
2017/06/22 18:43:49
Done.
| |
13 compiler_flags = [ | |
14 '-c', | |
Sébastien Marchand
2017/06/21 19:51:36
Fix the indentation.
njanevsk
2017/06/22 18:43:49
Done.
| |
15 '-fsanitize=address', | |
16 '-mllvm', | |
17 '-asan-instrumentation-with-call-threshold=0', | |
18 '-mllvm', | |
19 '-asan-stack=0', | |
20 '-DUNICODE', | |
21 '-D_UNICODE', | |
22 '-DNOMINMAX', | |
23 '-D_CRT_SECURE_NO_WARNINGS', | |
24 '-I' + src_dir | |
Sébastien Marchand
2017/06/21 19:51:36
s/+/,/ and move src_dir to the next line.
njanevsk
2017/06/22 18:43:49
Why? Cause this is a single flag. include the src
Sébastien Marchand
2017/06/22 19:34:16
Yes but this will also work with a comma, and here
| |
25 ] | |
26 compile_command = [clang_path] | |
27 compile_command.extend(compiler_flags) | |
28 compile_command.extend(source_files) | |
29 | |
30 ret = subprocess.call(compile_command) | |
31 if ret != 0: | |
32 print "Failed compiling the integration_tests using clang-cl" | |
Sébastien Marchand
2017/06/21 19:51:37
This isn't indented properly.
njanevsk
2017/06/22 18:43:49
Done.
| |
33 | |
34 def link(clang_path, source_files, build_dir): | |
35 object_files = [os.path.splitext(filename)[0] + ".o" for filename in source_fi les] | |
Sébastien Marchand
2017/06/21 19:51:36
> 80 chars.
njanevsk
2017/06/22 18:43:49
Done.
| |
36 | |
37 compiler_controlled_linker_flags = [ | |
38 '-o', | |
39 build_dir + '\integration_tests_dll.dll' | |
Sébastien Marchand
2017/06/21 19:51:36
Fix indentation, look at the other Python script f
njanevsk
2017/06/22 18:43:49
Done.
| |
40 ] | |
41 | |
42 linker_flags = [ | |
43 '/link', | |
44 '/dll', | |
45 build_dir + '\export_dll.dll.lib', | |
46 build_dir + '\syzyasan_rtl.dll.lib', | |
47 '-defaultlib:libcmt' | |
48 ] | |
49 | |
50 linker_command = [clang_path] | |
51 linker_command.extend(['-m32']) | |
Sébastien Marchand
2017/06/21 19:51:36
linker_command = [
clang_path,
'-m32',
]
njanevsk
2017/06/22 18:43:48
Done.
| |
52 linker_command.extend(object_files) | |
53 linker_command.extend(compiler_controlled_linker_flags) | |
54 linker_command.extend(linker_flags) | |
55 ret = subprocess.call(linker_command) | |
56 | |
57 if ret != 0: | |
58 print "Failed to link the integration_tests using clang-cl" | |
Sébastien Marchand
2017/06/21 19:51:36
Fix indent.
njanevsk
2017/06/22 18:43:49
Done.
| |
12 | 59 |
13 def main(): | 60 def main(): |
14 parser = optparse.OptionParser(usage='%prog [options]') | 61 parser = optparse.OptionParser(usage='%prog [options]') |
15 parser.add_option('--src-dir', | 62 parser.add_option('--src-dir', |
16 help='The src directory where the syzygy repository is located.') | 63 help='The src directory where the syzygy repository is located.') |
17 parser.add_option('--build-dir', help='Syzygy build directory.') | 64 parser.add_option('--build-dir', help='Syzygy build directory.') |
18 parser.add_option('--input-files', help='files to be compiled and linked') | 65 parser.add_option('--input-files', help='files to be compiled and linked') |
19 | 66 |
20 options, _ = parser.parse_args() | 67 options, _ = parser.parse_args() |
21 | 68 |
22 if not options.src_dir: | 69 if not options.src_dir: |
23 parser.error('--src-dir is required') | 70 parser.error('--src-dir is required') |
24 if not options.build_dir: | 71 if not options.build_dir: |
25 parser.error('--build-dir is required') | 72 parser.error('--build-dir is required') |
26 if not options.input_files: | 73 if not options.input_files: |
27 parser.error('--input-files is required') | 74 parser.error('--input-files is required') |
28 | 75 |
29 clang_path = options.src_dir + "/third_party/llvm-build/Release+Asserts/bin/cl ang-cl.exe" | 76 clang_path = options.src_dir + \ |
Sébastien Marchand
2017/06/21 19:51:37
Use parenthesis instead of \, better than that, mo
njanevsk
2017/06/22 18:43:49
Done.
| |
30 compiler_flags = '-c -fsanitize=address -mllvm -asan-instrumentation-with-call -threshold=0 -mllvm -asan-stack=0 -DUNICODE -D_UNICODE -DNOMINMAX -D_CRT_SECURE_ NO_WARNINGS -I' + options.src_dir | 77 "/third_party/llvm-build/Release+Asserts/bin/clang-cl.exe" |
31 | 78 |
32 print os.path.dirname(os.path.realpath(__file__)) | |
33 source_files = re.findall(r'\b(\w+.cc)\b', options.input_files) | 79 source_files = re.findall(r'\b(\w+.cc)\b', options.input_files) |
34 print subprocess.check_output('"' + clang_path + '" ' + compiler_flags + ' ' + ' '.join(source_files), shell = True) | 80 compile(clang_path, source_files, options.src_dir) |
Sébastien Marchand
2017/06/21 19:51:36
Check the return value, don't try to link if the c
njanevsk
2017/06/22 18:43:49
Done.
| |
35 object_files = [filename[:-3] + ".o" for filename in source_files] | 81 link(clang_path, source_files, options.build_dir) |
Sébastien Marchand
2017/06/21 19:51:36
Ditto.
njanevsk
2017/06/22 18:43:49
There is no need to check the return value here. I
Sébastien Marchand
2017/06/22 19:34:16
We still want the script to return something != 0
| |
36 | |
37 print subprocess.check_output('"' + clang_path + '" ' + '-m32' + ' ' + ' '.joi n(object_files) + ' -o' + ' ' + options.build_dir + '\integration_tests_dll.dll' + ' /link /dll ' + options.build_dir + '\export_dll.dll.lib ' + options.build_d ir + '\syzyasan_rtl.dll.lib' + ' -defaultlib:libcmt', shell = True) | |
38 | 82 |
39 if __name__ == '__main__': | 83 if __name__ == '__main__': |
40 sys.exit(main()) | 84 sys.exit(main()) |
OLD | NEW |