Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 | 5 |
| 6 """Downloads, builds (with instrumentation) and installs shared libraries.""" | 6 """Downloads, builds (with instrumentation) and installs shared libraries.""" |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 # Should be a dict from 'sanitizer type' to 'compiler flag'. | 14 # Should be a dict from 'sanitizer type' to 'compiler flag'. |
| 15 SUPPORTED_SANITIZERS = {'asan': 'address'} | 15 SUPPORTED_SANITIZERS = { |
|
alextaran1
2013/12/03 11:35:47
Looks like a part of gyp-file. Not sure should thi
Alexander Potapenko
2013/12/03 11:46:46
Yeah, probably. Let us leave it as is and then ref
| |
| 16 'asan': {'compiler_flags': '-fsanitize=address -g -fPIC -w'}, | |
|
Alexander Potapenko
2013/12/03 11:46:46
Please use -gline-tables-only instead of -g.
| |
| 17 'msan': {'compiler_flags': | |
| 18 '-fsanitize=memory -fsanitize-memory-track-origins -g -fPIC -w' | |
| 19 }, | |
| 20 } | |
| 16 | 21 |
| 17 | 22 |
| 18 class ScopedChangeDirectory(object): | 23 class ScopedChangeDirectory(object): |
| 19 """Changes current working directory and restores it back automatically.""" | 24 """Changes current working directory and restores it back automatically.""" |
| 20 def __init__(self, path): | 25 def __init__(self, path): |
| 21 self.path = path | 26 self.path = path |
| 22 self.old_path = '' | 27 self.old_path = '' |
| 23 | 28 |
| 24 def __enter__(self): | 29 def __enter__(self): |
| 25 self.old_path = os.getcwd() | 30 self.old_path = os.getcwd() |
| 26 os.chdir(self.path) | 31 os.chdir(self.path) |
| 27 | 32 |
| 28 def __exit__(self, exc_type, exc_value, traceback): | 33 def __exit__(self, exc_type, exc_value, traceback): |
| 29 os.chdir(self.old_path) | 34 os.chdir(self.old_path) |
| 30 | 35 |
| 31 | 36 |
| 32 def get_script_absolute_path(): | 37 def get_script_absolute_path(): |
| 33 return os.path.dirname(os.path.abspath(__file__)) | 38 return os.path.dirname(os.path.abspath(__file__)) |
| 34 | 39 |
| 35 | 40 |
| 36 def get_library_build_dependencies(library): | 41 def get_library_build_dependencies(library): |
| 37 command = 'apt-get -s build-dep %s | grep Inst | cut -d " " -f 2' % library | 42 command = 'apt-get -s build-dep %s | grep Inst | cut -d " " -f 2' % library |
| 38 command_result = subprocess.Popen(command, stdout=subprocess.PIPE, | 43 command_result = subprocess.Popen(command, stdout=subprocess.PIPE, |
| 39 shell=True) | 44 shell=True) |
| 45 if command_result.wait(): | |
| 46 raise Exception("Failed to determine build dependencies for %s" % library) | |
| 40 build_dependencies = [l.strip() for l in command_result.stdout] | 47 build_dependencies = [l.strip() for l in command_result.stdout] |
| 41 return build_dependencies | 48 return build_dependencies |
| 42 | 49 |
| 43 | 50 |
| 44 def download_build_install(parsed_arguments): | 51 def download_build_install(parsed_arguments): |
| 45 sanitizer_flag = SUPPORTED_SANITIZERS[parsed_arguments.sanitizer_type] | 52 sanitizer_params = SUPPORTED_SANITIZERS[parsed_arguments.sanitizer_type] |
| 46 | 53 |
| 47 environment = os.environ.copy() | 54 environment = os.environ.copy() |
| 48 environment['CFLAGS'] = '-fsanitize=%s -g -fPIC -w' % sanitizer_flag | 55 environment['CFLAGS'] = sanitizer_params['compiler_flags'] |
| 49 environment['CXXFLAGS'] = '-fsanitize=%s -g -fPIC -w' % sanitizer_flag | 56 environment['CXXFLAGS'] = sanitizer_params['compiler_flags'] |
| 50 # We use XORIGIN as RPATH and after building library replace it to $ORIGIN | 57 # We use XORIGIN as RPATH and after building library replace it to $ORIGIN |
| 51 # The reason: this flag goes through configure script and makefiles | 58 # The reason: this flag goes through configure script and makefiles |
| 52 # differently for different libraries. So the dollar sign '$' should be | 59 # differently for different libraries. So the dollar sign '$' should be |
| 53 # differently escaped. Instead of having problems with that it just | 60 # differently escaped. Instead of having problems with that it just |
| 54 # uses XORIGIN to build library and after that replaces it to $ORIGIN | 61 # uses XORIGIN to build library and after that replaces it to $ORIGIN |
| 55 # directly in .so file. | 62 # directly in .so file. |
| 56 environment['LDFLAGS'] = '-Wl,-z,origin -Wl,-R,XORIGIN/.' | 63 environment['LDFLAGS'] = '-Wl,-z,origin -Wl,-R,XORIGIN/.' |
|
Alexander Potapenko
2013/12/03 11:46:46
Aren't you passing -fsanitize=... to the linker?
alextaran1
2013/12/03 12:15:55
Sorry, my fault, due to http://clang.llvm.org/docs
| |
| 57 | 64 |
| 58 library_directory = '%s/%s' % (parsed_arguments.intermediate_directory, | 65 library_directory = '%s/%s' % (parsed_arguments.intermediate_directory, |
| 59 parsed_arguments.library) | 66 parsed_arguments.library) |
| 60 | 67 |
| 61 install_prefix = '%s/%s/instrumented_libraries/%s' % ( | 68 install_prefix = '%s/%s/instrumented_libraries/%s' % ( |
| 62 get_script_absolute_path(), | 69 get_script_absolute_path(), |
| 63 parsed_arguments.product_directory, | 70 parsed_arguments.product_directory, |
| 64 parsed_arguments.sanitizer_type) | 71 parsed_arguments.sanitizer_type) |
| 65 | 72 |
| 66 if not os.path.exists(library_directory): | 73 if not os.path.exists(library_directory): |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 print >> sys.stderr, 'One-liner for APT:' | 129 print >> sys.stderr, 'One-liner for APT:' |
| 123 print >> sys.stderr, 'sudo apt-get -y --no-remove build-dep %s' % \ | 130 print >> sys.stderr, 'sudo apt-get -y --no-remove build-dep %s' % \ |
| 124 parsed_arguments.library | 131 parsed_arguments.library |
| 125 sys.exit(1) | 132 sys.exit(1) |
| 126 | 133 |
| 127 download_build_install(parsed_arguments) | 134 download_build_install(parsed_arguments) |
| 128 | 135 |
| 129 | 136 |
| 130 if __name__ == '__main__': | 137 if __name__ == '__main__': |
| 131 main() | 138 main() |
| OLD | NEW |