def SyncSources(self): repo = repository.RepoRepository(self.manifest_dir, self.repo_root, referenced_repo=self.reference, manifest=MANIFEST_FILE, branch='master') # Trigger the network sync repo.Sync(jobs=multiprocessing.cpu_count() + 1, network_only=True) projects = [self.CHROMIUM_ROOT] if self.internal: projects.append(self.CHROME_ROOT) for project in projects: path = os.path.join(self.repo_root, project) if os.path.exists(path): try: git.CleanAndCheckoutUpstream(path, refresh_upstream=False) continue except cros_build_lib.RunCommandError: cros_build_lib.Error("Failed cleaning %r; wiping.", path) cros_build_lib.SudoRunCommand(['rm', '-rf', path], print_cmd=False) cros_build_lib.RunCommand(['repo', 'sync', '-ld', project], cwd=self.repo_root)
def RefreshManifestCheckout(manifest_dir, manifest_repo): """Checks out manifest-versions into the manifest directory. If a repository is already present, it will be cleansed of any local changes and restored to its pristine state, checking out the origin. """ reinitialize = True if os.path.exists(manifest_dir): result = cros_build_lib.RunCommand( ['git', 'config', 'remote.origin.url'], cwd=manifest_dir, print_cmd=False, redirect_stdout=True, error_code_ok=True) if (result.returncode == 0 and result.output.rstrip() == manifest_repo): logging.info('Updating manifest-versions checkout.') try: git.RunGit(manifest_dir, ['gc', '--auto']) git.CleanAndCheckoutUpstream(manifest_dir) except cros_build_lib.RunCommandError: logging.warning('Could not update manifest-versions checkout.') else: reinitialize = False else: logging.info('No manifest-versions checkout exists at %s', manifest_dir) if reinitialize: logging.info('Cloning fresh manifest-versions checkout.') _RemoveDirs(manifest_dir) repository.CloneGitRepo(manifest_dir, manifest_repo)
def RefreshManifestCheckout(manifest_dir, manifest_repo): """Checks out manifest-versions into the manifest directory. If a repository is already present, it will be cleansed of any local changes and restored to its pristine state, checking out the origin. """ logging.info('Refreshing %s from %s', manifest_dir, manifest_repo) reinitialize = True if os.path.exists(manifest_dir): result = git.RunGit(manifest_dir, ['config', 'remote.origin.url'], check=False) if (result.returncode == 0 and result.output.rstrip() == manifest_repo): logging.info('Updating manifest-versions checkout.') try: git.RunGit(manifest_dir, ['gc', '--auto']) git.CleanAndCheckoutUpstream(manifest_dir) except cros_build_lib.RunCommandError: logging.warning('Could not update manifest-versions checkout.') else: reinitialize = False else: logging.info('No manifest-versions checkout exists at %s', manifest_dir) if reinitialize: logging.info('Cloning fresh manifest-versions checkout.') osutils.RmDir(manifest_dir, ignore_missing=True) git.Clone(manifest_dir, manifest_repo)
def UpdateVersionFile(self, message, dry_run, push_to=None): """Update the version file with our current version. Args: message: Commit message. dry_run: Git dryrun. push_to: A git.RemoteRef object. """ if not self.version_file: raise VersionUpdateException( 'Cannot call UpdateVersionFile without ' 'an associated version_file') components = (('CHROMEOS_BUILD', self.build_number), ('CHROMEOS_BRANCH', self.branch_build_number), ('CHROMEOS_PATCH', self.patch_number), ('CHROME_BRANCH', self.chrome_branch)) with tempfile.NamedTemporaryFile(prefix='mvp', mode='w') as temp_fh: with open(self.version_file, 'r') as source_version_fh: for line in source_version_fh: for key, value in components: line = re.sub(self.KEY_VALUE_PATTERN % (key, ), '%s=%s\n' % (key, value), line) temp_fh.write(line) temp_fh.flush() repo_dir = os.path.dirname(self.version_file) logging.info('Updating version file to: %s', self.VersionString()) try: git.CreateBranch(repo_dir, PUSH_BRANCH) shutil.copyfile(temp_fh.name, self.version_file) _PushGitChanges(repo_dir, message, dry_run=dry_run, push_to=push_to) finally: # Update to the remote version that contains our changes. This is needed # to ensure that we don't build a release using a local commit. git.CleanAndCheckoutUpstream(repo_dir)
def UpdateGitRepo(working_dir, repo_url, **kwargs): """Update the given git repo, blowing away any local changes. If the repo does not exist, clone it from scratch. Args: working_dir: location where it should be cloned to repo_url: git repo to clone **kwargs: See CloneGitRepo. """ assert not kwargs.get('bare'), 'Bare checkouts are not supported' if git.IsGitRepo(working_dir): try: git.CleanAndCheckoutUpstream(working_dir) except cros_build_lib.RunCommandError: logging.warning('Could not update %s', working_dir, exc_info=True) shutil.rmtree(working_dir) CloneGitRepo(working_dir, repo_url, **kwargs) else: CloneGitRepo(working_dir, repo_url, **kwargs)
def CommonTestIncrementVersion(self, incr_type, version): """Common test increment. Returns path to new incremented file.""" message = 'Incrementing cuz I sed so' self.mox.StubOutWithMock(git, 'CreatePushBranch') self.mox.StubOutWithMock(manifest_version, '_PushGitChanges') self.mox.StubOutWithMock(git, 'CleanAndCheckoutUpstream') git.CreatePushBranch(manifest_version.PUSH_BRANCH, self.tempdir) version_file = self.CreateFakeVersionFile(self.tempdir, version) manifest_version._PushGitChanges(self.tempdir, message, dry_run=False) git.CleanAndCheckoutUpstream(self.tempdir) self.mox.ReplayAll() info = manifest_version.VersionInfo(version_file=version_file, incr_type=incr_type) info.IncrementVersion(message, dry_run=False) self.mox.VerifyAll() return version_file
def process_target(internal, manifest_url, reference): subdir = 'internal' if internal else 'external' root = os.path.join(options.testroot, subdir) repo_dir = os.path.join(root, 'repo') osutils.SafeMakedirs(repo_dir) manifest_dir = os.path.join(root, 'manifest') if os.path.exists(manifest_dir): git.CleanAndCheckoutUpstream(manifest_dir) git.RunGit(manifest_dir, ['checkout', '-B', 'master', '-t', 'origin/master']) else: repository.CloneGitRepo(manifest_dir, manifest_url) m = Manifest(repo_dir, manifest_dir, internal, reference=reference, dryrun=options.dryrun) m.PerformUpdate() if options.dryrun: print "%s manifest is now:" % subdir print osutils.ReadFile(os.path.join(manifest_dir, MANIFEST_FILE))
def SyncToHead(self, fetch_tags=False): """Syncs the repo to origin/master.""" git.CleanAndCheckoutUpstream(self.repo_dir) if fetch_tags: git.RunGit(self.repo_dir, ['fetch', '--tags'])
def IncrementVersion(self, message, dry_run): """Updates the version file by incrementing the patch component. Args: message: Commit message to use when incrementing the version. dry_run: Git dry_run. """ def IncrementOldValue(line, key, new_value): """Change key to new_value if found on line. Returns True if changed.""" old_value = self.FindValue(key, line) if old_value: temp_fh.write(line.replace(old_value, new_value, 1)) return True else: return False if not self.version_file: raise VersionUpdateException( 'Cannot call IncrementVersion without ' 'an associated version_file') if not self.incr_type or self.incr_type not in ('build', 'branch'): raise VersionUpdateException( 'Need to specify the part of the version to' ' increment') if self.incr_type == 'build': self.build_number = str(int(self.build_number) + 1) self.branch_build_number = '0' self.patch_number = '0' elif self.patch_number == '0': self.branch_build_number = str(int(self.branch_build_number) + 1) else: self.patch_number = str(int(self.patch_number) + 1) temp_file = tempfile.mkstemp(suffix='mvp', prefix='tmp', dir=None, text=True)[1] with open(self.version_file, 'r') as source_version_fh: with open(temp_file, 'w') as temp_fh: for line in source_version_fh: if IncrementOldValue(line, 'CHROMEOS_BUILD', self.build_number): pass elif IncrementOldValue(line, 'CHROMEOS_BRANCH', self.branch_build_number): pass elif IncrementOldValue(line, 'CHROMEOS_PATCH', self.patch_number): pass else: temp_fh.write(line) temp_fh.close() source_version_fh.close() repo_dir = os.path.dirname(self.version_file) try: git.CreatePushBranch(PUSH_BRANCH, repo_dir) shutil.copyfile(temp_file, self.version_file) os.unlink(temp_file) _PushGitChanges(repo_dir, message, dry_run=dry_run) finally: # Update to the remote version that contains our changes. This is needed # to ensure that we don't build a release using a local commit. git.CleanAndCheckoutUpstream(repo_dir) return self.VersionString()