def testManifestInheritance(self):
        osutils.WriteFile(
            self.active_manifest, """
        <manifest>
          <include name="include-target.xml" />
          <include name="empty.xml" />
          <project name="monkeys" path="baz" remote="foon" revision="master" />
        </manifest>""")
        # First, verify it properly explodes if the include can't be found.
        self.assertRaises(EnvironmentError, git.ManifestCheckout, self.tempdir)

        # Next, verify it can read an empty manifest; this is to ensure
        # that we can point Manifest at the empty manifest without exploding,
        # same for ManifestCheckout; this sort of thing is primarily useful
        # to ensure no step of an include assumes everything is yet assembled.
        empty_path = os.path.join(self.manifest_dir, 'empty.xml')
        osutils.WriteFile(empty_path, '<manifest/>')
        git.Manifest(empty_path)
        git.ManifestCheckout(self.tempdir, manifest_path=empty_path)

        # Next, verify include works.
        osutils.WriteFile(
            os.path.join(self.manifest_dir, 'include-target.xml'), """
        <manifest>
          <remote name="foon" fetch="http://localhost" />
        </manifest>""")
        manifest = git.ManifestCheckout(self.tempdir)
        self.assertEqual(list(manifest.checkouts_by_name), ['monkeys'])
        self.assertEqual(list(manifest.remotes), ['foon'])
Example #2
0
def GenerateBlameList(source_repo, lkgm_path, only_print_chumps=False):
  """Generate the blamelist since the specified manifest.

  Arguments:
    source_repo: Repository object for the source code.
    lkgm_path: Path to LKGM manifest.
    only_print_chumps: If True, only print changes that were chumped.
  """
  handler = git.Manifest(lkgm_path)
  reviewed_on_re = re.compile(r'\s*Reviewed-on:\s*(\S+)')
  author_re = re.compile(r'\s*Author:.*<(\S+)@\S+>\s*')
  committer_re = re.compile(r'\s*Commit:.*<(\S+)@\S+>\s*')
  for project in handler.projects.keys():
    rel_src_path = handler.projects[project].get('path')

    # If it's not part of our source tree, it doesn't affect our build.
    if not rel_src_path:
      continue

    # Additional case in case the repo has been removed from the manifest.
    src_path = source_repo.GetRelativePath(rel_src_path)
    if not os.path.exists(src_path):
      cros_build_lib.Info('Detected repo removed from manifest %s' % project)
      continue

    revision = handler.projects[project]['revision']
    result = cros_build_lib.RunCommand(['git', 'log', '--pretty=full',
                                        '%s..HEAD' % revision],
                                       print_cmd=False, redirect_stdout=True,
                                       cwd=src_path)
    current_author = None
    current_committer = None
    for line in unicode(result.output, 'ascii', 'ignore').splitlines():
      author_match = author_re.match(line)
      if author_match:
        current_author = author_match.group(1)

      committer_match = committer_re.match(line)
      if committer_match:
        current_committer = committer_match.group(1)

      review_match = reviewed_on_re.match(line)
      if review_match:
        review = review_match.group(1)
        _, _, change_number = review.rpartition('/')
        if current_committer != 'chrome-bot':
          cros_build_lib.PrintBuildbotLink(
              'CHUMP %s:%s' % (current_author, change_number),
              review)
        elif not only_print_chumps:
          cros_build_lib.PrintBuildbotLink(
              '%s:%s' % (current_author, change_number),
              review)
Example #3
0
    def _GenerateBlameListSinceLKGM(self):
        """Prints out links to all CL's that have been committed since LKGM.

    Add buildbot trappings to print <a href='url'>text</a> in the waterfall for
    each CL committed since we last had a passing build.
    """
        if not self._ShouldGenerateBlameListSinceLKGM():
            logging.info(
                'Not generating blamelist for lkgm as it is not appropriate '
                'for this build type.')
            return

        handler = git.Manifest(self.lkgm_path)
        reviewed_on_re = re.compile('\s*Reviewed-on:\s*(\S+)')
        author_re = re.compile('\s*Author:.*<(\S+)@\S+>\s*')
        committer_re = re.compile('\s*Commit:.*<(\S+)@\S+>\s*')
        for project in handler.projects.keys():
            rel_src_path = handler.projects[project].get('path')

            # If it's not part of our source tree, it doesn't affect our build.
            if not rel_src_path:
                continue

            # Additional case in case the repo has been removed from the manifest.
            src_path = self.cros_source.GetRelativePath(rel_src_path)
            if not os.path.exists(src_path):
                cros_build_lib.Info('Detected repo removed from manifest %s' %
                                    project)
                continue

            revision = handler.projects[project]['revision']
            result = cros_build_lib.RunCommand(
                ['git', 'log', '--pretty=full',
                 '%s..HEAD' % revision],
                print_cmd=False,
                redirect_stdout=True,
                cwd=src_path)
            current_author = None
            current_committer = None
            for line in result.output.splitlines():
                author_match = author_re.match(line)
                if author_match:
                    current_author = author_match.group(1)

                committer_match = committer_re.match(line)
                if committer_match:
                    current_committer = committer_match.group(1)

                review_match = reviewed_on_re.match(line)
                if review_match:
                    review = review_match.group(1)
                    _, _, change_number = review.rpartition('/')
                    if current_committer != 'chrome-bot':
                        cros_build_lib.PrintBuildbotLink(
                            'CHUMP %s:%s' % (current_author, change_number),
                            review)
                    elif self.build_type != constants.PALADIN_TYPE:
                        # Suppress re-printing changes we tried ourselves on paladin
                        # builders since they are redundant.
                        cros_build_lib.PrintBuildbotLink(
                            '%s:%s' % (current_author, change_number), review)
Example #4
0
def GenerateBlameList(source_repo, lkgm_path, only_print_chumps=False):
    """Generate the blamelist since the specified manifest.

  Args:
    source_repo: Repository object for the source code.
    lkgm_path: Path to LKGM manifest.
    only_print_chumps: If True, only print changes that were chumped.
  """
    handler = git.Manifest(lkgm_path)
    reviewed_on_re = re.compile(r'\s*Reviewed-on:\s*(\S+)')
    author_re = re.compile(r'\s*Author:.*<(\S+)@\S+>\s*')
    committer_re = re.compile(r'\s*Commit:.*<(\S+)@\S+>\s*')
    for rel_src_path, checkout in handler.checkouts_by_path.iteritems():
        project = checkout['name']

        # Additional case in case the repo has been removed from the manifest.
        src_path = source_repo.GetRelativePath(rel_src_path)
        if not os.path.exists(src_path):
            logging.info('Detected repo removed from manifest %s' % project)
            continue

        revision = checkout['revision']
        cmd = ['log', '--pretty=full', '%s..HEAD' % revision]
        try:
            result = git.RunGit(src_path, cmd)
        except cros_build_lib.RunCommandError as ex:
            # Git returns 128 when the revision does not exist.
            if ex.result.returncode != 128:
                raise
            logging.warning('Detected branch removed from local checkout.')
            logging.PrintBuildbotStepWarnings()
            return
        current_author = None
        current_committer = None
        for line in unicode(result.output, 'ascii', 'ignore').splitlines():
            author_match = author_re.match(line)
            if author_match:
                current_author = author_match.group(1)

            committer_match = committer_re.match(line)
            if committer_match:
                current_committer = committer_match.group(1)

            review_match = reviewed_on_re.match(line)
            if review_match:
                review = review_match.group(1)
                _, _, change_number = review.rpartition('/')
                if not current_author:
                    logging.notice(
                        'Failed to locate author before the line of review: '
                        '%s. Author name is set to <Unknown>', line)
                    current_author = '<Unknown>'
                items = [
                    os.path.basename(project),
                    current_author,
                    change_number,
                ]
                # TODO(phobbs) verify the domain of the email address as well.
                if current_committer not in ('chrome-bot',
                                             'chrome-internal-fetch',
                                             'chromeos-commit-bot',
                                             '3su6n15k.default'):
                    items.insert(0, 'CHUMP')
                elif only_print_chumps:
                    continue
                logging.PrintBuildbotLink(' | '.join(items), review)
    def testRelease(self):
        """Run-through of branch creation."""
        self._Prepare(extra_cmd_args=[
            '--branch-name', self.RELEASE_BRANCH_NAME, '--version',
            self.DEFAULT_VERSION
        ])
        # Simulate branch not existing.
        self.rc_mock.AddCmdResult(partial_mock.ListRegex(
            'git show-ref .*%s' % self.RELEASE_BRANCH_NAME),
                                  returncode=1)
        # SHA1 of HEAD for pinned branches.
        self.rc_mock.AddCmdResult(partial_mock.ListRegex('git rev-parse HEAD'),
                                  output='12345')

        before = manifest_version.VersionInfo.from_repo(self.build_root)
        self.RunStage()
        after = manifest_version.VersionInfo.from_repo(self.build_root)
        # Verify Chrome version was bumped.
        self.assertEquals(
            int(after.chrome_branch) - int(before.chrome_branch), 1)
        self.assertEquals(
            int(after.build_number) - int(before.build_number), 1)

        # Verify that manifests were branched properly. Notice that external,
        # explicit-external are pinned to a SHA1, not an actual branch.
        branch_names = {
            'chromite': self.norm_name,
            'external': '12345',
            'explicit-external': '12345',
            'explicit-external-sha1': '12345',
            'src/special-new': self.norm_name + '-new-special-branch',
            'src/special-old': self.norm_name + '-old-special-branch',
            'unpinned': 'refs/heads/master',
            'explicit-unpinned': 'refs/heads/master',
            # If all we had was a sha1, there is not way to even guess what the
            # "master" branch is, so leave it pinned.
            'explicit-unpinned-sha1': '12345',
        }
        # Verify that we correctly transfer branch modes to the branched manifest.
        branch_modes = {
            'explicit-external': 'pin',
            'explicit-external-sha1': 'pin',
            'explicit-unpinned': 'tot',
            'explicit-unpinned-sha1': 'tot',
        }
        for m in ['manifest/default.xml', 'manifest-internal/official.xml']:
            manifest = git.Manifest(os.path.join(self.build_root, m))
            for project_data in manifest.checkouts_by_path.itervalues():
                path = project_data['path']
                branch_name = branch_names[path]
                msg = ('Branch name for %s should be %r, but got %r' %
                       (path, branch_name, project_data['revision']))
                self.assertEquals(project_data['revision'], branch_name, msg)
                if path in branch_modes:
                    self.assertEquals(
                        project_data['branch-mode'], branch_modes[path],
                        'Branch mode for %s should be %r, but got %r' %
                        (path, branch_modes[path],
                         project_data['branch-mode']))

        self._VerifyPush(self.norm_name)
    def testGenerateBlameListSinceLKGM(self):
        """Tests that we can generate a blamelist from two commit messages.

    This test tests the functionality of generating a blamelist for a git log.
    Note in this test there are two commit messages, one commited by the
    Commit Queue and another from Non-Commit Queue.  We test the correct
    handling in both cases.
    """
        fake_git_log = """Author: Sammy Sosa <*****@*****.**>
    Commit: Chris Sosa <*****@*****.**>

    Date:   Mon Aug 8 14:52:06 2011 -0700

    Add in a test for cbuildbot

    TEST=So much testing
    BUG=chromium-os:99999

    Change-Id: Ib72a742fd2cee3c4a5223b8easwasdgsdgfasdf
    Reviewed-on: http://gerrit.chromium.org/gerrit/1234
    Reviewed-by: Fake person <*****@*****.**>
    Tested-by: Sammy Sosa <*****@*****.**>
    Author: Sammy Sosa <*****@*****.**>
    Commit: Gerrit <*****@*****.**>

    Date:   Mon Aug 8 14:52:06 2011 -0700

    Add in a test for cbuildbot

    TEST=So much testing
    BUG=chromium-os:99999

    Change-Id: Ib72a742fd2cee3c4a5223b8easwasdgsdgfasdf
    Reviewed-on: http://gerrit.chromium.org/gerrit/1235
    Reviewed-by: Fake person <*****@*****.**>
    Tested-by: Sammy Sosa <*****@*****.**>
    """
        self.manager.incr_type = 'build'
        self.mox.StubOutWithMock(os.path, 'exists')
        self.mox.StubOutWithMock(cros_build_lib, 'RunCommand')
        self.mox.StubOutWithMock(cros_build_lib, 'PrintBuildbotLink')

        fake_revision = '1234567890'
        fake_project_handler = self.mox.CreateMock(git.Manifest)
        fake_project_handler.projects = {
            'fake/repo': {
                'name': 'fake/repo',
                'path': 'fake/path',
                'revision': fake_revision,
            }
        }
        fake_result = self.mox.CreateMock(cros_build_lib.CommandResult)
        fake_result.output = fake_git_log

        self.mox.StubOutWithMock(git, 'Manifest', use_mock_anything=True)

        git.Manifest(self.tmpmandir +
                     '/LKGM/lkgm.xml').AndReturn(fake_project_handler)
        os.path.exists(mox.StrContains('fake/path')).AndReturn(True)
        cros_build_lib.RunCommand(
            ['git', 'log', '--pretty=full',
             '%s..HEAD' % fake_revision],
            print_cmd=False,
            redirect_stdout=True,
            cwd=self.tmpdir + '/fake/path').AndReturn(fake_result)
        cros_build_lib.PrintBuildbotLink(
            'CHUMP | repo | fake | 1234',
            'http://gerrit.chromium.org/gerrit/1234')
        cros_build_lib.PrintBuildbotLink(
            'repo | fake | 1235', 'http://gerrit.chromium.org/gerrit/1235')
        self.mox.ReplayAll()
        self.manager._GenerateBlameListSinceLKGM()
        self.mox.VerifyAll()