Ejemplo n.º 1
0
def RevertBinhostConf(overlay, conf_files, rev):
  """Revert binhost config files back to a particular revision.

  Args:
    overlay: The overlay holding the binhost config files.
    conf_files: A list of config file names.
    rev: The revision to revert back to.
  """
  binhost_dir = os.path.join(overlay, 'chromeos', 'binhost')
  for conf_file in conf_files:
    try:
      git.RevertPath(os.path.join(binhost_dir, 'target'), conf_file, rev)
    except Exception as e1:
      try:
        git.RevertPath(os.path.join(binhost_dir, 'host'), conf_file, rev)
      except Exception as e2:
        raise Exception(str(e1) + '\n' + str(e2))
Ejemplo n.º 2
0
def RevertStableEBuild(dirname, rev):
    """Revert the stable ebuilds for a package back to a particular revision.

  Also add/remove the files in git.

  Args:
    dirname: Path to the ebuild directory.
    rev: Revision to revert back to.

  Returns:
    The name of the ebuild reverted to.
  """
    package = os.path.basename(dirname.rstrip(os.sep))
    pattern = '%s-*.ebuild' % package

    # Get rid of existing stable ebuilds.
    ebuilds = glob.glob(os.path.join(dirname, pattern))
    for ebuild in ebuilds:
        parts = SplitPVPath(ebuild)
        if parts.version != '9999':
            git.RmPath(ebuild)

    # Bring back the old stable ebuild.
    names = git.GetObjectAtRev(dirname, './', rev).split()
    names = fnmatch.filter(names, pattern)
    names = [
        name for name in names
        if SplitPVPath(os.path.join(dirname, name)).version != '9999'
    ]
    if not names:
        return None
    assert len(names) == 1
    name = names[0]
    git.RevertPath(dirname, name, rev)

    # Update the manifest.
    UpdateManifest(os.path.join(dirname, name))
    manifest_path = os.path.join(dirname, 'Manifest')
    if os.path.exists(manifest_path):
        git.AddPath(manifest_path)
    return os.path.join(dirname, name)
Ejemplo n.º 3
0
    def pin(self, work_dir):
        """Pin chrome."""

        overlay = os.path.join(work_dir, 'overlay')
        priv_overlay = os.path.join(work_dir, 'priv_overlay')
        print('Setting up working directory...')
        CloneWorkingRepo(overlay, OVERLAY_URL, OVERLAY, self.options.branch)
        CloneWorkingRepo(priv_overlay, PRIV_OVERLAY_URL, PRIV_OVERLAY,
                         self.options.branch)
        print('Done')

        # Interesting paths.
        chrome_dir = os.path.join(overlay, constants.CHROME_CP)
        other_dirs = [
            os.path.join(overlay, pkg)
            for pkg in constants.OTHER_CHROME_PACKAGES
        ]

        # Let the user pick what version to pin chrome to.
        uprev_list = UprevList(chrome_dir)
        choice = cros_build_lib.GetChoice('Versions of chrome to pin to:',
                                          uprev_list,
                                          group_size=5)
        pin_version = uprev_list.uprevs[choice]
        commit_subject = ('Chrome: Pin to version %s' %
                          pin_version.from_parts.version)

        # Public branch.
        git.CreateBranch(overlay,
                         self.branch_name,
                         track=True,
                         branch_point='origin/%s' % self.options.branch)

        target_sha = pin_version.sha + '~'
        ebs = [RevertStableEBuild(chrome_dir, target_sha)]
        for pkg_dir in other_dirs:
            ebs.append(RevertStableEBuild(pkg_dir, target_sha))
        RevertBinhostConf(overlay, pin_version.conf_files, target_sha)
        git.RevertPath(os.path.join(overlay, 'chromeos', 'binhost'),
                       'chromium.json', target_sha)
        MaskNewerPackages(overlay, (eb for eb in ebs if eb))

        pub_cid = git.Commit(overlay, 'Public overlay commit')
        if not pub_cid:
            raise Exception(
                "Don't know the commit ID of the public overlay CL.")

        # Find out what package directory the binhost configs should point to.
        binhost_dir = os.path.join(overlay, 'chromeos', 'binhost')
        target_file = os.path.join(binhost_dir, 'target',
                                   pin_version.conf_files[0])
        host_file = os.path.join(binhost_dir, 'host',
                                 pin_version.conf_files[0])
        conf_file = target_file if os.path.exists(target_file) else host_file
        conf_content = osutils.ReadFile(conf_file)
        match = re.search('/(?P<package_dir>[^/\n]*)/packages', conf_content)
        if not match:
            raise Exception('Failed to parse binhost conf %s' %
                            conf_content.strip())
        pkg_dir = match.group('package_dir')

        # Private branch.
        git.CreateBranch(priv_overlay,
                         self.branch_name,
                         track=True,
                         branch_point='origin/%s' % self.options.branch)

        binhost_uprev = FindPrivateConfCL(priv_overlay, pkg_dir)
        if not binhost_uprev:
            raise Exception('Failed to find private binhost uprev.')
        target_sha = binhost_uprev.sha
        RevertBinhostConf(priv_overlay, binhost_uprev.conf_files, target_sha)
        git.RevertPath(os.path.join(priv_overlay, 'chromeos', 'binhost'),
                       'chrome.json', target_sha)

        commit_message = self.CommitMessage(commit_subject, pub_cid)
        priv_cid = git.Commit(priv_overlay, commit_message)
        if not priv_cid:
            raise Exception(
                "Don't know the commit ID of the private overlay CL.")

        # Update the commit message on the public overlay CL.
        commit_message = self.CommitMessage(commit_subject, '*' + priv_cid,
                                            pub_cid)
        git.Commit(overlay, commit_message, amend=True)

        # Upload the CLs.
        external_push = git.UploadCL(overlay,
                                     OVERLAY_URL,
                                     self.options.branch,
                                     skip=self.options.dryrun)
        print(external_push.output)
        internal_push = git.UploadCL(priv_overlay,
                                     PRIV_OVERLAY_URL,
                                     self.options.branch,
                                     skip=self.options.dryrun)
        print(internal_push.output)

        print('\n** Both of the changes above need to be submitted for chrome '
              'to be pinned. **\n')
Ejemplo n.º 4
0
 def testRevertPath(self):
     git.RevertPath(self.fake_git_dir, self.fake_file, '1234')
     self.assertCommandContains(['checkout'])
     self.assertCommandContains([self.fake_file])