| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Classes and functions for building Chrome. | 5 """Classes and functions for building Chrome. |
| 6 | 6 |
| 7 This includes functions for running commands to build, as well as | 7 This includes functions for running commands to build, as well as |
| 8 specific rules about which targets to build. | 8 specific rules about which targets to build. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 raise RuntimeError('Failed to set platform environment.') | 57 raise RuntimeError('Failed to set platform environment.') |
| 58 | 58 |
| 59 @staticmethod | 59 @staticmethod |
| 60 def FromOpts(opts): | 60 def FromOpts(opts): |
| 61 """Constructs and returns a Builder object. | 61 """Constructs and returns a Builder object. |
| 62 | 62 |
| 63 Args: | 63 Args: |
| 64 opts: Options parsed from the command-line. | 64 opts: Options parsed from the command-line. |
| 65 """ | 65 """ |
| 66 builder = None | 66 builder = None |
| 67 if opts.target_platform == 'cros': | 67 if opts.target_platform == 'android': |
| 68 builder = CrosBuilder(opts) | |
| 69 elif opts.target_platform == 'android': | |
| 70 builder = AndroidBuilder(opts) | 68 builder = AndroidBuilder(opts) |
| 71 elif opts.target_platform == 'android-chrome': | 69 elif opts.target_platform == 'android-chrome': |
| 72 builder = AndroidChromeBuilder(opts) | 70 builder = AndroidChromeBuilder(opts) |
| 73 else: | 71 else: |
| 74 builder = DesktopBuilder(opts) | 72 builder = DesktopBuilder(opts) |
| 75 return builder | 73 return builder |
| 76 | 74 |
| 77 def Build(self, depot, opts): | 75 def Build(self, depot, opts): |
| 78 """Runs a command to build Chrome.""" | 76 """Runs a command to build Chrome.""" |
| 79 raise NotImplementedError() | 77 raise NotImplementedError() |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 super(AndroidChromeBuilder, self).__init__(opts) | 184 super(AndroidChromeBuilder, self).__init__(opts) |
| 187 | 185 |
| 188 # TODO(qyearsley): Make this a class method and verify that it works with | 186 # TODO(qyearsley): Make this a class method and verify that it works with |
| 189 # a unit test. | 187 # a unit test. |
| 190 # pylint: disable=R0201 | 188 # pylint: disable=R0201 |
| 191 def _GetTargets(self): | 189 def _GetTargets(self): |
| 192 """Returns a list of build targets.""" | 190 """Returns a list of build targets.""" |
| 193 return AndroidBuilder._GetTargets(self) + ['chrome_apk'] | 191 return AndroidBuilder._GetTargets(self) + ['chrome_apk'] |
| 194 | 192 |
| 195 | 193 |
| 196 class CrosBuilder(Builder): | |
| 197 """CrosBuilder is used to build and image ChromeOS/Chromium. | |
| 198 | |
| 199 WARNING(qyearsley, 2014-08-15): This hasn't been tested recently. | |
| 200 """ | |
| 201 | |
| 202 def __init__(self, opts): | |
| 203 super(CrosBuilder, self).__init__(opts) | |
| 204 | |
| 205 @staticmethod | |
| 206 def ImageToTarget(opts): | |
| 207 """Installs latest image to target specified by opts.cros_remote_ip. | |
| 208 | |
| 209 Args: | |
| 210 opts: Program options containing cros_board and cros_remote_ip. | |
| 211 | |
| 212 Returns: | |
| 213 True if successful. | |
| 214 """ | |
| 215 try: | |
| 216 # Keys will most likely be set to 0640 after wiping the chroot. | |
| 217 os.chmod(bisect_utils.CROS_SCRIPT_KEY_PATH, 0600) | |
| 218 os.chmod(bisect_utils.CROS_TEST_KEY_PATH, 0600) | |
| 219 cmd = [bisect_utils.CROS_SDK_PATH, '--', './bin/cros_image_to_target.py', | |
| 220 '--remote=%s' % opts.cros_remote_ip, | |
| 221 '--board=%s' % opts.cros_board, '--test', '--verbose'] | |
| 222 | |
| 223 return_code = bisect_utils.RunProcess(cmd) | |
| 224 return not return_code | |
| 225 except OSError: | |
| 226 return False | |
| 227 | |
| 228 @staticmethod | |
| 229 def BuildPackages(opts, depot): | |
| 230 """Builds packages for cros. | |
| 231 | |
| 232 Args: | |
| 233 opts: Program options containing cros_board. | |
| 234 depot: The depot being bisected. | |
| 235 | |
| 236 Returns: | |
| 237 True if successful. | |
| 238 """ | |
| 239 cmd = [bisect_utils.CROS_SDK_PATH] | |
| 240 | |
| 241 if depot != 'cros': | |
| 242 path_to_chrome = os.path.join(os.getcwd(), '..') | |
| 243 cmd += ['--chrome_root=%s' % path_to_chrome] | |
| 244 | |
| 245 cmd += ['--'] | |
| 246 | |
| 247 if depot != 'cros': | |
| 248 cmd += ['CHROME_ORIGIN=LOCAL_SOURCE'] | |
| 249 | |
| 250 cmd += ['BUILDTYPE=%s' % opts.target_build_type, './build_packages', | |
| 251 '--board=%s' % opts.cros_board] | |
| 252 return_code = bisect_utils.RunProcess(cmd) | |
| 253 | |
| 254 return not return_code | |
| 255 | |
| 256 @staticmethod | |
| 257 def BuildImage(opts, depot): | |
| 258 """Builds test image for cros. | |
| 259 | |
| 260 Args: | |
| 261 opts: Program options containing cros_board. | |
| 262 depot: The depot being bisected. | |
| 263 | |
| 264 Returns: | |
| 265 True if successful. | |
| 266 """ | |
| 267 cmd = [bisect_utils.CROS_SDK_PATH] | |
| 268 | |
| 269 if depot != 'cros': | |
| 270 path_to_chrome = os.path.join(os.getcwd(), '..') | |
| 271 cmd += ['--chrome_root=%s' % path_to_chrome] | |
| 272 | |
| 273 cmd += ['--'] | |
| 274 | |
| 275 if depot != 'cros': | |
| 276 cmd += ['CHROME_ORIGIN=LOCAL_SOURCE'] | |
| 277 | |
| 278 cmd += ['BUILDTYPE=%s' % opts.target_build_type, '--', './build_image', | |
| 279 '--board=%s' % opts.cros_board, 'test'] | |
| 280 | |
| 281 return_code = bisect_utils.RunProcess(cmd) | |
| 282 | |
| 283 return not return_code | |
| 284 | |
| 285 def Build(self, depot, opts): | |
| 286 """Builds targets using options passed into the script. | |
| 287 | |
| 288 Args: | |
| 289 depot: Current depot being bisected. | |
| 290 opts: The options parsed from the command line. | |
| 291 | |
| 292 Returns: | |
| 293 True if build was successful. | |
| 294 """ | |
| 295 if self.BuildPackages(opts, depot): | |
| 296 if self.BuildImage(opts, depot): | |
| 297 return self.ImageToTarget(opts) | |
| 298 return False | |
| 299 | |
| 300 | |
| 301 def SetBuildSystemDefault(build_system, use_goma, goma_dir): | 194 def SetBuildSystemDefault(build_system, use_goma, goma_dir): |
| 302 """Sets up any environment variables needed to build with the specified build | 195 """Sets up any environment variables needed to build with the specified build |
| 303 system. | 196 system. |
| 304 | 197 |
| 305 Args: | 198 Args: |
| 306 build_system: A string specifying build system. Currently only 'ninja' or | 199 build_system: A string specifying build system. Currently only 'ninja' or |
| 307 'make' are supported. | 200 'make' are supported. |
| 308 """ | 201 """ |
| 309 if build_system == 'ninja': | 202 if build_system == 'ninja': |
| 310 gyp_var = os.getenv('GYP_GENERATORS', default='') | 203 gyp_var = os.getenv('GYP_GENERATORS', default='') |
| (...skipping 26 matching lines...) Expand all Loading... |
| 337 | 230 |
| 338 Args: | 231 Args: |
| 339 opts: The options parsed from the command line through parse_args(). | 232 opts: The options parsed from the command line through parse_args(). |
| 340 | 233 |
| 341 Returns: | 234 Returns: |
| 342 True if successful. | 235 True if successful. |
| 343 """ | 236 """ |
| 344 if 'android' in opts.target_platform: | 237 if 'android' in opts.target_platform: |
| 345 CopyAndSaveOriginalEnvironmentVars() | 238 CopyAndSaveOriginalEnvironmentVars() |
| 346 return SetupAndroidBuildEnvironment(opts) | 239 return SetupAndroidBuildEnvironment(opts) |
| 347 elif opts.target_platform == 'cros': | |
| 348 return bisect_utils.SetupCrosRepo() | |
| 349 return True | 240 return True |
| 350 | 241 |
| 351 | 242 |
| 352 def BuildWithMake(threads, targets, build_type='Release'): | 243 def BuildWithMake(threads, targets, build_type='Release'): |
| 353 """Runs a make command with the given targets. | 244 """Runs a make command with the given targets. |
| 354 | 245 |
| 355 Args: | 246 Args: |
| 356 threads: The number of threads to use. None means unspecified/unlimited. | 247 threads: The number of threads to use. None means unspecified/unlimited. |
| 357 targets: List of make targets. | 248 targets: List of make targets. |
| 358 build_type: Release or Debug. | 249 build_type: Release or Debug. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 def CopyAndSaveOriginalEnvironmentVars(): | 284 def CopyAndSaveOriginalEnvironmentVars(): |
| 394 """Makes a copy of the current environment variables. | 285 """Makes a copy of the current environment variables. |
| 395 | 286 |
| 396 Before making a copy of the environment variables and setting a global | 287 Before making a copy of the environment variables and setting a global |
| 397 variable, this function unsets a certain set of environment variables. | 288 variable, this function unsets a certain set of environment variables. |
| 398 """ | 289 """ |
| 399 # TODO: Waiting on crbug.com/255689, will remove this after. | 290 # TODO: Waiting on crbug.com/255689, will remove this after. |
| 400 vars_to_remove = [ | 291 vars_to_remove = [ |
| 401 'CHROME_SRC', | 292 'CHROME_SRC', |
| 402 'CHROMIUM_GYP_FILE', | 293 'CHROMIUM_GYP_FILE', |
| 403 'GYP_CROSSCOMPILE', | |
| 404 'GYP_DEFINES', | 294 'GYP_DEFINES', |
| 405 'GYP_GENERATORS', | 295 'GYP_GENERATORS', |
| 406 'GYP_GENERATOR_FLAGS', | 296 'GYP_GENERATOR_FLAGS', |
| 407 'OBJCOPY', | 297 'OBJCOPY', |
| 408 ] | 298 ] |
| 409 for key in os.environ: | 299 for key in os.environ: |
| 410 if 'ANDROID' in key: | 300 if 'ANDROID' in key: |
| 411 vars_to_remove.append(key) | 301 vars_to_remove.append(key) |
| 412 for key in vars_to_remove: | 302 for key in vars_to_remove: |
| 413 if os.environ.has_key(key): | 303 if os.environ.has_key(key): |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 # (See http://crrev.com/170273005). So, we set this variable explicitly here | 340 # (See http://crrev.com/170273005). So, we set this variable explicitly here |
| 451 # in order to build Chrome on Android. | 341 # in order to build Chrome on Android. |
| 452 if 'GYP_DEFINES' not in os.environ: | 342 if 'GYP_DEFINES' not in os.environ: |
| 453 os.environ['GYP_DEFINES'] = 'OS=android' | 343 os.environ['GYP_DEFINES'] = 'OS=android' |
| 454 else: | 344 else: |
| 455 os.environ['GYP_DEFINES'] += ' OS=android' | 345 os.environ['GYP_DEFINES'] += ' OS=android' |
| 456 | 346 |
| 457 if opts.use_goma: | 347 if opts.use_goma: |
| 458 os.environ['GYP_DEFINES'] += ' use_goma=1' | 348 os.environ['GYP_DEFINES'] += ' use_goma=1' |
| 459 return not proc.returncode | 349 return not proc.returncode |
| OLD | NEW |