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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 = list(compile_command_base) |
| 60 compile_command.extend([source_file, '-o', object_file]) | 60 compile_command.extend([source_file, '-o', object_file]) |
| 61 ret = subprocess.call(compile_command) | 61 ret = subprocess.call(compile_command) |
| 62 if ret != 0: | 62 if ret != 0: |
| 63 print 'ERROR: Failed compiling %s using clang-cl.' % target_name | 63 print 'ERROR: Failed compiling %s using clang-cl.' % target_name |
| 64 return ret | 64 return ret |
| 65 return ret | 65 return ret |
| 66 | 66 |
| 67 | 67 |
| 68 def link(clang_path, object_files, build_dir, target_name): | 68 def link(clang_path, object_files, build_dir, target_name, def_file): |
| 69 """ 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. |
| 70 | 70 |
| 71 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 |
| 72 produced by the compile method above. | 72 produced by the compile method above. |
| 73 | 73 |
| 74 Args: | 74 Args: |
| 75 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. |
| 76 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. |
| 77 build_dir: The directory where to produce the linked dll. | 77 build_dir: The directory where to produce the linked dll. |
| 78 target_name: The name of the target being build. | 78 target_name: The name of the target being build. |
| 79 """ | 79 """ |
| 80 | 80 |
| 81 linker_flags = [ | 81 linker_flags = [ |
| 82 '-o', | 82 '-o', |
| 83 os.path.join(build_dir, target_name + '.dll'), | 83 os.path.join(build_dir, target_name + '.dll'), |
| 84 '/link', | 84 '/link', |
| 85 '/dll', | 85 '/dll', |
| 86 os.path.join(build_dir, 'export_dll.dll.lib'), | 86 os.path.join(build_dir, 'export_dll.dll.lib'), |
| 87 os.path.join(build_dir, 'syzyasan_rtl.dll.lib'), | 87 os.path.join(build_dir, 'syzyasan_rtl.dll.lib'), |
| 88 '-defaultlib:libcmt' | 88 '-defaultlib:libcmt', |
| 89 '/def:' + def_file, | |
|
Sébastien Marchand
2017/07/19 13:57:29
You also want to produce a PDB, otherwise you won'
njanevsk
2017/07/19 20:58:57
Added /debug which produces a PDB and in the compi
| |
| 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 |
| 98 return ret | 99 return ret |
| 99 | 100 |
| 100 | 101 |
| 101 def main(): | 102 def main(): |
| 102 parser = optparse.OptionParser(usage='%prog [options]') | 103 parser = optparse.OptionParser(usage='%prog [options]') |
| 103 parser.add_option('--output-dir', | 104 parser.add_option('--output-dir', |
| 104 help='Path to the Syzygy Release directory.') | 105 help='Path to the Syzygy Release directory.') |
| 105 parser.add_option('--input-files', help='Files to be compiled and linked.') | 106 parser.add_option('--input-files', help='Files to be compiled and linked.') |
| 106 parser.add_option('--target-name', help='Name of the target to be compiled.') | 107 parser.add_option('--target-name', help='Name of the target to be compiled.') |
| 108 parser.add_option('--def-file', help='Definition file for the dll.') | |
| 107 | 109 |
| 108 options, _ = parser.parse_args() | 110 options, _ = parser.parse_args() |
| 109 | 111 |
| 110 if not options.output_dir: | 112 if not options.output_dir: |
| 111 parser.error('--output-dir is required.') | 113 parser.error('--output-dir is required.') |
| 112 if not options.input_files: | 114 if not options.input_files: |
| 113 parser.error('--input-files is required.') | 115 parser.error('--input-files is required.') |
| 114 if not options.target_name: | 116 if not options.target_name: |
| 115 parser.error('--target-name is required.') | 117 parser.error('--target-name is required.') |
| 118 if not options.def_file: | |
| 119 parser.error('--def-file is required.') | |
| 116 | 120 |
| 117 def get_object_file_location(source_file, | 121 def get_object_file_location(source_file, |
| 118 output_dir, target_name): | 122 output_dir, target_name): |
| 119 return os.path.join(output_dir, 'obj', | 123 return os.path.join(output_dir, 'obj', |
| 120 os.path.dirname(os.path.relpath(source_file, _SRC_DIR)), | 124 os.path.dirname(os.path.relpath(source_file, _SRC_DIR)), |
| 121 '%s.%s.obj' % (target_name, | 125 '%s.%s.obj' % (target_name, |
| 122 os.path.splitext(os.path.basename(source_file))[0])) | 126 os.path.splitext(os.path.basename(source_file))[0])) |
| 123 | 127 |
| 124 source_files = options.input_files.split() | 128 source_files = options.input_files.split() |
| 125 object_files = [] | 129 object_files = [] |
| 126 | 130 |
| 127 for source_file in source_files: | 131 for source_file in source_files: |
| 128 object_files.append(get_object_file_location(source_file, | 132 object_files.append(get_object_file_location(source_file, |
| 129 options.output_dir, | 133 options.output_dir, |
| 130 options.target_name)) | 134 options.target_name)) |
| 131 | 135 |
| 132 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR, | 136 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR, |
| 133 object_files, options.target_name) | 137 object_files, options.target_name) |
| 134 | 138 |
| 135 if ret == 0: | 139 if ret == 0: |
| 136 ret = link(_CLANG_CL_PATH, object_files, options.output_dir, | 140 ret = link(_CLANG_CL_PATH, object_files, options.output_dir, |
| 137 options.target_name) | 141 options.target_name, options.def_file) |
| 138 else: | 142 else: |
| 139 print ('ERROR: Compilation of %s failed, skipping link step.' | 143 print ('ERROR: Compilation of %s failed, skipping link step.' |
| 140 % options.target_name) | 144 % options.target_name) |
| 141 | 145 |
| 142 return ret | 146 return ret |
| 143 | 147 |
| 144 | 148 |
| 145 if __name__ == '__main__': | 149 if __name__ == '__main__': |
| 146 sys.exit(main()) | 150 sys.exit(main()) |
| OLD | NEW |