| 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 platform | 10 import platform |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 real_path(args.run_before_build) if args.run_before_build else None | 51 real_path(args.run_before_build) if args.run_before_build else None |
| 52 self._sanitizer = args.sanitizer | 52 self._sanitizer = args.sanitizer |
| 53 self._verbose = args.verbose | 53 self._verbose = args.verbose |
| 54 self._clobber = clobber | 54 self._clobber = clobber |
| 55 self._working_dir = os.path.join( | 55 self._working_dir = os.path.join( |
| 56 real_path(args.intermediate_dir), self._package, '') | 56 real_path(args.intermediate_dir), self._package, '') |
| 57 | 57 |
| 58 product_dir = real_path(args.product_dir) | 58 product_dir = real_path(args.product_dir) |
| 59 self._destdir = os.path.join( | 59 self._destdir = os.path.join( |
| 60 product_dir, 'instrumented_libraries', self._sanitizer) | 60 product_dir, 'instrumented_libraries', self._sanitizer) |
| 61 self._source_archives_dir = os.path.join( |
| 62 product_dir, 'instrumented_libraries', 'sources', self._package) |
| 61 | 63 |
| 62 self._cflags = unescape_flags(args.cflags) | 64 self._cflags = unescape_flags(args.cflags) |
| 63 if args.sanitizer_blacklist: | 65 if args.sanitizer_blacklist: |
| 64 blacklist_file = real_path(args.sanitizer_blacklist) | 66 blacklist_file = real_path(args.sanitizer_blacklist) |
| 65 self._cflags += ' -fsanitize-blacklist=%s' % blacklist_file | 67 self._cflags += ' -fsanitize-blacklist=%s' % blacklist_file |
| 66 | 68 |
| 67 self._ldflags = unescape_flags(args.ldflags) | 69 self._ldflags = unescape_flags(args.ldflags) |
| 68 | 70 |
| 69 self.init_build_env() | 71 self.init_build_env() |
| 70 | 72 |
| 71 # Initialized later. | 73 # Initialized later. |
| 72 self._source_dir = None | 74 self._source_dir = None |
| 75 self._source_archives = None |
| 73 | 76 |
| 74 def init_build_env(self): | 77 def init_build_env(self): |
| 75 self._build_env = os.environ.copy() | 78 self._build_env = os.environ.copy() |
| 76 | 79 |
| 77 self._build_env['CC'] = self._cc | 80 self._build_env['CC'] = self._cc |
| 78 self._build_env['CXX'] = self._cxx | 81 self._build_env['CXX'] = self._cxx |
| 79 | 82 |
| 80 self._build_env['CFLAGS'] = self._cflags | 83 self._build_env['CFLAGS'] = self._cflags |
| 81 self._build_env['CXXFLAGS'] = self._cflags | 84 self._build_env['CXXFLAGS'] = self._cflags |
| 82 self._build_env['LDFLAGS'] = self._ldflags | 85 self._build_env['LDFLAGS'] = self._ldflags |
| (...skipping 15 matching lines...) Expand all Loading... |
| 98 child = subprocess.Popen( | 101 child = subprocess.Popen( |
| 99 command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, | 102 command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, |
| 100 env=env, shell=True, cwd=cwd) | 103 env=env, shell=True, cwd=cwd) |
| 101 stdout, stderr = child.communicate() | 104 stdout, stderr = child.communicate() |
| 102 if self._verbose or child.returncode: | 105 if self._verbose or child.returncode: |
| 103 print stdout | 106 print stdout |
| 104 if child.returncode: | 107 if child.returncode: |
| 105 raise Exception('Failed to run: %s' % command) | 108 raise Exception('Failed to run: %s' % command) |
| 106 | 109 |
| 107 def maybe_download_source(self): | 110 def maybe_download_source(self): |
| 108 """Checks out the source code (if needed) and sets self._source_dir.""" | 111 """Checks out the source code (if needed). |
| 112 |
| 113 Checks out the source code for the package, if required (i.e. unless running |
| 114 in no-clobber mode). Initializes self._source_dir and self._source_archives. |
| 115 """ |
| 109 get_fresh_source = self._clobber or not os.path.exists(self._working_dir) | 116 get_fresh_source = self._clobber or not os.path.exists(self._working_dir) |
| 110 if get_fresh_source: | 117 if get_fresh_source: |
| 111 self.shell_call('rm -rf %s' % self._working_dir) | 118 self.shell_call('rm -rf %s' % self._working_dir) |
| 112 os.makedirs(self._working_dir) | 119 os.makedirs(self._working_dir) |
| 113 self.shell_call('apt-get source %s' % self._package, | 120 self.shell_call('apt-get source %s' % self._package, |
| 114 cwd=self._working_dir) | 121 cwd=self._working_dir) |
| 115 | 122 |
| 116 (dirpath, dirnames, filenames) = os.walk(self._working_dir).next() | 123 (dirpath, dirnames, filenames) = os.walk(self._working_dir).next() |
| 124 |
| 117 if len(dirnames) != 1: | 125 if len(dirnames) != 1: |
| 118 raise Exception('apt-get source %s must create exactly one subdirectory.' | 126 raise Exception( |
| 127 '`apt-get source %s\' must create exactly one subdirectory.' |
| 128 % self._package) |
| 129 self._source_dir = os.path.join(dirpath, dirnames[0], '') |
| 130 |
| 131 if len(filenames) == 0: |
| 132 raise Exception('Can\'t find source archives after `apt-get source %s\'.' |
| 119 % self._package) | 133 % self._package) |
| 120 self._source_dir = os.path.join(dirpath, dirnames[0], '') | 134 self._source_archives = \ |
| 135 [os.path.join(dirpath, filename) for filename in filenames] |
| 121 | 136 |
| 122 return get_fresh_source | 137 return get_fresh_source |
| 123 | 138 |
| 124 def patch_source(self): | 139 def patch_source(self): |
| 125 if self._patch: | 140 if self._patch: |
| 126 self.shell_call('patch -p1 -i %s' % self._patch, cwd=self._source_dir) | 141 self.shell_call('patch -p1 -i %s' % self._patch, cwd=self._source_dir) |
| 127 if self._run_before_build: | 142 if self._run_before_build: |
| 128 self.shell_call(self._run_before_build, cwd=self._source_dir) | 143 self.shell_call(self._run_before_build, cwd=self._source_dir) |
| 129 | 144 |
| 145 def copy_source_archives(self): |
| 146 """Copies the downloaded source archives to the output dir. |
| 147 |
| 148 For license compliance purposes, every Chromium build that includes |
| 149 instrumented libraries must include their full source code. |
| 150 """ |
| 151 self.shell_call('rm -rf %s' % self._source_archives_dir) |
| 152 os.makedirs(self._source_archives_dir) |
| 153 for filename in self._source_archives: |
| 154 shutil.copy(filename, self._source_archives_dir) |
| 155 if self._patch: |
| 156 shutil.copy(self._patch, self._source_archives_dir) |
| 157 |
| 130 def download_build_install(self): | 158 def download_build_install(self): |
| 131 got_fresh_source = self.maybe_download_source() | 159 got_fresh_source = self.maybe_download_source() |
| 132 if got_fresh_source: | 160 if got_fresh_source: |
| 133 self.patch_source() | 161 self.patch_source() |
| 162 self.copy_source_archives() |
| 134 | 163 |
| 135 self.shell_call('mkdir -p %s' % self.dest_libdir()) | 164 self.shell_call('mkdir -p %s' % self.dest_libdir()) |
| 136 | 165 |
| 137 try: | 166 try: |
| 138 self.build_and_install() | 167 self.build_and_install() |
| 139 except Exception as exception: | 168 except Exception as exception: |
| 140 print 'ERROR: Failed to build package %s. Have you run ' \ | 169 print 'ERROR: Failed to build package %s. Have you run ' \ |
| 141 'src/third_party/instrumented_libraries/install-build-deps.sh?' % \ | 170 'src/third_party/instrumented_libraries/install-build-deps.sh?' % \ |
| 142 self._package | 171 self._package |
| 143 print | 172 print |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 builder = LibcapBuilder(args, clobber) | 416 builder = LibcapBuilder(args, clobber) |
| 388 elif args.build_method == 'custom_libpci3': | 417 elif args.build_method == 'custom_libpci3': |
| 389 builder = Libpci3Builder(args, clobber) | 418 builder = Libpci3Builder(args, clobber) |
| 390 else: | 419 else: |
| 391 raise Exception('Unrecognized build method: %s' % args.build_method) | 420 raise Exception('Unrecognized build method: %s' % args.build_method) |
| 392 | 421 |
| 393 builder.download_build_install() | 422 builder.download_build_install() |
| 394 | 423 |
| 395 if __name__ == '__main__': | 424 if __name__ == '__main__': |
| 396 main() | 425 main() |
| OLD | NEW |