Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: syzygy/integration_tests/make_integration_tests_clang.py

Issue 2974783002: Fixed some nits based on reviewer comments. (Closed)
Patch Set: Fixed some nits based on reviewer comments. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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, _SRC_DIR)),
122 _SRC_DIR))[0], 121 '%s.%s.obj' % (target_name,
123 '%s.%s.obj' % (target_name, 122 os.path.splitext(os.path.basename(source_file))[0]))
124 os.path.splitext(os.path.basename(source_file))[0]))
125 123
126 source_files = options.input_files.split() 124 source_files = options.input_files.split()
127 object_files = [] 125 object_files = []
128 126
129 for source_file in source_files: 127 for source_file in source_files:
130 object_files.append(get_object_file_location(source_file, 128 object_files.append(get_object_file_location(source_file,
131 options.output_dir, 129 options.output_dir,
132 options.target_name)) 130 options.target_name))
133 131
134 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR, 132 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR,
135 object_files, options.target_name) 133 object_files, options.target_name)
136 134
137 if ret == 0: 135 if ret == 0:
138 ret = link(_CLANG_CL_PATH, object_files, options.output_dir, 136 ret = link(_CLANG_CL_PATH, object_files, options.output_dir,
139 options.target_name) 137 options.target_name)
140 else: 138 else:
141 print ('ERROR: Compilation of %s failed, skipping link step.' 139 print ('ERROR: Compilation of %s failed, skipping link step.'
142 % options.target_name) 140 % options.target_name)
143 141
144 return ret 142 return ret
145 143
146 144
147 if __name__ == '__main__': 145 if __name__ == '__main__':
148 sys.exit(main()) 146 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698