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

Unified 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: Response to reviews Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: syzygy/integration_tests/make_integration_tests_clang.py
diff --git a/syzygy/integration_tests/make_integration_tests_clang.py b/syzygy/integration_tests/make_integration_tests_clang.py
new file mode 100644
index 0000000000000000000000000000000000000000..8da25569381f2ffd8f7eab317e2cd7cbf146898c
--- /dev/null
+++ b/syzygy/integration_tests/make_integration_tests_clang.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+""" A script to compile the integration tests with llvm's clang,
Sébastien Marchand 2017/06/23 18:01:54 Remove the space before the 'A'
+instrument the code with llvm's Asan, and link it to the syzyasan_rtl
+runtime environment.
+"""
+
+import optparse
+import os
+import re
+import subprocess
+import sys
+
+
+_SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
+_SRC_DIR = os.path.abspath(os.path.join(_SCRIPT_DIR, os.pardir, os.pardir))
+_CLANG_CL_PATH = (_SRC_DIR,
+ "/third_party/llvm-build/Release+Asserts/bin/clang-cl.exe")
+
+
+def compile_with_asan(clang_path, source_files, src_dir):
+ """Only compiles with clang but does not link.
+
+ Only compiles the files and isntruments them with LLVM's Asan but does not
+ link them. The linking is done separately in the method link.
+
+ Args:
+ clang_path: Path to the clang-cl compiler.
+ source_files: The source files to be compiled.
+ src_dir: The repository where the syzgy src is located.
+ """
+ compiler_flags = [
+ '-c',
+ '-fsanitize=address',
+ '-mllvm',
+ '-asan-instrumentation-with-call-threshold=0',
+ '-mllvm',
+ '-asan-stack=0',
+ '-DUNICODE',
+ '-D_UNICODE',
+ '-DNOMINMAX',
+ '-D_CRT_SECURE_NO_WARNINGS',
+ '-I',
+ src_dir
+ ]
+
+ compile_command = [clang_path]
+ compile_command.extend(compiler_flags)
+ compile_command.extend(source_files)
+
+ ret = subprocess.call(compile_command)
Sébastien Marchand 2017/06/23 18:01:54 The object files seems to be produced next to thei
+ if ret != 0:
+ print "Failed compiling the integration_tests using clang-cl"
+ return ret
+
+
+def link(clang_path, source_files, build_dir):
+ """ Links the object files and produces the integration_tests_clang_dll.dll.
+
+
+ Links the object files and produces the dll. The object files have to be
+ produced by the compile method above.
+
+ Args:
+ clang_path: Path to the clang-cl compiler in the syzygy project.
+ source_files: The source file names which are converted to obj filenames.
+ build_dir: The directory where to produce the linked dll.
+ """
+ object_files = ([os.path.splitext(filename)[0] +
+ ".o" for filename in source_files])
+
+ compiler_controlled_linker_flags = [
Sébastien Marchand 2017/06/23 18:01:54 this name is confusing, why not just call it linke
+ '-o',
+ (build_dir, '\integration_tests_clang_dll.dll')
+ ]
+
+ linker_flags = [
+ '/link',
+ '/dll',
+ build_dir + '\export_dll.dll.lib',
+ build_dir + '\syzyasan_rtl.dll.lib',
+ '-defaultlib:libcmt'
+ ]
+
+ linker_command = [clang_path, '-m32']
+ linker_command.extend(object_files)
+ linker_command.extend(compiler_controlled_linker_flags)
+ linker_command.extend(linker_flags)
+ ret = subprocess.call(linker_command)
+
+ if ret != 0:
+ print "Failed to link the integration_tests using clang-cl"
+ return ret
+
+
+def main():
+ parser = optparse.OptionParser(usage='%prog [options]')
+ parser.add_option('--build-dir',
+ help='Path to the Syzygy Release directory.')
+ parser.add_option('--input-files', help='files to be compiled and linked')
+
+ options, _ = parser.parse_args()
+
+ if not options.build_dir:
+ parser.error('--build-dir is required')
+ if not options.input_files:
+ parser.error('--input-files is required')
Sébastien Marchand 2017/06/23 18:01:54 Could you add a "target-name" flag and use it ever
+
+ source_files = options.input_files.split()
+
+ ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR)
+ if ret == 0:
+ ret = link(_CLANG_CL_PATH, source_files, options.build_dir)
+ else:
+ print "Compilation of integration_tests_clang_dll failed."
Sébastien Marchand 2017/06/23 18:01:54 Add "ERROR" at the beginning of this line, so it'l
+ print "Skipping link step."
Sébastien Marchand 2017/06/23 18:01:54 Print these 2 messages on the same line.
+
+ return ret
+
+
+if __name__ == '__main__':
+ sys.exit(main())
« 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