def CreateFromManifest(self, manifest, retries=manifest_version.NUM_RETRIES, build_id=None): """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. build_id: Optional integer cidb build id of the build publishing the manifest. Returns: Path to the manifest version file to use. 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 = manifest_version.FilterManifest( manifest, whitelisted_remotes=config_lib.GetSiteParams().EXTERNAL_REMOTES) 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] logging.info('Publishing filtered build spec') self.PublishManifest(new_manifest, version, build_id=build_id) 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 raise manifest_version.GenerateBuildSpecException(last_error)
def CreateNewCandidate(self, validation_pool=None, android_version=None, chrome_version=None, retries=manifest_version.NUM_RETRIES, build_id=None): """Creates, syncs to, and returns the next candidate manifest. Args: validation_pool: Validation pool to apply to the manifest before publishing. android_version: The Android version to write in the manifest. Defaults to None, in which case no version is written. chrome_version: The Chrome version to write in the manifest. Defaults to None, in which case no version is written. retries: Number of retries for updating the status. Defaults to manifest_version.NUM_RETRIES. build_id: Optional integer cidb id of the build that is creating this candidate. 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() # Throw away CLs that might not be used this run. if validation_pool: validation_pool.FilterChangesForThrottledTree() # Apply any manifest CLs (internal or exteral). validation_pool.ApplyPoolIntoRepo( filter_fn=trybot_patch_pool.ManifestFilter) manifest_dir = os.path.join(validation_pool.build_root, 'manifest-internal') if not os.path.exists(manifest_dir): # Fall back to external manifest directory. manifest_dir = os.path.join(validation_pool.build_root, 'manifest') # This is only needed if there were internal manifest changes, but we # always run it to make sure this logic works. self._AdjustRepoCheckoutToLocalManifest(manifest_dir) new_manifest = self.CreateManifest() # For Android PFQ, add the version of Android to use. if android_version: self._AddAndroidVersionToManifest(new_manifest, android_version) # For Chrome PFQ, add the version of Chrome to use. if chrome_version: self._AddChromeVersionToManifest(new_manifest, chrome_version) # 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 config_lib.IsPFQType(self.build_type)): return None self._AddPatchesToManifest(new_manifest, validation_pool.applied) # Add info about the last known good version to the manifest. This will # be used by slaves to calculate what artifacts from old builds are safe # to use. self._AddLKGMToManifest(new_manifest) 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.applied) 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, build_id=build_id) 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 raise manifest_version.GenerateBuildSpecException(last_error)
def CreateNewCandidate(self, android_version=None, chrome_version=None, retries=manifest_version.NUM_RETRIES, build_id=None): """Creates, syncs to, and returns the next candidate manifest. Args: android_version: The Android version to write in the manifest. Defaults to None, in which case no version is written. chrome_version: The Chrome version to write in the manifest. Defaults to None, in which case no version is written. retries: Number of retries for updating the status. Defaults to manifest_version.NUM_RETRIES. build_id: Optional integer cidb id of the build that is creating this candidate. 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) new_manifest = self.CreateManifest() # For Android PFQ, add the version of Android to use. if android_version: self._AddAndroidVersionToManifest(new_manifest, android_version) # For Chrome PFQ, add the version of Chrome to use. if chrome_version: self._AddChromeVersionToManifest(new_manifest, chrome_version) 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 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, build_id=build_id) 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 raise manifest_version.GenerateBuildSpecException(last_error)