OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
Sébastien Marchand
2017/06/22 19:44:48
Add a comment to describe what this script does, e
njanevsk
2017/06/22 21:16:32
Done.
| |
5 | |
Sébastien Marchand
2017/06/22 19:44:48
Add a BL here.
Basically each "section" is separa
njanevsk
2017/06/22 21:16:33
Done.
| |
6 import optparse | |
7 import os | |
8 import re | |
9 import subprocess | |
10 import sys | |
11 | |
Sébastien Marchand
2017/06/22 19:34:17
Add an extra BL here.
njanevsk
2017/06/22 21:16:32
Done.
| |
12 _SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) | |
13 _SRC_DIR = os.path.abspath(os.path.join(os.path.join(_SCRIPT_DIR, os.pardir), | |
Sébastien Marchand
2017/06/22 19:34:17
you can do os.path.abspath(os.path.join(_SCRIPT_DI
njanevsk
2017/06/22 21:16:33
Done.
| |
14 os.pardir)) | |
Sébastien Marchand
2017/06/22 19:34:17
Indent at +4.
njanevsk
2017/06/22 21:16:32
Done.
| |
15 _CLANG_PATH = (_SRC_DIR, | |
Sébastien Marchand
2017/06/22 19:34:16
I'd call this _CLANG_CL_PATH
njanevsk
2017/06/22 21:16:32
Done.
| |
16 "/third_party/llvm-build/Release+Asserts/bin/clang-cl.exe") | |
17 | |
Sébastien Marchand
2017/06/22 19:34:17
Add an extra BL here.
njanevsk
2017/06/22 21:16:32
Done.
| |
18 def compile(clang_path, source_files, src_dir): | |
19 """ Only compiles the integration tests but does not link. | |
Sébastien Marchand
2017/06/22 19:34:17
Remove the space before "Only", also I'll just say
njanevsk
2017/06/22 21:16:32
Done.
| |
20 | |
Sébastien Marchand
2017/06/22 19:34:17
Remove one of these 2 BLs.
njanevsk
2017/06/22 21:16:33
Done.
| |
21 | |
22 Only compiles the files and isntruments them with LLVM's Asan but does not | |
23 link them. The linking is done separately in the method link. | |
24 | |
25 Args: | |
26 clang_path: Path to the clang-cl compiler in the syzygy project. | |
27 source_files: The source files to be compiled. | |
28 src_dir: The repository where the syzgy src is located. | |
29 """ | |
30 compiler_flags = ['-c', | |
Sébastien Marchand
2017/06/22 19:34:17
Nit, I prefer this form:
foo = [
'bar',
'b
njanevsk
2017/06/22 21:16:32
Done.
| |
31 '-fsanitize=address', | |
32 '-mllvm', | |
33 '-asan-instrumentation-with-call-threshold=0', | |
34 '-mllvm', | |
35 '-asan-stack=0', | |
36 '-DUNICODE', | |
37 '-D_UNICODE', | |
38 '-DNOMINMAX', | |
39 '-D_CRT_SECURE_NO_WARNINGS', | |
40 '-I' + src_dir] | |
41 | |
42 compile_command = [clang_path] | |
43 compile_command.extend(compiler_flags) | |
44 compile_command.extend(source_files) | |
45 | |
46 ret = subprocess.call(compile_command) | |
47 if ret != 0: | |
48 print "Failed compiling the integration_tests using clang-cl" | |
49 return ret | |
50 | |
Sébastien Marchand
2017/06/22 19:44:48
2 BLs between each function :)
njanevsk
2017/06/22 21:16:32
Done.
| |
51 def link(clang_path, source_files, build_dir): | |
52 """ Links the object files and produces the integration_tests_clang_dll.dll. | |
53 | |
Sébastien Marchand
2017/06/22 19:34:17
Remove one of these BLs.
njanevsk
2017/06/22 21:16:33
Done.
| |
54 | |
55 Links the object files and produces the dll. The object files have to be | |
56 produced by the compile method above. | |
57 | |
58 Args: | |
59 clang_path: Path to the clang-cl compiler in the syzygy project. | |
60 source_files: The source file names which are converted to obj filenames. | |
61 build_dir: The directory where to produce the linked dll. | |
62 """ | |
63 object_files = ([os.path.splitext(filename)[0] + | |
64 ".o" for filename in source_files]) | |
Sébastien Marchand
2017/06/22 19:34:17
Indent +2. When you continue a line over the next
njanevsk
2017/06/22 21:16:32
Done.
| |
65 | |
66 compiler_controlled_linker_flags = ['-o', | |
67 (build_dir, | |
Sébastien Marchand
2017/06/22 19:34:17
Why the parenthesis? Should you use os.path.join h
njanevsk
2017/06/22 21:16:33
To join the two. I tried os.path.join but I get an
Sébastien Marchand
2017/06/23 18:01:54
os.path.join handles '..', you should use it.
| |
68 '\integration_tests_clang_dll.dll')] | |
69 | |
70 linker_flags = ['/link', | |
71 '/dll', | |
72 build_dir + '\export_dll.dll.lib', | |
73 build_dir + '\syzyasan_rtl.dll.lib', | |
74 '-defaultlib:libcmt'] | |
75 | |
76 linker_command = [clang_path, '-m32'] | |
77 linker_command.extend(object_files) | |
78 linker_command.extend(compiler_controlled_linker_flags) | |
79 linker_command.extend(linker_flags) | |
80 ret = subprocess.call(linker_command) | |
81 | |
82 if ret != 0: | |
83 print "Failed to link the integration_tests using clang-cl" | |
84 | |
85 def main(): | |
86 parser = optparse.OptionParser(usage='%prog [options]') | |
87 parser.add_option('--build-dir', help='Syzygy build directory.') | |
Sébastien Marchand
2017/06/22 19:44:48
help="Path to the build directory"? There's a dire
njanevsk
2017/06/22 21:16:32
To the Release directory not the build directory.
Sébastien Marchand
2017/06/23 18:01:53
You also want this to work in debug :), let's just
| |
88 parser.add_option('--input-files', help='files to be compiled and linked') | |
89 | |
90 options, _ = parser.parse_args() | |
91 | |
92 if not options.build_dir: | |
93 parser.error('--build-dir is required') | |
94 if not options.input_files: | |
95 parser.error('--input-files is required') | |
96 | |
97 source_files = re.findall(r'\b(\w+.cc)\b', options.input_files) | |
Sébastien Marchand
2017/06/22 19:34:17
using a Regex is overkill, you can use glob: https
Sébastien Marchand
2017/06/22 19:44:48
And as discussed in a previous patchset we should
| |
98 ret = compile(_CLANG_PATH, source_files, _SRC_DIR) | |
99 if ret == 0: | |
100 link(_CLANG_PATH, source_files, options.build_dir) | |
101 else: | |
102 print "Compilation of integration_tests_clang_dll failed." | |
103 print "Skipping link step." | |
Sébastien Marchand
2017/06/22 19:34:17
You should also return something !0 on failure so
njanevsk
2017/06/22 21:16:32
Done.
| |
104 | |
105 if __name__ == '__main__': | |
106 sys.exit(main()) | |
OLD | NEW |