Exemple #1
0
def main(argv):
    cros_build_lib.AssertInsideChroot()
    opts = _ParseArguments(argv)

    site_config = config_lib.GetConfig()

    logging.info('Generating board configs. This takes about 2m...')
    for key in sorted(binhost.GetChromePrebuiltConfigs(site_config)):
        binhost.GenConfigsForBoard(key.board,
                                   regen=opts.regen,
                                   error_code_ok=True)

    # Fetch all compat IDs.
    fetcher = binhost.CompatIdFetcher()
    keys = binhost.GetChromePrebuiltConfigs(site_config).keys()
    compat_ids = fetcher.FetchCompatIds(keys)

    # Save the PFQ configs.
    pfq_configs = binhost.PrebuiltMapping.Get(keys, compat_ids)
    filename_internal = binhost.PrebuiltMapping.GetFilename(
        opts.buildroot, 'chrome')
    pfq_configs.Dump(filename_internal)
    git.AddPath(filename_internal)
    git.Commit(os.path.dirname(filename_internal),
               'Update PFQ config dump',
               allow_empty=True)

    filename_external = binhost.PrebuiltMapping.GetFilename(opts.buildroot,
                                                            'chromium',
                                                            internal=False)
    pfq_configs.Dump(filename_external, internal=False)
    git.AddPath(filename_external)
    git.Commit(os.path.dirname(filename_external),
               'Update PFQ config dump',
               allow_empty=True)
 def testCommit(self):
     self.rc.AddCmdResult(partial_mock.In('log'), output=self.COMMIT_LOG)
     git.Commit(self.fake_git_dir, 'bar')
     self.assertCommandContains(['--amend'], expected=False)
     cid = git.Commit(self.fake_git_dir, 'bar', amend=True)
     self.assertCommandContains(['--amend'])
     self.assertCommandContains(['--allow-empty'], expected=False)
     self.assertEqual(cid, self.CHANGE_ID)
     cid = git.Commit(self.fake_git_dir, 'new', allow_empty=True)
     self.assertCommandContains(['--allow-empty'])
Exemple #3
0
def PrepManifestForRepo(git_repo, manifest):
    """Use this to store a local manifest in a git repo suitable for repo.

  The repo tool can only fetch manifests from git repositories. So, to use
  a local manifest file as the basis for a checkout, it must be checked into
  a local git repository.

  Common Usage:
    manifest = CreateOrFetchWondrousManifest()
    with osutils.TempDir() as manifest_git_dir:
      PrepManifestForRepo(manifest_git_dir, manifest)
      repo = RepoRepository(manifest_git_dir, repo_dir)
      repo.Sync()

  Args:
    git_repo: Path at which to create the git repository (directory created, if
              needed). If a tempdir, then cleanup is owned by the caller.
    manifest: Path to existing manifest file to copy into the new git
              repository.
  """
    if not git.IsGitRepo(git_repo):
        git.Init(git_repo)

    new_manifest = os.path.join(git_repo, constants.DEFAULT_MANIFEST)

    shutil.copyfile(manifest, new_manifest)
    git.AddPath(new_manifest)
    message = 'Local repository holding: %s' % manifest

    # Commit new manifest. allow_empty in case it's the same as last manifest.
    git.Commit(git_repo, message, allow_empty=True)
    def setUp(self):
        self.manifest_dir = os.path.join(self.tempdir, '.repo', 'manifests')

        # Initialize a repo instance here.
        local_repo = os.path.join(constants.SOURCE_ROOT, '.repo/repo/.git')

        # TODO(evanhernandez): This is a hack. Find a way to simplify this test.
        # We used to use the current checkout's manifests.git, but that caused
        # problems in production environemnts.
        remote_manifests = os.path.join(self.tempdir, 'remote',
                                        'manifests.git')
        osutils.SafeMakedirs(remote_manifests)
        git.Init(remote_manifests)
        default_manifest = os.path.join(remote_manifests, 'default.xml')
        osutils.WriteFile(
            default_manifest,
            '<?xml version="1.0" encoding="UTF-8"?><manifest></manifest>')
        git.AddPath(default_manifest)
        git.Commit(remote_manifests, 'dummy commit', allow_empty=True)
        git.CreateBranch(remote_manifests, 'default')
        git.CreateBranch(remote_manifests, 'release-R23-2913.B')
        git.CreateBranch(remote_manifests, 'release-R23-2913.B-suffix')
        git.CreateBranch(remote_manifests, 'firmware-link-')

        # Create a copy of our existing manifests.git, but rewrite it so it
        # looks like a remote manifests.git.  This is to avoid hitting the
        # network, and speeds things up in general.
        local_manifests = 'file://%s' % remote_manifests
        temp_manifests = os.path.join(self.tempdir, 'manifests.git')
        git.RunGit(self.tempdir, ['clone', '-n', '--bare', local_manifests])
        git.RunGit(temp_manifests, [
            'fetch', '-f', '-u', local_manifests,
            'refs/remotes/origin/*:refs/heads/*'
        ])
        git.RunGit(temp_manifests, ['branch', '-D', 'default'])
        cros_build_lib.run([
            'repo',
            'init',
            '-u',
            temp_manifests,
            '--repo-branch',
            'default',
            '--repo-url',
            'file://%s' % local_repo,
        ],
                           cwd=self.tempdir)

        self.active_manifest = os.path.realpath(
            os.path.join(self.tempdir, '.repo', 'manifest.xml'))
Exemple #5
0
def UpdateBinhostConfFile(path, key, value):
  """Update binhost config file file with key=value.

  Args:
    path: Filename to update.
    key: Key to update.
    value: New value for key.
  """
  cwd, filename = os.path.split(os.path.abspath(path))
  osutils.SafeMakedirs(cwd)
  if not git.GetCurrentBranch(cwd):
    git.CreatePushBranch(constants.STABLE_EBUILD_BRANCH, cwd, sync=False)
  osutils.WriteFile(path, '', mode='a')
  if UpdateLocalFile(path, value, key):
    desc = '%s: %s %s' % (filename, 'updating' if value else 'clearing', key)
    git.AddPath(path)
    git.Commit(cwd, desc)
  def unpin(self, work_dir):
    """Unpin chrome."""

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

    mask_file = os.path.join(overlay, MASK_FILE)
    if not os.path.exists(mask_file):
      raise Exception('Mask file not found. Is Chrome pinned?')

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

    git.RmPath(mask_file)
    git.Commit(overlay, self.CommitMessage('Chrome: Unpin chrome'))
    git.UploadCL(overlay, OVERLAY_URL, self.options.branch,
                 skip=self.options.dryrun)
Exemple #7
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')
Exemple #8
0
    def UprevChrome(self, work_dir, pfq_build, build_number):
        """Uprev Chrome.

    Args:
      work_dir: directory to clone repository and update uprev.
      pfq_build: pfq build_id to uprev chrome.
      build_number: corresponding build number showed on waterfall.

    Raises:
      Exception when no commit ID is found in the public overlay CL.
      Exception when no commit ID is found in the private overlay CL.
    """
        # Verify the format of reviewers
        reviewers = self.options.reviewers
        self.ValidateReviewers(reviewers)

        pub_overlay = os.path.join(work_dir, 'pub_overlay')
        priv_overlay = os.path.join(work_dir, 'priv_overlay')

        print('Setting up working directory...')
        # TODO(nxia): move cros_pinchrome.CloneWorkingRepo to a util class?
        cros_pinchrome.CloneWorkingRepo(pub_overlay, PUB_OVERLAY_URL,
                                        PUB_OVERLAY, MASTER_BRANCH)
        cros_pinchrome.CloneWorkingRepo(priv_overlay, PRIV_OVERLAY_URL,
                                        PRIV_OVERLAY, MASTER_BRANCH)

        print('Preparing CLs...')
        remote = 'origin'
        branch_name = constants.STAGING_PFQ_BRANCH_PREFIX + pfq_build
        remote_ref = ('refs/' + constants.PFQ_REF + '/' + branch_name)
        local_branch = '%s_%s' % (branch_name,
                                  cros_build_lib.GetRandomString())

        logging.info('Checking remote refs.')
        self.CheckRemoteBranch(pub_overlay, remote, remote_ref)
        self.CheckRemoteBranch(priv_overlay, remote, remote_ref)

        # Fetch the remote refspec for the public overlay
        logging.info('git fetch %s %s:%s', remote, remote_ref, local_branch)
        git.RunGit(pub_overlay,
                   ['fetch', remote,
                    '%s:%s' % (remote_ref, local_branch)])

        logging.info('git checkout %s', local_branch)
        git.RunGit(pub_overlay, ['checkout', local_branch])

        pub_commit_body = self.ParseGitLog(pub_overlay)
        commit_message = self.CommitMessage(pub_commit_body, pfq_build,
                                            build_number)

        # Update the commit message and reset author.
        pub_cid = git.Commit(pub_overlay,
                             commit_message,
                             amend=True,
                             reset_author=True)
        if not pub_cid:
            raise Exception(
                "Don't know the commit ID of the public overlay CL.")

        # Fetch the remote refspec for the private overlay.
        logging.info('git fetch %s %s:%s', remote, remote_ref, local_branch)
        git.RunGit(priv_overlay,
                   ['fetch', remote,
                    '%s:%s' % (remote_ref, local_branch)])

        git.RunGit(priv_overlay, ['checkout', local_branch])
        logging.info('git checkout %s', local_branch)

        priv_commit_body = self.ParseGitLog(priv_overlay)
        # Add CQ-DEPEND
        commit_message = self.CommitMessage(priv_commit_body, pfq_build,
                                            build_number, pub_cid)

        # Update the commit message and reset author
        priv_cid = git.Commit(priv_overlay,
                              commit_message,
                              amend=True,
                              reset_author=True)
        if not priv_cid:
            raise Exception(
                "Don't know the commit ID of the private overlay CL.")

        # Add CQ-DEPEND
        commit_message = self.CommitMessage(pub_commit_body, pfq_build,
                                            build_number, '*' + priv_cid,
                                            pub_cid)

        git.Commit(pub_overlay, commit_message, amend=True)

        overlays = [(pub_overlay, PUB_OVERLAY_URL),
                    (priv_overlay, PRIV_OVERLAY_URL)]

        for (_overlay, _overlay_url) in overlays:
            logging.info('git pull --rebase %s %s', remote, MASTER_BRANCH)
            git.RunGit(_overlay, ['pull', '--rebase', remote, MASTER_BRANCH])

            logging.info('Upload CLs to Gerrit.')
            git.UploadCL(_overlay,
                         _overlay_url,
                         MASTER_BRANCH,
                         skip=self.options.dry_run,
                         draft=self.options.draft,
                         debug_level=logging.NOTICE,
                         reviewers=reviewers)

        print('Please review and submit the CLs together from Gerrit.')
        print('Successfully run cros uprevchrome!')