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 """A script to compile the integration tests with llvm's clang, | 5 """A script to compile the integration tests with llvm's clang, |
6 instrument the code with llvm's Asan, and link it to the syzyasan_rtl | 6 instrument the code with llvm's Asan, and link it to the syzyasan_rtl |
7 runtime environment. | 7 runtime environment. |
8 """ | 8 """ |
9 | 9 |
10 import optparse | 10 import optparse |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 '-DNOMINMAX', | 49 '-DNOMINMAX', |
50 '-D_CRT_SECURE_NO_WARNINGS', | 50 '-D_CRT_SECURE_NO_WARNINGS', |
51 '-I', | 51 '-I', |
52 src_dir, | 52 src_dir, |
53 ] | 53 ] |
54 | 54 |
55 compile_command_base = [clang_path] | 55 compile_command_base = [clang_path] |
56 compile_command_base.extend(compiler_flags) | 56 compile_command_base.extend(compiler_flags) |
57 | 57 |
58 for source_file, object_file in zip(source_files, object_files): | 58 for source_file, object_file in zip(source_files, object_files): |
59 compile_command = list(compile_command_base) | 59 compile_command = compile_command_base |
60 compile_command.extend([source_file, '-o', object_file]) | 60 compile_command.extend([source_file, '-o', object_file]) |
| 61 print compile_command |
61 ret = subprocess.call(compile_command) | 62 ret = subprocess.call(compile_command) |
62 if ret != 0: | 63 if ret != 0: |
63 print 'ERROR: Failed compiling %s using clang-cl.' % target_name | 64 print 'ERROR: Failed compiling %s using clang-cl.' % target_name |
64 return ret | 65 return ret |
65 return ret | 66 return ret |
66 | 67 |
67 | 68 |
68 def link(clang_path, object_files, build_dir, target_name): | 69 def link(clang_path, object_files, build_dir, target_name): |
69 """ Links the object files and produces the integration_tests_clang_dll.dll. | 70 """ Links the object files and produces the integration_tests_clang_dll.dll. |
70 | 71 |
71 Links the object files and produces the dll. The object files have to be | 72 Links the object files and produces the dll. The object files have to be |
72 produced by the compile method above. | 73 produced by the compile method above. |
73 | 74 |
74 Args: | 75 Args: |
75 clang_path: Path to the clang-cl compiler in the syzygy project. | 76 clang_path: Path to the clang-cl compiler in the syzygy project. |
76 source_files: The source file names which are converted to obj filenames. | 77 source_files: The source file names which are converted to obj filenames. |
77 build_dir: The directory where to produce the linked dll. | 78 build_dir: The directory where to produce the linked dll. |
78 target_name: The name of the target being build. | 79 target_name: The name of the target being build. |
79 """ | 80 """ |
80 | 81 |
81 linker_flags = [ | 82 linker_flags = [ |
82 '-o', | 83 '-o', |
83 os.path.join(build_dir, target_name + '.dll'), | 84 os.path.join(build_dir, target_name + '.dll'), |
84 '/link', | 85 '/link', |
85 '/dll', | 86 '/dll', |
86 os.path.join(build_dir, 'export_dll.dll.lib'), | 87 build_dir + '\export_dll.dll.lib', |
87 os.path.join(build_dir, 'syzyasan_rtl.dll.lib'), | 88 build_dir + '\syzyasan_rtl.dll.lib', |
88 '-defaultlib:libcmt' | 89 '-defaultlib:libcmt' |
89 ] | 90 ] |
90 | 91 |
91 linker_command = [clang_path, '-m32'] | 92 linker_command = [clang_path, '-m32'] |
92 linker_command.extend(object_files) | 93 linker_command.extend(object_files) |
93 linker_command.extend(linker_flags) | 94 linker_command.extend(linker_flags) |
94 ret = subprocess.call(linker_command) | 95 ret = subprocess.call(linker_command) |
95 | 96 |
96 if ret != 0: | 97 if ret != 0: |
97 print 'ERROR: Failed to link %s using clang-cl.' % target_name | 98 print 'ERROR: Failed to link %s using clang-cl.' % target_name |
(...skipping 12 matching lines...) Expand all Loading... |
110 if not options.output_dir: | 111 if not options.output_dir: |
111 parser.error('--output-dir is required.') | 112 parser.error('--output-dir is required.') |
112 if not options.input_files: | 113 if not options.input_files: |
113 parser.error('--input-files is required.') | 114 parser.error('--input-files is required.') |
114 if not options.target_name: | 115 if not options.target_name: |
115 parser.error('--target-name is required.') | 116 parser.error('--target-name is required.') |
116 | 117 |
117 def get_object_file_location(source_file, | 118 def get_object_file_location(source_file, |
118 output_dir, target_name): | 119 output_dir, target_name): |
119 return os.path.join(output_dir, 'obj', | 120 return os.path.join(output_dir, 'obj', |
120 os.path.dirname(os.path.relpath(source_file, | 121 os.path.split(os.path.relpath(source_file, |
121 _SRC_DIR)), | 122 _SRC_DIR))[0], |
122 '%s.%s.obj' % (target_name, | 123 '%s.%s.obj' % (target_name, |
123 os.path.splitext(os.path.basename(source_file))[0])) | 124 os.path.splitext(os.path.basename(source_file))[0])) |
124 | 125 |
125 source_files = options.input_files.split() | 126 source_files = options.input_files.split() |
126 object_files = [] | 127 object_files = [] |
127 | 128 |
128 for source_file in source_files: | 129 for source_file in source_files: |
129 object_files.append(get_object_file_location(source_file, | 130 object_files.append(get_object_file_location(source_file, |
130 options.output_dir, | 131 options.output_dir, |
131 options.target_name)) | 132 options.target_name)) |
132 | 133 |
133 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR, | 134 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR, |
134 object_files, options.target_name) | 135 object_files, options.target_name) |
135 | 136 |
136 if ret == 0: | 137 if ret == 0: |
137 ret = link(_CLANG_CL_PATH, object_files, options.output_dir, | 138 ret = link(_CLANG_CL_PATH, object_files, options.output_dir, |
138 options.target_name) | 139 options.target_name) |
139 else: | 140 else: |
140 print ('ERROR: Compilation of %s failed, skipping link step.' | 141 print ('ERROR: Compilation of %s failed, skipping link step.' |
141 % options.target_name) | 142 % options.target_name) |
142 | 143 |
143 return ret | 144 return ret |
144 | 145 |
145 | 146 |
146 if __name__ == '__main__': | 147 if __name__ == '__main__': |
147 sys.exit(main()) | 148 sys.exit(main()) |
OLD | NEW |