Chromium Code Reviews| 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 = compile_command_base | 59 compile_command = list(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 | |
| 62 ret = subprocess.call(compile_command) | 61 ret = subprocess.call(compile_command) |
| 63 if ret != 0: | 62 if ret != 0: |
| 64 print 'ERROR: Failed compiling %s using clang-cl.' % target_name | 63 print 'ERROR: Failed compiling %s using clang-cl.' % target_name |
| 65 return ret | 64 return ret |
| 66 return ret | 65 return ret |
| 67 | 66 |
| 68 | 67 |
| 69 def link(clang_path, object_files, build_dir, target_name): | 68 def link(clang_path, object_files, build_dir, target_name): |
| 70 """ Links the object files and produces the integration_tests_clang_dll.dll. | 69 """ Links the object files and produces the integration_tests_clang_dll.dll. |
| 71 | 70 |
| 72 Links the object files and produces the dll. The object files have to be | 71 Links the object files and produces the dll. The object files have to be |
| 73 produced by the compile method above. | 72 produced by the compile method above. |
| 74 | 73 |
| 75 Args: | 74 Args: |
| 76 clang_path: Path to the clang-cl compiler in the syzygy project. | 75 clang_path: Path to the clang-cl compiler in the syzygy project. |
| 77 source_files: The source file names which are converted to obj filenames. | 76 source_files: The source file names which are converted to obj filenames. |
| 78 build_dir: The directory where to produce the linked dll. | 77 build_dir: The directory where to produce the linked dll. |
| 79 target_name: The name of the target being build. | 78 target_name: The name of the target being build. |
| 80 """ | 79 """ |
| 81 | 80 |
| 82 linker_flags = [ | 81 linker_flags = [ |
| 83 '-o', | 82 '-o', |
| 84 os.path.join(build_dir, target_name + '.dll'), | 83 os.path.join(build_dir, target_name + '.dll'), |
| 85 '/link', | 84 '/link', |
| 86 '/dll', | 85 '/dll', |
| 87 build_dir + '\export_dll.dll.lib', | 86 os.path.join(build_dir, 'export_dll.dll.lib'), |
| 88 build_dir + '\syzyasan_rtl.dll.lib', | 87 os.path.join(build_dir, 'syzyasan_rtl.dll.lib'), |
| 89 '-defaultlib:libcmt' | 88 '-defaultlib:libcmt' |
| 90 ] | 89 ] |
| 91 | 90 |
| 92 linker_command = [clang_path, '-m32'] | 91 linker_command = [clang_path, '-m32'] |
| 93 linker_command.extend(object_files) | 92 linker_command.extend(object_files) |
| 94 linker_command.extend(linker_flags) | 93 linker_command.extend(linker_flags) |
| 95 ret = subprocess.call(linker_command) | 94 ret = subprocess.call(linker_command) |
| 96 | 95 |
| 97 if ret != 0: | 96 if ret != 0: |
| 98 print 'ERROR: Failed to link %s using clang-cl.' % target_name | 97 print 'ERROR: Failed to link %s using clang-cl.' % target_name |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 111 if not options.output_dir: | 110 if not options.output_dir: |
| 112 parser.error('--output-dir is required.') | 111 parser.error('--output-dir is required.') |
| 113 if not options.input_files: | 112 if not options.input_files: |
| 114 parser.error('--input-files is required.') | 113 parser.error('--input-files is required.') |
| 115 if not options.target_name: | 114 if not options.target_name: |
| 116 parser.error('--target-name is required.') | 115 parser.error('--target-name is required.') |
| 117 | 116 |
| 118 def get_object_file_location(source_file, | 117 def get_object_file_location(source_file, |
| 119 output_dir, target_name): | 118 output_dir, target_name): |
| 120 return os.path.join(output_dir, 'obj', | 119 return os.path.join(output_dir, 'obj', |
| 121 os.path.split(os.path.relpath(source_file, | 120 os.path.dirname(os.path.relpath(source_file, |
| 122 _SRC_DIR))[0], | 121 _SRC_DIR)), |
| 123 '%s.%s.obj' % (target_name, | 122 '%s.%s.obj' % (target_name, |
| 124 os.path.splitext(os.path.basename(source_file))[0])) | 123 os.path.splitext(os.path.basename(source_file))[0])) |
|
Sébastien Marchand
2017/07/10 16:46:10
This should be aligned with the 'target_name' argu
njanevsk
2017/07/10 18:44:25
Done.
| |
| 125 | 124 |
| 126 source_files = options.input_files.split() | 125 source_files = options.input_files.split() |
| 127 object_files = [] | 126 object_files = [] |
| 128 | 127 |
| 129 for source_file in source_files: | 128 for source_file in source_files: |
| 130 object_files.append(get_object_file_location(source_file, | 129 object_files.append(get_object_file_location(source_file, |
| 131 options.output_dir, | 130 options.output_dir, |
| 132 options.target_name)) | 131 options.target_name)) |
| 133 | 132 |
| 134 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR, | 133 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR, |
| 135 object_files, options.target_name) | 134 object_files, options.target_name) |
| 136 | 135 |
| 137 if ret == 0: | 136 if ret == 0: |
| 138 ret = link(_CLANG_CL_PATH, object_files, options.output_dir, | 137 ret = link(_CLANG_CL_PATH, object_files, options.output_dir, |
| 139 options.target_name) | 138 options.target_name) |
| 140 else: | 139 else: |
| 141 print ('ERROR: Compilation of %s failed, skipping link step.' | 140 print ('ERROR: Compilation of %s failed, skipping link step.' |
| 142 % options.target_name) | 141 % options.target_name) |
| 143 | 142 |
| 144 return ret | 143 return ret |
| 145 | 144 |
| 146 | 145 |
| 147 if __name__ == '__main__': | 146 if __name__ == '__main__': |
| 148 sys.exit(main()) | 147 sys.exit(main()) |
| OLD | NEW |