def PerformStage(self): chroot_path = os.path.join(self._build_root, constants.DEFAULT_CHROOT_DIR) chroot_exists = os.path.isdir(self._build_root) replace = self._run.config.chroot_replace or self.force_chroot_replace pre_ver = None if chroot_exists and not replace: # Make sure the chroot has a valid version before we update it. pre_ver = cros_sdk_lib.GetChrootVersion(chroot_path) if pre_ver is None: logging.PrintBuildbotStepText('Replacing broken chroot') logging.PrintBuildbotStepWarnings() replace = True if not chroot_exists or replace: use_sdk = (self._run.config.use_sdk and not self._run.options.nosdk) pre_ver = None commands.MakeChroot(buildroot=self._build_root, replace=replace, use_sdk=use_sdk, chrome_root=self._run.options.chrome_root, extra_env=self._portage_extra_env, use_image=self._run.config.chroot_use_image, cache_dir=self._run.options.cache_dir) post_ver = cros_sdk_lib.GetChrootVersion(chroot_path) if pre_ver is not None and pre_ver != post_ver: logging.PrintBuildbotStepText('%s->%s' % (pre_ver, post_ver)) else: logging.PrintBuildbotStepText(post_ver)
def testNoChroot(self): """Verify we don't blow up when there is no chroot yet.""" self.PatchObject(cros_sdk_lib.ChrootUpdater, 'GetVersion', side_effect=IOError()) self.assertIsNone( cros_sdk_lib.GetChrootVersion('/.$om3/place/nowhere'))
def testSimpleBuildroot(self): """Verify buildroot arg works""" read_mock = self.PatchObject(osutils, 'ReadFile', return_value='12\n') ret = cros_sdk_lib.GetChrootVersion(buildroot='/build/root') self.assertEqual(ret, '12') read_mock.assert_called_with( '/build/root/chroot/etc/cros_chroot_version')
def PerformStage(self): chroot_path = os.path.join(self._build_root, constants.DEFAULT_CHROOT_DIR) # Worksapce chroots are always wiped by cleanup stage, no need to update. cmd = ['cros_sdk', '--create'] + ChrootArgs(self._run.options) commands.RunBuildScript(self._build_root, cmd, chromite_cmd=True, extra_env=self._portage_extra_env) post_ver = cros_sdk_lib.GetChrootVersion(chroot_path) logging.PrintBuildbotStepText(post_ver)
def PerformStage(self): # This prepares depot_tools in the source tree, in advance. self.DepotToolsEnsureBootstrap() chroot_path = os.path.join(self._build_root, constants.DEFAULT_CHROOT_DIR) replace = self._run.config.chroot_replace or self.force_chroot_replace pre_ver = post_ver = None if os.path.isdir(self._build_root) and not replace: try: pre_ver = cros_sdk_lib.GetChrootVersion(chroot=chroot_path) if pre_ver is not None: commands.RunChrootUpgradeHooks( self._build_root, chrome_root=self._run.options.chrome_root, extra_env=self._portage_extra_env) except failures_lib.BuildScriptFailure: logging.PrintBuildbotStepText('Replacing broken chroot') logging.PrintBuildbotStepWarnings() if not os.path.isdir(chroot_path) or replace: use_sdk = (self._run.config.use_sdk and not self._run.options.nosdk) pre_ver = None commands.MakeChroot(buildroot=self._build_root, replace=replace, use_sdk=use_sdk, chrome_root=self._run.options.chrome_root, extra_env=self._portage_extra_env, use_image=self._run.config.chroot_use_image) post_ver = cros_sdk_lib.GetChrootVersion(chroot=chroot_path) if pre_ver is not None and pre_ver != post_ver: logging.PrintBuildbotStepText('%s->%s' % (pre_ver, post_ver)) else: logging.PrintBuildbotStepText(post_ver) commands.SetSharedUserPassword( self._build_root, password=self._run.config.shared_user_password)
def GetChrootVersion(chroot_path=None): """Get the chroot version. Args: chroot_path (str|None): The chroot path. Returns: int|None - The version of the chroot if the chroot is valid, else None. """ if chroot_path: path = chroot_path elif cros_build_lib.IsInsideChroot(): path = None else: path = constants.DEFAULT_CHROOT_PATH return cros_sdk_lib.GetChrootVersion(path)
def testNoChroot(self): """Verify we don't blow up when there is no chroot yet""" ret = cros_sdk_lib.GetChrootVersion(chroot='/.$om3/place/nowhere') self.assertEqual(ret, None)