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

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

Issue 2946063002: Python script to compile and link the integration tests using llvm's clang-cl (Closed)
Patch Set: Python script to compile and link the integration tests using llvm's clang-cl 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
(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.
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
7 runtime environment.
8 """
9
10 import optparse
11 import os
12 import re
13 import subprocess
14 import sys
15
16
17 _SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
18 _SRC_DIR = os.path.abspath(os.path.join(_SCRIPT_DIR, os.pardir, os.pardir))
19 _CLANG_CL_PATH = os.path.join(_SRC_DIR,
20 'third_party', 'llvm-build', 'Release+Asserts', 'bin', 'clang-cl.exe')
21
22 def compile_with_asan(clang_path, source_files, src_dir, object_files,
23 target_name):
24 """Only compiles with clang but does not link.
25
26 Only compiles the files and isntruments them with LLVM's Asan but does not
27 link them. The linking is done separately in the method link.
28
29 Args:
30 clang_path: Path to the clang-cl compiler.
31 source_files: The source files to be compiled.
32 src_dir: The repository where the syzgy src is located.
33 object_files: The path where each object file should be generated.
34 target_name: The name of the target being build.
35 """
36
37 compiler_flags = [
38 '-c',
39 '-m32',
40 '-fsanitize=address',
41 '-mllvm',
42 '-asan-instrumentation-with-call-threshold=0',
43 '-mllvm',
44 '-asan-stack=0',
45 '-DUNICODE',
46 '-D_UNICODE',
47 '-DNOMINMAX',
48 '-D_CRT_SECURE_NO_WARNINGS',
49 '-I',
50 src_dir,
51 ]
52
53 compile_command_base = [clang_path]
54 compile_command_base.extend(compiler_flags)
55
56 for source_file, object_file in zip(source_files, object_files):
57 compile_command = compile_command_base
Sébastien Marchand 2017/07/06 19:29:57 You could use the "compile_command = [...]" syntax
njanevsk 2017/07/06 19:42:16 Done.
58 compile_command.append(source_file)
59 compile_command.append('-o')
60 compile_command.append(object_file)
61
62 ret = subprocess.call(compile_command)
63 if ret != 0:
64 print 'ERROR: Failed compiling %s using clang-cl' % target_name
Sébastien Marchand 2017/07/06 19:29:57 Missing period at the end of this message.
njanevsk 2017/07/06 19:42:16 Done.
65 return ret
66 return ret
67
68 def link(clang_path, object_files, build_dir, target_name):
69 """ Links the object files and produces the integration_tests_clang_dll.dll.
70
71
72 Links the object files and produces the dll. The object files have to be
73 produced by the compile method above.
74
75 Args:
76 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.
78 build_dir: The directory where to produce the linked dll.
79 target_name: The name of the target being build.
80 """
81
82 linker_flags = [
83 '-o',
84 os.path.join(build_dir, target_name + '.dll'),
85 '/link',
86 '/dll',
87 build_dir + '\export_dll.dll.lib',
88 build_dir + '\syzyasan_rtl.dll.lib',
89 '-defaultlib:libcmt'
90 ]
91
92 linker_command = [clang_path, '-m32']
93 linker_command.extend(object_files)
94 linker_command.extend(linker_flags)
95 ret = subprocess.call(linker_command)
96
97 if ret != 0:
98 print 'ERROR: Failed to link %s using clang-cl' % target_name
Sébastien Marchand 2017/07/06 19:29:57 Missing period at the end of this message.
njanevsk 2017/07/06 19:42:16 Done.
99 return ret
100
101
102 def main():
103 parser = optparse.OptionParser(usage='%prog [options]')
104 parser.add_option('--output-dir',
105 help='Path to the Syzygy Release directory.')
106 parser.add_option('--input-files', help='Files to be compiled and linked.')
107 parser.add_option('--target-name', help='Name of the target to be compiled.')
108
109 options, _ = parser.parse_args()
110
111 if not options.output_dir:
112 parser.error('--output-dir is required.')
113 if not options.input_files:
114 parser.error('--input-files is required.')
115 if not options.target_name:
116 parser.error('--target-name is required.')
117
118 def get_object_file_location(source_file,
119 output_dir, target_name):
120 return os.path.join(output_dir, 'obj',
121 os.path.split(os.path.relpath(source_file,
122 _SRC_DIR))[0],
123 '%s.%s.obj' % (target_name,
124 os.path.splitext(os.path.basename(source_file))[0])
125
126 source_files = options.input_files.split()
127 object_files = []
128
129 for source_file in source_files:
130 object_files.append(get_object_file_location(source_file,
131 options.output_dir,
132 options.target_name))
133
134 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR,
135 object_files, options.target_name)
136
137 if ret == 0:
138 ret = link(_CLANG_CL_PATH, object_files, options.output_dir,
139 options.target_name)
140 else:
141 print ('ERROR: Compilation of %s failed, skipping link step.'
142 % options.target_name)
143
144 return ret
145
146
147 if __name__ == '__main__':
148 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