Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | |
| 3 | import argparse |
| 4 | import sys |
| 5 | import subprocess |
| 6 | import re |
| 7 | import os |
| 8 | import os.path |
| 9 | import string |
| 10 | import shutil |
| 11 | import errno |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 12 | import queue |
| 13 | import threading |
Brian Silverman | f2bbe09 | 2014-05-13 16:55:03 -0700 | [diff] [blame] | 14 | import pty |
Brian Silverman | 6bca472 | 2014-05-20 17:02:49 -0700 | [diff] [blame^] | 15 | import signal |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 16 | |
| 17 | class TestThread(threading.Thread): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 18 | """Runs 1 test and keeps track of its current state. |
| 19 | |
| 20 | A TestThread is either waiting to start the test, actually running it, done, |
| 21 | running it, or stopped. The first 3 always happen in that order and can |
| 22 | change to stopped at any time. |
| 23 | |
| 24 | It will finish (ie join() will return) once the process has exited, at which |
| 25 | point accessing process to see the status is OK. |
| 26 | |
| 27 | Attributes: |
| 28 | executable: The file path of the executable to run. |
| 29 | env: The environment variables to set. |
| 30 | done_queue: A queue.Queue to place self on once done running the test. |
| 31 | start_semaphore: A threading.Semaphore to wait on before starting. |
| 32 | process_lock: A lock around process. |
| 33 | process: The currently executing test process or None. Synchronized by |
| 34 | process_lock. |
| 35 | stopped: True if we're stopped. |
| 36 | """ |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 37 | def __init__(self, executable, env, done_queue, start_semaphore): |
| 38 | super(TestThread, self).__init__( |
| 39 | name=os.path.split(executable)[1]) |
| 40 | |
| 41 | self.executable = executable |
| 42 | self.env = env |
| 43 | self.done_queue = done_queue |
| 44 | self.start_semaphore = start_semaphore |
| 45 | |
| 46 | self.process_lock = threading.Lock() |
| 47 | self.process = None |
| 48 | self.stopped = False |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 49 | self.returncode = None |
| 50 | self.output = None |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 51 | |
| 52 | def run(self): |
| 53 | with self.start_semaphore: |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 54 | if self.stopped: |
| 55 | return |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 56 | test_output('Starting test %s...' % self.name) |
Brian Silverman | f2bbe09 | 2014-05-13 16:55:03 -0700 | [diff] [blame] | 57 | self.output, subprocess_output = pty.openpty() |
| 58 | try: |
| 59 | with self.process_lock: |
| 60 | self.process = subprocess.Popen(self.executable, |
| 61 | env=self.env, |
| 62 | stderr=subprocess.STDOUT, |
| 63 | stdout=subprocess_output, |
| 64 | stdin=open(os.devnull, 'r')) |
| 65 | finally: |
| 66 | os.close(subprocess_output) |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 67 | self.process.wait() |
| 68 | with self.process_lock: |
| 69 | self.returncode = self.process.returncode |
| 70 | self.process = None |
| 71 | if not self.stopped: |
| 72 | self.done_queue.put(self) |
| 73 | |
| 74 | def terminate_process(self): |
Brian Silverman | bf0e1db | 2014-05-10 22:13:15 -0700 | [diff] [blame] | 75 | """Asks any currently running process to stop.""" |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 76 | with self.process_lock: |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 77 | if not self.process: |
| 78 | return |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 79 | self.process.terminate() |
| 80 | def kill_process(self): |
Brian Silverman | bf0e1db | 2014-05-10 22:13:15 -0700 | [diff] [blame] | 81 | """Forcibly terminates any running process.""" |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 82 | with self.process_lock: |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 83 | if not self.process: |
| 84 | return |
Brian Silverman | 6bca472 | 2014-05-20 17:02:49 -0700 | [diff] [blame^] | 85 | try: |
| 86 | self.process.kill() |
| 87 | except OSError as e: |
| 88 | if e.errno == errno.ESRCH: |
| 89 | # We don't really care if it's already gone. |
| 90 | pass |
| 91 | else: |
| 92 | raise e |
Brian Silverman | bf0e1db | 2014-05-10 22:13:15 -0700 | [diff] [blame] | 93 | def stop(self): |
| 94 | """Changes self to the stopped state.""" |
| 95 | with self.process_lock: |
| 96 | self.stopped = True |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 97 | |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 98 | def aos_path(): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 99 | """Returns: |
| 100 | A relative path to the aos directory. |
| 101 | """ |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 102 | return os.path.join(os.path.dirname(__file__), '..') |
| 103 | |
| 104 | def get_ip(device): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 105 | """Retrieves the IP address for a given device.""" |
| 106 | FILENAME = os.path.normpath(os.path.join(aos_path(), '..', |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 107 | 'output', 'ip_base.txt')) |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 108 | if not os.access(FILENAME, os.R_OK): |
| 109 | os.makedirs(os.path.dirname(FILENAME), exist_ok=True) |
| 110 | with open(FILENAME, 'w') as f: |
| 111 | f.write('10.9.71') |
| 112 | with open(FILENAME, 'r') as f: |
| 113 | base = f.readline() |
| 114 | if device == 'prime': |
| 115 | return base + '.179' |
| 116 | elif device == 'robot': |
| 117 | return base + '.2' |
| 118 | else: |
| 119 | raise Exception('Unknown device %s to get an IP address for.' % device) |
| 120 | |
Brian Silverman | a9b1e5c | 2014-04-30 18:08:04 -0700 | [diff] [blame] | 121 | def user_output(message): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 122 | """Prints message to the user.""" |
Brian Silverman | a9b1e5c | 2014-04-30 18:08:04 -0700 | [diff] [blame] | 123 | print('build.py: ' + message, file=sys.stderr) |
| 124 | |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 125 | # A lock to avoid making a mess intermingling test-related messages. |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 126 | test_output_lock = threading.RLock() |
| 127 | def test_output(message): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 128 | """Prints message to the user. Intended for messages related to tests.""" |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 129 | with test_output_lock: |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 130 | print('tests: ' + message, file=sys.stdout) |
| 131 | |
| 132 | def call_download_externals(argument): |
| 133 | """Calls download_externals.sh for a given set of externals. |
| 134 | |
| 135 | Args: |
| 136 | argument: The argument to pass to the shell script to tell it what to |
| 137 | download. |
| 138 | """ |
| 139 | subprocess.check_call( |
| 140 | (os.path.join(aos_path(), 'build', 'download_externals.sh'), |
| 141 | argument), |
| 142 | stdin=open(os.devnull, 'r')) |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 143 | |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 144 | class Processor(object): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 145 | """Represents a processor architecture we can build for.""" |
| 146 | |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 147 | class UnknownPlatform(Exception): |
| 148 | def __init__(self, message): |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 149 | super(Processor.UnknownPlatform, self).__init__() |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 150 | self.message = message |
| 151 | |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 152 | class Platform(object): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 153 | """Represents a single way to build the code.""" |
| 154 | |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 155 | def outdir(self): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 156 | """Returns: |
| 157 | The path of the directory build outputs get put in to. |
| 158 | """ |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 159 | return os.path.join( |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 160 | aos_path(), '..', 'output', self.outname()) |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 161 | def build_ninja(self): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 162 | """Returns: |
| 163 | The path of the build.ninja file. |
| 164 | """ |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 165 | return os.path.join(self.outdir(), 'build.ninja') |
| 166 | |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 167 | def do_deploy(self, dry_run, command): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 168 | """Helper for subclasses to implement deploy. |
| 169 | |
| 170 | Args: |
| 171 | dry_run: If True, prints the command instead of actually running it. |
| 172 | command: A tuple of command-line arguments. |
| 173 | """ |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 174 | real_command = (('echo',) + command) if dry_run else command |
| 175 | subprocess.check_call(real_command, stdin=open(os.devnull, 'r')) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 176 | |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 177 | def deploy(self, dry_run): |
| 178 | """Downloads the compiled code to the target computer.""" |
| 179 | raise NotImplementedError('deploy should be overriden') |
| 180 | def outname(self): |
| 181 | """Returns: |
| 182 | The name of the directory the code will be compiled to. |
| 183 | """ |
| 184 | raise NotImplementedError('outname should be overriden') |
| 185 | def os(self): |
| 186 | """Returns: |
| 187 | The name of the operating system this platform is for. |
| 188 | |
| 189 | This will be used as the value of the OS gyp variable. |
| 190 | """ |
| 191 | raise NotImplementedError('os should be overriden') |
| 192 | def gyp_platform(self): |
| 193 | """Returns: |
| 194 | The platform name the .gyp files know. |
| 195 | |
| 196 | This will be used as the value of the PLATFORM gyp variable. |
| 197 | """ |
| 198 | raise NotImplementedError('gyp_platform should be overriden') |
| 199 | def architecture(self): |
| 200 | """Returns: |
| 201 | The processor architecture for this platform. |
| 202 | |
| 203 | This will be used as the value of the ARCHITECTURE gyp variable. |
| 204 | """ |
| 205 | raise NotImplementedError('architecture should be overriden') |
| 206 | def compiler(self): |
| 207 | """Returns: |
| 208 | The compiler used for this platform. |
| 209 | |
| 210 | Everything before the first _ will be used as the value of the |
| 211 | COMPILER gyp variable and the whole thing will be used as the value |
| 212 | of the FULL_COMPILER gyp variable. |
| 213 | """ |
| 214 | raise NotImplementedError('compiler should be overriden') |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 215 | def sanitizer(self): |
| 216 | """Returns: |
| 217 | The sanitizer used on this platform. |
| 218 | |
| 219 | This will be used as the value of the SANITIZER gyp variable. |
| 220 | |
| 221 | "none" if there isn't one. |
| 222 | """ |
| 223 | raise NotImplementedError('sanitizer should be overriden') |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 224 | def debug(self): |
| 225 | """Returns: |
| 226 | Whether or not this platform compiles with debugging information. |
| 227 | |
| 228 | The DEBUG gyp variable will be set to "yes" or "no" based on this. |
| 229 | """ |
| 230 | raise NotImplementedError('debug should be overriden') |
| 231 | def build_env(self): |
| 232 | """Returns: |
| 233 | A map of environment variables to set while building this platform. |
| 234 | """ |
| 235 | raise NotImplementedError('build_env should be overriden') |
Brian Silverman | bd380fd | 2014-05-13 16:55:24 -0700 | [diff] [blame] | 236 | def priority(self): |
| 237 | """Returns: |
| 238 | A relative priority for this platform relative to other ones. |
| 239 | |
| 240 | Higher priority platforms will get built, tested, etc first. Generally, |
| 241 | platforms which give higher-quality compiler errors etc should come first. |
| 242 | """ |
| 243 | return 0 |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 244 | |
Brian Silverman | 9b7a684 | 2014-05-05 16:19:11 -0700 | [diff] [blame] | 245 | def check_installed(self, platforms, is_deploy): |
| 246 | """Makes sure that everything necessary to build platforms are installed.""" |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 247 | raise NotImplementedError('check_installed should be overriden') |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 248 | def parse_platforms(self, platforms_string): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 249 | """Args: |
| 250 | string: A user-supplied string saying which platforms to select. |
| 251 | |
| 252 | Returns: |
| 253 | A tuple of Platform objects. |
| 254 | |
| 255 | Raises: |
| 256 | Processor.UnknownPlatform: Parsing string didn't work out. |
| 257 | """ |
| 258 | raise NotImplementedError('parse_platforms should be overriden') |
| 259 | def extra_gyp_flags(self): |
| 260 | """Returns: |
| 261 | A tuple of extra flags to pass to gyp (if any). |
| 262 | """ |
| 263 | return () |
| 264 | def modify_ninja_file(self, ninja_file): |
| 265 | """Modifies a freshly generated ninja file as necessary. |
| 266 | |
| 267 | Args: |
| 268 | ninja_file: Path to the file to modify. |
| 269 | """ |
| 270 | pass |
| 271 | def download_externals(self, platforms): |
| 272 | """Calls download_externals as appropriate to build platforms. |
| 273 | |
| 274 | Args: |
| 275 | platforms: A list of platforms to download external libraries for. |
| 276 | """ |
| 277 | raise NotImplementedError('download_externals should be overriden') |
| 278 | |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 279 | def do_check_installed(self, other_packages): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 280 | """Helper for subclasses to implement check_installed. |
| 281 | |
| 282 | Args: |
| 283 | other_packages: A tuple of platform-specific packages to check for.""" |
Brian Silverman | 9b7a684 | 2014-05-05 16:19:11 -0700 | [diff] [blame] | 284 | all_packages = other_packages |
| 285 | # Necessary to build stuff. |
| 286 | all_packages += ('ccache', 'make') |
| 287 | # Necessary to download stuff to build. |
| 288 | all_packages += ('wget', 'git', 'subversion', 'patch', 'unzip', 'bzip2') |
| 289 | # Necessary to build externals stuff. |
| 290 | all_packages += ('python', 'gcc', 'g++') |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 291 | try: |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 292 | # TODO(brians): Check versions too. |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 293 | result = subprocess.check_output( |
| 294 | ('dpkg-query', '--show') + all_packages, |
| 295 | stdin=open(os.devnull, 'r'), |
| 296 | stderr=subprocess.STDOUT) |
| 297 | except subprocess.CalledProcessError as e: |
Brian Silverman | 9b7a684 | 2014-05-05 16:19:11 -0700 | [diff] [blame] | 298 | output = e.output.decode('utf-8').rstrip() |
| 299 | not_found = [] |
| 300 | for line in output.splitlines(True): |
| 301 | match = re.match(r'dpkg-query: no packages found matching (.*)', |
| 302 | line) |
| 303 | if match: |
| 304 | not_found.append(match.group(1)) |
| 305 | user_output('Some packages not installed: %s.' % ', '.join(not_found)) |
| 306 | user_output('Try something like `sudo apt-get install %s`.' % |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 307 | ' '.join(not_found)) |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 308 | exit(1) |
| 309 | |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 310 | class CRIOProcessor(Processor): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 311 | """A Processor subclass for building cRIO code.""" |
| 312 | |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 313 | class Platform(Processor.Platform): |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 314 | def __init__(self, debug, wind_base): |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 315 | super(CRIOProcessor.Platform, self).__init__() |
| 316 | |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 317 | self.__debug = debug |
| 318 | self.__wind_base = wind_base |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 319 | |
| 320 | def __repr__(self): |
Brian Silverman | 9b7a684 | 2014-05-05 16:19:11 -0700 | [diff] [blame] | 321 | return 'CRIOProcessor.Platform(debug=%s)' % self.debug() |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 322 | def __str__(self): |
Brian Silverman | 9b7a684 | 2014-05-05 16:19:11 -0700 | [diff] [blame] | 323 | return 'crio%s' % ('-debug' if self.debug() else '') |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 324 | |
| 325 | def outname(self): |
Brian Silverman | 9b7a684 | 2014-05-05 16:19:11 -0700 | [diff] [blame] | 326 | return 'crio-debug' if self.debug() else 'crio' |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 327 | def os(self): |
| 328 | return 'vxworks' |
| 329 | def gyp_platform(self): |
| 330 | return 'crio' |
| 331 | def architecture(self): |
| 332 | return 'ppc' |
| 333 | def compiler(self): |
| 334 | return 'gcc' |
Brian Silverman | 9b7a684 | 2014-05-05 16:19:11 -0700 | [diff] [blame] | 335 | def sanitizer(self): |
| 336 | return 'none' |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 337 | def debug(self): |
| 338 | return self.__debug |
| 339 | def wind_base(self): |
| 340 | return self.__wind_base |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 341 | |
Brian Silverman | e48c09a | 2014-04-30 18:04:58 -0700 | [diff] [blame] | 342 | # TODO(brians): test this |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 343 | def deploy(self, dry_run): |
| 344 | self.do_deploy(dry_run, |
| 345 | ('ncftpput', get_ip('robot'), '/', |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 346 | os.path.join(self.outdir(), 'lib', |
| 347 | 'FRC_UserProgram.out'))) |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 348 | |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 349 | def build_env(self): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 350 | return {'WIND_BASE': self.wind_base()} |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 351 | |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 352 | def __init__(self): |
| 353 | super(CRIOProcessor, self).__init__() |
| 354 | |
| 355 | if 'WIND_BASE' in os.environ: |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 356 | self.__wind_base = os.environ['WIND_BASE'] |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 357 | else: |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 358 | self.__wind_base = '/usr/local/powerpc-wrs-vxworks/wind_base' |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 359 | |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 360 | def parse_platforms(self, platforms_string): |
| 361 | if platforms_string is None or platforms_string == 'crio': |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 362 | return (CRIOProcessor.Platform(False, self.wind_base()),) |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 363 | elif string == 'crio-debug' or string == 'debug': |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 364 | return (CRIOProcessor.Platform(True, self.wind_base()),) |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 365 | else: |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 366 | raise Processor.UnknownPlatform( |
| 367 | 'Unknown cRIO platform "%s".' % platforms_string) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 368 | |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 369 | def wind_base(self): |
| 370 | return self.__wind_base |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 371 | |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 372 | def extra_gyp_flags(self): |
| 373 | return ('-DWIND_BASE=%s' % self.wind_base(),) |
| 374 | |
| 375 | def modify_ninja_file(self, ninja_file): |
| 376 | subprocess.check_call( |
| 377 | ('sed', '-i', |
| 378 | 's/nm -gD/nm/g', ninja_file), |
| 379 | stdin=open(os.devnull, 'r')) |
| 380 | |
| 381 | def download_externals(self, _): |
| 382 | call_download_externals('crio') |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 383 | |
Brian Silverman | 9b7a684 | 2014-05-05 16:19:11 -0700 | [diff] [blame] | 384 | def check_installed(self, platforms, is_deploy): |
| 385 | packages = ('powerpc-wrs-vxworks', 'tcl') |
| 386 | if is_deploy: |
| 387 | packages += ('ncftp',) |
| 388 | self.do_check_installed(packages) |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 389 | |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 390 | class PrimeProcessor(Processor): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 391 | """A Processor subclass for building prime code.""" |
| 392 | |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 393 | class Platform(Processor.Platform): |
Brian Silverman | f0d3c78 | 2014-05-02 23:56:32 -0700 | [diff] [blame] | 394 | def __init__(self, architecture, compiler, debug, sanitizer): |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 395 | super(PrimeProcessor.Platform, self).__init__() |
| 396 | |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 397 | self.__architecture = architecture |
| 398 | self.__compiler = compiler |
| 399 | self.__debug = debug |
| 400 | self.__sanitizer = sanitizer |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 401 | |
| 402 | def __repr__(self): |
Brian Silverman | f0d3c78 | 2014-05-02 23:56:32 -0700 | [diff] [blame] | 403 | return 'PrimeProcessor.Platform(architecture=%s, compiler=%s, debug=%s' \ |
| 404 | ', sanitizer=%s)' \ |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 405 | % (self.architecture(), self.compiler(), self.debug(), |
| 406 | self.sanitizer()) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 407 | def __str__(self): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 408 | return '%s-%s%s-%s' % (self.architecture(), self.compiler(), |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 409 | '-debug' if self.debug() else '', self.sanitizer()) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 410 | |
| 411 | def os(self): |
| 412 | return 'linux' |
| 413 | def gyp_platform(self): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 414 | return '%s-%s-%s' % (self.os(), self.architecture(), self.compiler()) |
| 415 | def architecture(self): |
| 416 | return self.__architecture |
| 417 | def compiler(self): |
| 418 | return self.__compiler |
| 419 | def sanitizer(self): |
| 420 | return self.__sanitizer |
| 421 | def debug(self): |
| 422 | return self.__debug |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 423 | |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 424 | def outname(self): |
| 425 | return str(self) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 426 | |
Brian Silverman | bd380fd | 2014-05-13 16:55:24 -0700 | [diff] [blame] | 427 | def priority(self): |
| 428 | r = 0 |
| 429 | if self.compiler() == 'gcc': |
| 430 | r -= 100 |
| 431 | elif self.compiler() == 'clang': |
| 432 | r += 100 |
| 433 | if self.sanitizer() != 'none': |
| 434 | r -= 50 |
| 435 | elif self.debug(): |
| 436 | r -= 10 |
| 437 | if self.architecture() == 'amd64': |
| 438 | r += 5 |
| 439 | return r |
| 440 | |
Brian Silverman | e48c09a | 2014-04-30 18:04:58 -0700 | [diff] [blame] | 441 | # TODO(brians): test this |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 442 | def deploy(self, dry_run): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 443 | # Downloads code to the prime in a way that avoids clashing too badly with |
| 444 | # starter (like the naive download everything one at a time). |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 445 | SUM = 'md5sum' |
| 446 | TARGET_DIR = '/home/driver/robot_code/bin' |
| 447 | TEMP_DIR = '/tmp/aos_downloader' |
| 448 | TARGET = 'driver@' + get_ip('prime') |
| 449 | |
| 450 | from_dir = os.path.join(self.outdir(), 'outputs') |
| 451 | sums = subprocess.check_output((SUM,) + tuple(os.listdir(from_dir)), |
| 452 | stdin=open(os.devnull, 'r'), |
| 453 | cwd=from_dir) |
| 454 | to_download = subprocess.check_output( |
| 455 | ('ssh', TARGET, |
| 456 | """rm -rf {TMPDIR} && mkdir {TMPDIR} && cd {TO_DIR} |
| 457 | && echo '{SUMS}' | {SUM} --check --quiet |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 458 | |& grep -F FAILED | sed 's/^\\(.*\\): FAILED.*"'$'"/\\1/g'""". |
| 459 | format(TMPDIR=TEMP_DIR, TO_DIR=TARGET_DIR, SUMS=sums, SUM=SUM))) |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 460 | if not to_download: |
Brian Silverman | a9b1e5c | 2014-04-30 18:08:04 -0700 | [diff] [blame] | 461 | user_output("Nothing to download") |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 462 | return |
| 463 | self.do_deploy( |
| 464 | dry_run, |
| 465 | ('scp', '-o', 'Compression yes') + to_download |
| 466 | + (('%s:%s' % (TARGET, TEMP_DIR)),)) |
| 467 | if not dry_run: |
| 468 | subprocess.check_call( |
| 469 | ('ssh', TARGET, |
| 470 | """mv {TMPDIR}/* {TO_DIR} |
| 471 | && echo 'Done moving new executables into place' |
| 472 | && ionice -c 3 bash -c 'sync && sync && sync'""".format( |
| 473 | TMPDIR=TEMP_DIR, TO_DIR=TARGET_DIR))) |
| 474 | |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 475 | def build_env(self): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 476 | OTHER_SYSROOT = '/opt/clang-3.5/' |
| 477 | SYMBOLIZER_PATH = OTHER_SYSROOT + 'bin/llvm-symbolizer' |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 478 | r = {} |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 479 | if self.compiler() == 'clang' or self.compiler() == 'gcc_4.8': |
| 480 | r['LD_LIBRARY_PATH'] = OTHER_SYSROOT + 'lib64' |
| 481 | if self.sanitizer() == 'address': |
| 482 | r['ASAN_SYMBOLIZER_PATH'] = SYMBOLIZER_PATH |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 483 | r['ASAN_OPTIONS'] = \ |
| 484 | 'detect_leaks=1:check_initialization_order=1:strict_init_order=1' |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 485 | elif self.sanitizer() == 'memory': |
| 486 | r['MSAN_SYMBOLIZER_PATH'] = SYMBOLIZER_PATH |
| 487 | elif self.sanitizer() == 'thread': |
| 488 | r['TSAN_OPTIONS'] = 'external_symbolizer_path=' + SYMBOLIZER_PATH |
Brian Silverman | d3fac73 | 2014-05-03 16:03:46 -0700 | [diff] [blame] | 489 | |
| 490 | r['CCACHE_COMPRESS'] = 'yes' |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 491 | r['CCACHE_DIR'] = os.path.abspath(os.path.join(aos_path(), '..', 'output', |
| 492 | 'ccache_dir')) |
Brian Silverman | d3fac73 | 2014-05-03 16:03:46 -0700 | [diff] [blame] | 493 | r['CCACHE_HASHDIR'] = 'yes' |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 494 | if self.compiler() == 'clang': |
Brian Silverman | d3fac73 | 2014-05-03 16:03:46 -0700 | [diff] [blame] | 495 | # clang doesn't like being run directly on the preprocessed files. |
| 496 | r['CCACHE_CPP2'] = 'yes' |
| 497 | # Without this, ccache slows down because of the generated header files. |
| 498 | # The race condition that this opens up isn't a problem because the build |
| 499 | # system finishes modifying header files before compiling anything that |
| 500 | # uses them. |
| 501 | r['CCACHE_SLOPPINESS'] = 'include_file_mtime' |
Brian Silverman | d3fac73 | 2014-05-03 16:03:46 -0700 | [diff] [blame] | 502 | |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 503 | if self.architecture() == 'amd64': |
Brian Silverman | d3fac73 | 2014-05-03 16:03:46 -0700 | [diff] [blame] | 504 | r['PATH'] = os.path.join(aos_path(), 'build', 'bin-ld.gold') + \ |
| 505 | ':' + os.environ['PATH'] |
| 506 | |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 507 | return r |
| 508 | |
Brian Silverman | 47cd6f6 | 2014-05-03 10:35:52 -0700 | [diff] [blame] | 509 | ARCHITECTURES = ('arm', 'amd64') |
| 510 | COMPILERS = ('clang', 'gcc', 'gcc_4.8') |
| 511 | SANITIZERS = ('address', 'undefined', 'integer', 'memory', 'thread', 'none') |
| 512 | SANITIZER_TEST_WARNINGS = { |
| 513 | 'memory': (True, |
| 514 | """We don't have all of the libraries instrumented which leads to lots of false |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 515 | errors with msan (especially stdlibc++). |
| 516 | TODO(brians): Figure out a way to deal with it."""), |
Brian Silverman | 47cd6f6 | 2014-05-03 10:35:52 -0700 | [diff] [blame] | 517 | } |
Brian Silverman | a5301e3 | 2014-05-03 10:51:49 -0700 | [diff] [blame] | 518 | PIE_SANITIZERS = ('memory', 'thread') |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 519 | |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 520 | def __init__(self, is_test, is_deploy): |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 521 | super(PrimeProcessor, self).__init__() |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 522 | |
| 523 | platforms = [] |
| 524 | for architecture in PrimeProcessor.ARCHITECTURES: |
| 525 | for compiler in PrimeProcessor.COMPILERS: |
| 526 | for debug in [True, False]: |
Brian Silverman | 47cd6f6 | 2014-05-03 10:35:52 -0700 | [diff] [blame] | 527 | if architecture == 'arm' and compiler == 'gcc_4.8': |
| 528 | # We don't have a compiler to use here. |
| 529 | continue |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 530 | platforms.append( |
Brian Silverman | f0d3c78 | 2014-05-02 23:56:32 -0700 | [diff] [blame] | 531 | PrimeProcessor.Platform(architecture, compiler, debug, 'none')) |
| 532 | for sanitizer in PrimeProcessor.SANITIZERS: |
Brian Silverman | 47cd6f6 | 2014-05-03 10:35:52 -0700 | [diff] [blame] | 533 | for compiler in ('gcc_4.8', 'clang'): |
| 534 | if compiler == 'gcc_4.8' and (sanitizer == 'undefined' or |
| 535 | sanitizer == 'integer' or |
| 536 | sanitizer == 'memory'): |
| 537 | # GCC 4.8 doesn't support these sanitizers. |
| 538 | continue |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 539 | if sanitizer == 'none': |
| 540 | # We already added sanitizer == 'none' above. |
| 541 | continue |
| 542 | platforms.append( |
| 543 | PrimeProcessor.Platform('amd64', compiler, True, sanitizer)) |
| 544 | self.__platforms = frozenset(platforms) |
| 545 | |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 546 | if is_test: |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 547 | default_platforms = self.select_platforms(architecture='amd64', |
| 548 | debug=True) |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 549 | for sanitizer, warning in PrimeProcessor.SANITIZER_TEST_WARNINGS.items(): |
| 550 | if warning[0]: |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 551 | default_platforms -= self.select_platforms(sanitizer=sanitizer) |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 552 | elif is_deploy: |
| 553 | # TODO(brians): Switch to deploying the code built with clang. |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 554 | default_platforms = self.select_platforms(architecture='arm', |
| 555 | compiler='gcc', |
| 556 | debug=False) |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 557 | else: |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 558 | default_platforms = self.select_platforms(debug=False) |
| 559 | self.__default_platforms = frozenset(default_platforms) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 560 | |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 561 | def platforms(self): |
| 562 | return self.__platforms |
| 563 | def default_platforms(self): |
| 564 | return self.__default_platforms |
| 565 | |
| 566 | def download_externals(self, platforms): |
| 567 | to_download = set() |
| 568 | for architecture in PrimeProcessor.ARCHITECTURES: |
| 569 | for sanitizer in PrimeProcessor.PIE_SANITIZERS: |
| 570 | if platforms & self.select_platforms(architecture=architecture, |
| 571 | sanitizer=sanitizer): |
| 572 | to_download.add(architecture + '-fPIE') |
| 573 | if platforms & self.select_platforms(architecture=architecture, |
| 574 | sanitizer='none'): |
| 575 | to_download.add(architecture) |
| 576 | for download_target in to_download: |
| 577 | call_download_externals(download_target) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 578 | |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 579 | def parse_platforms(self, platform_string): |
| 580 | if platform_string is None: |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 581 | return self.default_platforms() |
| 582 | r = self.default_platforms() |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 583 | for part in platform_string.split(','): |
Brian Silverman | 1867aae | 2014-05-05 17:16:34 -0700 | [diff] [blame] | 584 | if part == 'all': |
| 585 | r = self.platforms() |
| 586 | elif part[0] == '+': |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 587 | r = r | self.select_platforms_string(part[1:]) |
| 588 | elif part[0] == '-': |
| 589 | r = r - self.select_platforms_string(part[1:]) |
| 590 | elif part[0] == '=': |
| 591 | r = self.select_platforms_string(part[1:]) |
| 592 | else: |
Brian Silverman | 7cd5ad4 | 2014-04-27 08:11:30 -0500 | [diff] [blame] | 593 | selected = self.select_platforms_string(part) |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 594 | r = r - (self.platforms() - selected) |
Brian Silverman | 7cd5ad4 | 2014-04-27 08:11:30 -0500 | [diff] [blame] | 595 | if not r: |
| 596 | r = selected |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 597 | return r |
| 598 | |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 599 | def select_platforms(self, architecture=None, compiler=None, debug=None, |
| 600 | sanitizer=None): |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 601 | r = [] |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 602 | for platform in self.platforms(): |
| 603 | if architecture is None or platform.architecture() == architecture: |
| 604 | if compiler is None or platform.compiler() == compiler: |
| 605 | if debug is None or platform.debug() == debug: |
| 606 | if sanitizer is None or platform.sanitizer() == sanitizer: |
Brian Silverman | f0d3c78 | 2014-05-02 23:56:32 -0700 | [diff] [blame] | 607 | r.append(platform) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 608 | return set(r) |
| 609 | |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 610 | def select_platforms_string(self, platforms_string): |
Brian Silverman | f0d3c78 | 2014-05-02 23:56:32 -0700 | [diff] [blame] | 611 | architecture, compiler, debug, sanitizer = None, None, None, None |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 612 | for part in platforms_string.split('-'): |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 613 | if part in PrimeProcessor.ARCHITECTURES: |
| 614 | architecture = part |
| 615 | elif part in PrimeProcessor.COMPILERS: |
| 616 | compiler = part |
| 617 | elif part in ['debug', 'dbg']: |
| 618 | debug = True |
| 619 | elif part in ['release', 'nodebug', 'ndb']: |
| 620 | debug = False |
Brian Silverman | f0d3c78 | 2014-05-02 23:56:32 -0700 | [diff] [blame] | 621 | elif part in PrimeProcessor.SANITIZERS: |
| 622 | sanitizer = part |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 623 | else: |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 624 | raise Processor.UnknownPlatform( |
| 625 | 'Unknown platform string component "%s".' % part) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 626 | return self.select_platforms( |
| 627 | architecture=architecture, |
| 628 | compiler=compiler, |
Brian Silverman | f0d3c78 | 2014-05-02 23:56:32 -0700 | [diff] [blame] | 629 | debug=debug, |
| 630 | sanitizer=sanitizer) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 631 | |
Brian Silverman | 9b7a684 | 2014-05-05 16:19:11 -0700 | [diff] [blame] | 632 | def check_installed(self, platforms, is_deploy): |
| 633 | packages = set(('lzip', 'm4', 'realpath')) |
| 634 | packages.add('ruby') |
| 635 | # clang-format from here gets used for all versions. |
| 636 | packages.add('clang-3.5') |
| 637 | packages.add('arm-eabi-gcc') |
| 638 | for platform in platforms: |
| 639 | if platform.architecture() == 'arm': |
| 640 | packages.add('gcc-4.7-arm-linux-gnueabihf') |
| 641 | packages.add('g++-4.7-arm-linux-gnueabihf') |
| 642 | if platform.compiler() == 'clang' or platform.compiler() == 'gcc_4.8': |
| 643 | packages.add('clang-3.5') |
Brian Silverman | 1867aae | 2014-05-05 17:16:34 -0700 | [diff] [blame] | 644 | if platform.compiler() == 'gcc_4.8': |
| 645 | packages.add('libcloog-isl3:amd64') |
Brian Silverman | 9b7a684 | 2014-05-05 16:19:11 -0700 | [diff] [blame] | 646 | if is_deploy: |
| 647 | packages.add('openssh-client') |
| 648 | if platform.compiler() == 'gcc' and platform.architecture() == 'amd64': |
| 649 | packages.add('gcc-4.7') |
| 650 | packages.add('g++-4.7') |
| 651 | |
| 652 | self.do_check_installed(tuple(packages)) |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 653 | |
Brian Silverman | 6bca472 | 2014-05-20 17:02:49 -0700 | [diff] [blame^] | 654 | def strsignal(num): |
| 655 | # It ends up with SIGIOT instead otherwise, which is weird. |
| 656 | if num == signal.SIGABRT: |
| 657 | return 'SIGABRT' |
| 658 | # SIGCLD is a weird way to spell it. |
| 659 | if num == signal.SIGCHLD: |
| 660 | return 'SIGCHLD' |
| 661 | |
| 662 | SIGNALS_TO_NAMES = dict((getattr(signal, n), n) |
| 663 | for n in dir(signal) if n.startswith('SIG') |
| 664 | and '_' not in n) |
| 665 | return SIGNALS_TO_NAMES.get(num, 'Unknown signal %d' % num) |
| 666 | |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 667 | def main(): |
| 668 | class TryParsingAgain(Exception): |
| 669 | pass |
| 670 | |
| 671 | class TryAgainArgumentParser(argparse.ArgumentParser): |
| 672 | def __init__(self, **kwargs): |
| 673 | super(TryAgainArgumentParser, self).__init__(**kwargs) |
| 674 | |
| 675 | def error(self, message): |
| 676 | raise TryParsingAgain |
| 677 | |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 678 | def set_up_parser(parser, args): |
| 679 | def add_build_args(parser): |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 680 | parser.add_argument( |
| 681 | 'target', |
| 682 | help='target to build', |
| 683 | nargs='*') |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 684 | parser.add_argument( |
| 685 | '--jobs', '-j', |
| 686 | help='number of things to do at once', |
| 687 | type=int) |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 688 | def add_common_args(parser): |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 689 | parser.add_argument( |
| 690 | 'platforms', |
| 691 | help='platform(s) to act on', |
| 692 | nargs='?') |
| 693 | |
| 694 | parser.add_argument('--processor', required=True, help='prime or crio') |
| 695 | parser.add_argument('--main_gyp', required=True, help='main .gyp file') |
| 696 | subparsers = parser.add_subparsers(dest='action_name') |
| 697 | |
| 698 | build_parser = subparsers.add_parser( |
| 699 | 'build', |
| 700 | help='build the code (default)') |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 701 | add_common_args(build_parser) |
| 702 | add_build_args(build_parser) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 703 | |
| 704 | clean_parser = subparsers.add_parser( |
| 705 | 'clean', |
| 706 | help='remove all output directories') |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 707 | add_common_args(clean_parser) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 708 | |
| 709 | deploy_parser = subparsers.add_parser( |
| 710 | 'deploy', |
| 711 | help='build and download the code') |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 712 | add_common_args(deploy_parser) |
| 713 | add_build_args(deploy_parser) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 714 | deploy_parser.add_argument( |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 715 | '-n', '--dry-run', |
| 716 | help="don't actually download anything", |
| 717 | action='store_true') |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 718 | |
Brian Silverman | e48c09a | 2014-04-30 18:04:58 -0700 | [diff] [blame] | 719 | tests_parser = subparsers.add_parser( |
| 720 | 'tests', |
| 721 | help='run tests') |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 722 | add_common_args(tests_parser) |
| 723 | add_build_args(tests_parser) |
Brian Silverman | e48c09a | 2014-04-30 18:04:58 -0700 | [diff] [blame] | 724 | |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 725 | return parser.parse_args(args) |
| 726 | |
| 727 | try: |
| 728 | parser = TryAgainArgumentParser() |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 729 | args = set_up_parser(parser, sys.argv[1:]) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 730 | except TryParsingAgain: |
| 731 | parser = argparse.ArgumentParser() |
| 732 | REQUIRED_ARGS_END = 5 |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 733 | args = set_up_parser(parser, sys.argv[1:REQUIRED_ARGS_END] + ['build'] + |
| 734 | sys.argv[(REQUIRED_ARGS_END):]) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 735 | |
| 736 | if args.processor == 'crio': |
| 737 | processor = CRIOProcessor() |
| 738 | elif args.processor == 'prime': |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 739 | processor = PrimeProcessor(args.action_name == 'tests', |
| 740 | args.action_name == 'deploy') |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 741 | else: |
| 742 | parser.exit(status=1, message='Unknown processor "%s".' % args.processor) |
| 743 | |
| 744 | if 'target' in args: |
| 745 | targets = args.target[:] |
| 746 | else: |
| 747 | targets = [] |
| 748 | unknown_platform_error = None |
| 749 | try: |
| 750 | platforms = processor.parse_platforms(args.platforms) |
| 751 | except Processor.UnknownPlatform as e: |
| 752 | unknown_platform_error = e.message |
| 753 | targets.append(args.platforms) |
| 754 | platforms = processor.parse_platforms(None) |
| 755 | if not platforms: |
Brian Silverman | a9b1e5c | 2014-04-30 18:08:04 -0700 | [diff] [blame] | 756 | user_output("No platforms selected!") |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 757 | exit(1) |
| 758 | |
Brian Silverman | 9b7a684 | 2014-05-05 16:19:11 -0700 | [diff] [blame] | 759 | processor.check_installed(platforms, args.action_name == 'deploy') |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 760 | processor.download_externals(platforms) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 761 | |
| 762 | class ToolsConfig(object): |
| 763 | def __init__(self): |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 764 | self.variables = {'AOS': aos_path()} |
| 765 | with open(os.path.join(aos_path(), 'build', 'tools_config'), 'r') as f: |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 766 | for line in f: |
| 767 | if line[0] == '#': |
| 768 | pass |
| 769 | elif line.isspace(): |
| 770 | pass |
| 771 | else: |
| 772 | new_name, new_value = line.rstrip().split('=') |
| 773 | for name, value in self.variables.items(): |
| 774 | new_value = new_value.replace('${%s}' % name, value) |
| 775 | self.variables[new_name] = new_value |
| 776 | def __getitem__(self, key): |
| 777 | return self.variables[key] |
| 778 | |
| 779 | tools_config = ToolsConfig() |
| 780 | |
| 781 | def handle_clean_error(function, path, excinfo): |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 782 | _, _ = function, path |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 783 | if issubclass(OSError, excinfo[0]): |
| 784 | if excinfo[1].errno == errno.ENOENT: |
| 785 | # Who cares if the file we're deleting isn't there? |
| 786 | return |
| 787 | raise excinfo[1] |
| 788 | |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 789 | def need_to_run_gyp(platform): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 790 | """Determines if we need to run gyp again or not. |
| 791 | |
| 792 | The generated build files are supposed to re-run gyp again themselves, but |
| 793 | that doesn't work (or at least it used to not) and we sometimes want to |
| 794 | modify the results anyways. |
| 795 | |
| 796 | Args: |
| 797 | platform: The platform to check for. |
| 798 | """ |
Brian Silverman | f0d3c78 | 2014-05-02 23:56:32 -0700 | [diff] [blame] | 799 | if not os.path.exists(platform.build_ninja()): |
| 800 | return True |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 801 | if os.path.getmtime(__file__) > os.path.getmtime(platform.build_ninja()): |
| 802 | return True |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 803 | dirs = os.listdir(os.path.join(aos_path(), '..')) |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 804 | # Looking through these folders takes a long time and isn't useful. |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 805 | if dirs.count('output'): |
| 806 | dirs.remove('output') |
| 807 | if dirs.count('.git'): |
| 808 | dirs.remove('.git') |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 809 | return not not subprocess.check_output( |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 810 | ('find',) + tuple(os.path.join(aos_path(), '..', d) for d in dirs) |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 811 | + ('-newer', platform.build_ninja(), |
| 812 | '(', '-name', '*.gyp', '-or', '-name', '*.gypi', ')'), |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 813 | stdin=open(os.devnull, 'r')) |
| 814 | |
| 815 | def env(platform): |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 816 | """Makes sure we pass through important environmental variables. |
| 817 | |
| 818 | Returns: |
| 819 | An environment suitable for passing to subprocess.Popen and friends. |
| 820 | """ |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 821 | build_env = dict(platform.build_env()) |
Brian Silverman | d3fac73 | 2014-05-03 16:03:46 -0700 | [diff] [blame] | 822 | if not 'TERM' in build_env: |
| 823 | build_env['TERM'] = os.environ['TERM'] |
| 824 | if not 'PATH' in build_env: |
| 825 | build_env['PATH'] = os.environ['PATH'] |
Brian Silverman | a4aff56 | 2014-05-02 17:43:50 -0700 | [diff] [blame] | 826 | return build_env |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 827 | |
Brian Silverman | bd380fd | 2014-05-13 16:55:24 -0700 | [diff] [blame] | 828 | sorted_platforms = sorted(platforms, |
| 829 | key=lambda platform: -platform.priority()) |
| 830 | |
Brian Silverman | 47cd6f6 | 2014-05-03 10:35:52 -0700 | [diff] [blame] | 831 | to_build = [] |
Brian Silverman | bd380fd | 2014-05-13 16:55:24 -0700 | [diff] [blame] | 832 | for platform in sorted_platforms: |
Brian Silverman | 47cd6f6 | 2014-05-03 10:35:52 -0700 | [diff] [blame] | 833 | to_build.append(str(platform)) |
| 834 | if len(to_build) > 1: |
| 835 | to_build[-1] = 'and ' + to_build[-1] |
| 836 | user_output('Building %s...' % ', '.join(to_build)) |
| 837 | |
| 838 | if args.action_name == 'tests': |
| 839 | for sanitizer, warning in PrimeProcessor.SANITIZER_TEST_WARNINGS.items(): |
| 840 | warned_about = platforms & processor.select_platforms(sanitizer=sanitizer) |
| 841 | if warned_about: |
| 842 | user_output(warning[1]) |
| 843 | if warning[0]: |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 844 | # TODO(brians): Add a --force flag or something to override this? |
Brian Silverman | 47cd6f6 | 2014-05-03 10:35:52 -0700 | [diff] [blame] | 845 | user_output('Refusing to run tests for sanitizer %s.' % sanitizer) |
| 846 | exit(1) |
| 847 | |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 848 | num = 1 |
Brian Silverman | bd380fd | 2014-05-13 16:55:24 -0700 | [diff] [blame] | 849 | for platform in sorted_platforms: |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 850 | user_output('Building %s (%d/%d)...' % (platform, num, len(platforms))) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 851 | if args.action_name == 'clean': |
| 852 | shutil.rmtree(platform.outdir(), onerror=handle_clean_error) |
| 853 | else: |
| 854 | if need_to_run_gyp(platform): |
Brian Silverman | a9b1e5c | 2014-04-30 18:08:04 -0700 | [diff] [blame] | 855 | user_output('Running gyp...') |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 856 | gyp = subprocess.Popen( |
| 857 | (tools_config['GYP'], |
| 858 | '--check', |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 859 | '--depth=%s' % os.path.join(aos_path(), '..'), |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 860 | '--no-circular-check', |
| 861 | '-f', 'ninja', |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 862 | '-I%s' % os.path.join(aos_path(), 'build', 'aos.gypi'), |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 863 | '-I/dev/stdin', '-Goutput_dir=output', |
| 864 | '-DOS=%s' % platform.os(), |
| 865 | '-DPLATFORM=%s' % platform.gyp_platform(), |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 866 | '-DARCHITECTURE=%s' % platform.architecture(), |
| 867 | '-DCOMPILER=%s' % platform.compiler().split('_')[0], |
| 868 | '-DFULL_COMPILER=%s' % platform.compiler(), |
| 869 | '-DDEBUG=%s' % ('yes' if platform.debug() else 'no'), |
| 870 | '-DSANITIZER=%s' % platform.sanitizer(), |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 871 | '-DSANITIZER_FPIE=%s' % |
| 872 | ('-fPIE' if platform.sanitizer() in PrimeProcessor.PIE_SANITIZERS |
| 873 | else '')) + |
Brian Silverman | b3d5054 | 2014-04-23 14:28:55 -0500 | [diff] [blame] | 874 | processor.extra_gyp_flags() + (args.main_gyp,), |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 875 | stdin=subprocess.PIPE) |
| 876 | gyp.communicate((""" |
| 877 | { |
| 878 | 'target_defaults': { |
| 879 | 'configurations': { |
| 880 | '%s': {} |
| 881 | } |
| 882 | } |
| 883 | }""" % platform.outname()).encode()) |
| 884 | if gyp.returncode: |
Brian Silverman | a9b1e5c | 2014-04-30 18:08:04 -0700 | [diff] [blame] | 885 | user_output("Running gyp failed!") |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 886 | exit(1) |
Brian Silverman | e6bada6 | 2014-05-04 16:16:54 -0700 | [diff] [blame] | 887 | processor.modify_ninja_file(platform.build_ninja()) |
Brian Silverman | 47cd6f6 | 2014-05-03 10:35:52 -0700 | [diff] [blame] | 888 | user_output('Done running gyp') |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 889 | else: |
Brian Silverman | 47cd6f6 | 2014-05-03 10:35:52 -0700 | [diff] [blame] | 890 | user_output("Not running gyp") |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 891 | |
| 892 | try: |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 893 | call = (tools_config['NINJA'], |
| 894 | '-C', platform.outdir()) + tuple(targets) |
| 895 | if args.jobs: |
| 896 | call += ('-j', str(args.jobs)) |
| 897 | subprocess.check_call(call, |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 898 | stdin=open(os.devnull, 'r'), |
| 899 | env=env(platform)) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 900 | except subprocess.CalledProcessError as e: |
| 901 | if unknown_platform_error is not None: |
Brian Silverman | a9b1e5c | 2014-04-30 18:08:04 -0700 | [diff] [blame] | 902 | user_output(unknown_platform_error) |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 903 | raise e |
| 904 | |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 905 | if args.action_name == 'deploy': |
| 906 | platform.deploy(args.dry_run) |
Brian Silverman | e48c09a | 2014-04-30 18:04:58 -0700 | [diff] [blame] | 907 | elif args.action_name == 'tests': |
| 908 | dirname = os.path.join(platform.outdir(), 'tests') |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 909 | done_queue = queue.Queue() |
| 910 | running = [] |
| 911 | if args.jobs: |
| 912 | number_jobs = args.jobs |
| 913 | else: |
| 914 | number_jobs = os.sysconf('SC_NPROCESSORS_ONLN') + 2 |
| 915 | test_start_semaphore = threading.Semaphore(number_jobs) |
| 916 | if targets: |
| 917 | to_run = [] |
| 918 | for target in targets: |
| 919 | if target.endswith('_test'): |
| 920 | to_run.append(target) |
| 921 | else: |
| 922 | to_run = os.listdir(dirname) |
| 923 | for f in to_run: |
| 924 | thread = TestThread(os.path.join(dirname, f), env(platform), done_queue, |
| 925 | test_start_semaphore) |
| 926 | running.append(thread) |
| 927 | thread.start() |
| 928 | try: |
| 929 | while running: |
| 930 | done = done_queue.get() |
| 931 | running.remove(done) |
| 932 | with test_output_lock: |
| 933 | test_output('Output from test %s:' % done.name) |
Brian Silverman | f2bbe09 | 2014-05-13 16:55:03 -0700 | [diff] [blame] | 934 | with os.fdopen(done.output) as output_file: |
| 935 | try: |
| 936 | for line in output_file: |
| 937 | if not sys.stdout.isatty(): |
| 938 | # Remove color escape codes. |
| 939 | line = re.sub(r'\x1B\[[0-9;]*[a-zA-Z]', '', line) |
| 940 | sys.stdout.write(line) |
| 941 | except IOError as e: |
| 942 | # We want to just ignore EIOs from reading the master pty because that just |
| 943 | # means we hit the end. |
| 944 | if e.errno != errno.EIO: |
| 945 | raise e |
| 946 | if not done.returncode: |
| 947 | test_output('Test %s succeeded' % done.name) |
| 948 | else: |
Brian Silverman | 6bca472 | 2014-05-20 17:02:49 -0700 | [diff] [blame^] | 949 | if done.returncode < 0: |
| 950 | sig = -done.returncode |
| 951 | test_output('Test %s was killed by signal %d (%s)' % \ |
| 952 | (done.name, sig, strsignal(sig))) |
| 953 | elif done.returncode != 1: |
| 954 | test_output('Test %s exited with %d' % \ |
| 955 | (done.name, done.returncode)) |
| 956 | else: |
| 957 | test_output('Test %s failed' % done.name) |
| 958 | user_output('Aborting because of test failure for %s.' % \ |
| 959 | platform) |
Brian Silverman | f2bbe09 | 2014-05-13 16:55:03 -0700 | [diff] [blame] | 960 | exit(1) |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 961 | finally: |
| 962 | if running: |
| 963 | test_output('Killing other tests...') |
Brian Silverman | bf0e1db | 2014-05-10 22:13:15 -0700 | [diff] [blame] | 964 | # Stop all of them before killing processes because otherwise stopping some of |
| 965 | # them tends to let other ones that are waiting to start go. |
| 966 | for thread in running: |
| 967 | thread.stop() |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 968 | for thread in running: |
| 969 | thread.terminate_process() |
| 970 | to_remove = [] |
| 971 | for thread in running: |
| 972 | thread.join(5) |
| 973 | if not thread.is_alive(): |
Brian Silverman | 452aaec | 2014-05-05 16:52:18 -0700 | [diff] [blame] | 974 | to_remove.append(thread) |
| 975 | for thread in to_remove: |
| 976 | running.remove(thread) |
Brian Silverman | c3740c3 | 2014-05-04 12:42:47 -0700 | [diff] [blame] | 977 | for thread in running: |
| 978 | test_output( |
| 979 | 'Test %s did not terminate. Killing it.' % thread.name) |
| 980 | thread.kill_process() |
| 981 | thread.join() |
| 982 | test_output('Done killing other tests') |
Brian Silverman | be6cfe2 | 2014-04-27 08:06:27 -0500 | [diff] [blame] | 983 | |
Brian Silverman | c2d8e5a | 2014-05-01 18:33:12 -0700 | [diff] [blame] | 984 | user_output('Done building %s (%d/%d)' % (platform, num, len(platforms))) |
| 985 | num += 1 |
Brian Silverman | a29ebf9 | 2014-04-23 13:08:49 -0500 | [diff] [blame] | 986 | |
| 987 | if __name__ == '__main__': |
| 988 | main() |