def UpdateDefaultVersion(self): """Update the version that we default to using. Returns: A tuple of the form (version, updated), where |version| is the version number in the format '3929.0.0', and |updated| indicates whether the version was indeed updated. """ checkout = commandline.DetermineCheckout(os.getcwd()) current = self.GetDefaultVersion() or '0' if checkout.chrome_src_dir: target = self._GetChromeLKGM(checkout.chrome_src_dir) elif checkout.type == commandline.CHECKOUT_TYPE_REPO: target = self._GetRepoCheckoutVersion(checkout.root) if target != current: lv_cls = distutils.version.LooseVersion if lv_cls(target) > lv_cls(current): # Hit the network for the newest uploaded version for the branch. newest = self._GetNewestManifestVersion() # The SDK for the version of the checkout has not been uploaded yet, # so fall back to the latest uploaded SDK. if lv_cls(target) > lv_cls(newest): target = newest else: target = self._GetNewestManifestVersion() self._SetDefaultVersion(target) return target, target != current
def RunTest(self, dir_struct, cwd, expected_root, expected_type, expected_src): """Run a test with specific parameters and expected results.""" cros_test_lib.CreateOnDiskHierarchy(self.tempdir, dir_struct) cwd = os.path.join(self.tempdir, cwd) checkout_info = commandline.DetermineCheckout(cwd) full_root = expected_root if expected_root is not None: full_root = os.path.join(self.tempdir, expected_root) full_src = expected_src if expected_src is not None: full_src = os.path.join(self.tempdir, expected_src) self.assertEquals(checkout_info.root, full_root) self.assertEquals(checkout_info.type, expected_type) self.assertEquals(checkout_info.chrome_src_dir, full_src)
def Run(self): """Perform the command.""" if os.environ.get(SDKFetcher.SDK_VERSION_ENV) is not None: cros_build_lib.Die('Already in an SDK shell.') if self.options.clang and not self.options.make: cros_build_lib.Die('--clang requires --make to be set.') if not self.options.chrome_src: checkout = commandline.DetermineCheckout(os.getcwd()) self.options.chrome_src = checkout.chrome_src_dir else: checkout = commandline.DetermineCheckout(self.options.chrome_src) if not checkout.chrome_src_dir: cros_build_lib.Die('Chrome checkout not found at %s', self.options.chrome_src) self.options.chrome_src = checkout.chrome_src_dir if self.options.clang and not self.options.chrome_src: cros_build_lib.Die('--clang requires --chrome-src to be set.') self.silent = bool(self.options.cmd) # Lazy initialize because SDKFetcher creates a GSContext() object in its # constructor, which may block on user input. self.sdk = SDKFetcher(self.options.cache_dir, self.options.board, silent=self.silent) if not self.sdk.config['internal']: cros_build_lib.Die('External boards are not supported due to ' 'http://crbug.com/236500') prepare_version = self.options.version if not prepare_version: prepare_version, _ = self.sdk.UpdateDefaultVersion() components = [self.sdk.TARGET_TOOLCHAIN_KEY, constants.CHROME_ENV_TAR] if not self.options.chroot: components.append(constants.CHROME_SYSROOT_TAR) goma_dir = None goma_port = None if self.options.goma: try: goma_dir, goma_port = self._FetchGoma() except GomaError as e: logging.error('Goma: %s. Bypass by running with --nogoma.', e) if self.options.clang: self._SetupClang() with self.sdk.Prepare(components, version=prepare_version) as ctx: env = self._SetupEnvironment(self.options.board, ctx, self.options, goma_dir=goma_dir, goma_port=goma_port) with self._GetRCFile(env, self.options.bashrc) as rcfile: bash_cmd = ['/bin/bash'] extra_env = None if not self.options.cmd: bash_cmd.extend(['--rcfile', rcfile, '-i']) else: # The '"$@"' expands out to the properly quoted positional args # coming after the '--'. bash_cmd.extend(['-c', '"$@"', '--']) bash_cmd.extend(self.options.cmd) # When run in noninteractive mode, bash sources the rc file set in # BASH_ENV, and ignores the --rcfile flag. extra_env = {'BASH_ENV': rcfile} cros_build_lib.RunCommand(bash_cmd, print_cmd=False, debug_level=logging.CRITICAL, error_code_ok=True, extra_env=extra_env)