def CreateFromManifest(self, manifest, retries=manifest_version.NUM_RETRIES): """Sets up an lkgm_manager from the given manifest. This method sets up an LKGM manager and publishes a new manifest to the manifest versions repo based on the passed in manifest but filtering internal repositories and changes out of it. Args: manifest: A manifest that possibly contains private changes/projects. It is named with the given version we want to create a new manifest from i.e R20-1920.0.1-rc7.xml where R20-1920.0.1-rc7 is the version. retries: Number of retries for updating the status. Raises: GenerateBuildSpecException in case of failure to check-in the new manifest because of a git error or the manifest is already checked-in. """ last_error = None new_manifest = self._FilterCrosInternalProjectsFromManifest(manifest) version_info = self.GetCurrentVersionInfo() for _attempt in range(0, retries + 1): try: self.RefreshManifestCheckout() self.InitializeManifestVariables(version_info) git.CreatePushBranch(manifest_version.PUSH_BRANCH, self.manifest_dir, sync=False) version = os.path.splitext(os.path.basename(manifest))[0] self.PublishManifest(new_manifest, version) self.SetInFlight(version) self.current_version = version return self.GetLocalManifest(version) except cros_build_lib.RunCommandError as e: err_msg = 'Failed to generate LKGM Candidate. error: %s' % e logging.error(err_msg) last_error = err_msg else: raise manifest_version.GenerateBuildSpecException(last_error)
def CreateNewCandidate(self, validation_pool=None, retries=manifest_version.NUM_RETRIES): """Creates, syncs to, and returns the next candidate manifest. Args: validation_pool: Validation pool to apply to the manifest before publishing. retries: Number of retries for updating the status. Raises: GenerateBuildSpecException in case of failure to generate a buildspec """ self.CheckoutSourceCode() # Refresh manifest logic from manifest_versions repository to grab the # LKGM to generate the blamelist. version_info = self.GetCurrentVersionInfo() self.RefreshManifestCheckout() self.InitializeManifestVariables(version_info) self._GenerateBlameListSinceLKGM() new_manifest = self.CreateManifest() # For the Commit Queue, apply the validation pool as part of checkout. if validation_pool: # If we have nothing that could apply from the validation pool and # we're not also a pfq type, we got nothing to do. assert self.cros_source.directory == validation_pool.build_root if (not validation_pool.ApplyPoolIntoRepo() and not cbuildbot_config.IsPFQType(self.build_type)): return None self._AddPatchesToManifest(new_manifest, validation_pool.changes) last_error = None for attempt in range(0, retries + 1): try: # Refresh manifest logic from manifest_versions repository. # Note we don't need to do this on our first attempt as we needed to # have done it to get the LKGM. if attempt != 0: self.RefreshManifestCheckout() self.InitializeManifestVariables(version_info) # If we don't have any valid changes to test, make sure the checkout # is at least different. if ((not validation_pool or not validation_pool.changes) and not self.force and self.HasCheckoutBeenBuilt()): return None # Check whether the latest spec available in manifest-versions is # newer than our current version number. If so, use it as the base # version number. Otherwise, we default to 'rc1'. if self.latest: latest = max(self.latest, version_info.VersionString(), key=self.compare_versions_fn) version_info = _LKGMCandidateInfo( latest, chrome_branch=version_info.chrome_branch, incr_type=self.incr_type) git.CreatePushBranch(manifest_version.PUSH_BRANCH, self.manifest_dir, sync=False) version = self.GetNextVersion(version_info) self.PublishManifest(new_manifest, version) self.current_version = version return self.GetLocalManifest(version) except cros_build_lib.RunCommandError as e: err_msg = 'Failed to generate LKGM Candidate. error: %s' % e logging.error(err_msg) last_error = err_msg else: raise manifest_version.GenerateBuildSpecException(last_error)