def main(argv):
    parser = GetParser()
    options = parser.parse_args(argv)
    options.Freeze()

    overlay_dir = os.path.abspath(_OVERLAY_DIR % {'srcroot': options.srcroot})
    android_package_dir = os.path.join(overlay_dir, constants.ANDROID_CP)
    version_to_uprev = None
    subpaths = None

    (unstable_ebuild,
     stable_ebuilds) = FindAndroidCandidates(android_package_dir)

    if options.force_version:
        version_to_uprev = options.force_version
        subpaths = IsBuildIdValid(options.android_bucket_url,
                                  options.android_build_branch,
                                  version_to_uprev)
        if not subpaths:
            logging.error('Requested build %s is not valid' % version_to_uprev)
    else:
        version_to_uprev, subpaths = GetLatestBuild(
            options.android_bucket_url, options.android_build_branch)

    acls = MakeAclDict(android_package_dir)
    CopyToArcBucket(options.android_bucket_url, options.android_build_branch,
                    version_to_uprev, subpaths, options.arc_bucket_url, acls)

    stable_candidate = portage_util.BestEBuild(stable_ebuilds)

    if stable_candidate:
        logging.info('Stable candidate found %s' % stable_candidate.version)
    else:
        logging.info('No stable candidate found.')

    tracking_branch = 'remotes/m/%s' % os.path.basename(
        options.tracking_branch)
    existing_branch = git.GetCurrentBranch(android_package_dir)
    work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH,
                                                tracking_branch,
                                                android_package_dir)
    work_branch.CreateBranch()

    # In the case of uprevving overlays that have patches applied to them,
    # include the patched changes in the stabilizing branch.
    if existing_branch:
        git.RunGit(overlay_dir, ['rebase', existing_branch])

    android_version_atom = MarkAndroidEBuildAsStable(
        stable_candidate, unstable_ebuild, constants.ANDROID_PN,
        version_to_uprev, android_package_dir, options.android_build_branch,
        options.arc_bucket_url)
    if android_version_atom:
        if options.boards:
            cros_mark_as_stable.CleanStalePackages(options.srcroot,
                                                   options.boards.split(':'),
                                                   [android_version_atom])

        # Explicit print to communicate to caller.
        print('ANDROID_VERSION_ATOM=%s' % android_version_atom)
Exemplo n.º 2
0
def main(argv):
    parser = GetParser()
    options = parser.parse_args(argv)
    options.Freeze()

    overlay_dir = os.path.abspath(_OVERLAY_DIR % {'srcroot': options.srcroot})
    android_package_dir = os.path.join(overlay_dir, constants.ANDROID_CP)
    version_to_uprev = None

    (unstable_ebuild,
     stable_ebuilds) = FindAndroidCandidates(android_package_dir)
    acls = MakeAclDict(android_package_dir)
    # Mirror artifacts, i.e., images and some sdk tools (e.g., adb, aapt).
    version_to_uprev = MirrorArtifacts(options.android_bucket_url,
                                       options.android_build_branch,
                                       options.arc_bucket_url, acls,
                                       constants.ANDROID_BUILD_TARGETS,
                                       options.force_version)

    # Mirror GTS.
    MirrorArtifacts(options.android_bucket_url,
                    options.android_gts_build_branch, options.arc_bucket_url,
                    acls, constants.ANDROID_GTS_BUILD_TARGETS)

    stable_candidate = portage_util.BestEBuild(stable_ebuilds)

    if stable_candidate:
        logging.info('Stable candidate found %s' % stable_candidate.version)
    else:
        logging.info('No stable candidate found.')

    tracking_branch = 'remotes/m/%s' % os.path.basename(
        options.tracking_branch)
    existing_branch = git.GetCurrentBranch(android_package_dir)
    work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH,
                                                tracking_branch,
                                                android_package_dir)
    work_branch.CreateBranch()

    # In the case of uprevving overlays that have patches applied to them,
    # include the patched changes in the stabilizing branch.
    if existing_branch:
        git.RunGit(overlay_dir, ['rebase', existing_branch])

    android_version_atom = MarkAndroidEBuildAsStable(
        stable_candidate, unstable_ebuild, constants.ANDROID_PN,
        version_to_uprev, android_package_dir, options.android_build_branch,
        options.arc_bucket_url)
    if android_version_atom:
        if options.boards:
            cros_mark_as_stable.CleanStalePackages(options.srcroot,
                                                   options.boards.split(':'),
                                                   [android_version_atom])

        # Explicit print to communicate to caller.
        print('ANDROID_VERSION_ATOM=%s' % android_version_atom)
Exemplo n.º 3
0
    def setUp(self):
        # Always stub RunCommmand out as we use it in every method.
        self.rc_mock = self.PatchObject(cros_build_lib, 'RunCommand')

        self._branch_name = 'test_branch'
        self._target_manifest_branch = 'cros/test'
        self._branch = cros_mark_as_stable.GitBranch(
            branch_name=self._branch_name,
            tracking_branch=self._target_manifest_branch,
            cwd='.')
 def testExists(self):
   branch = cros_mark_as_stable.GitBranch(self._branch_name,
                                          self._target_manifest_branch, '.')
   # Test if branch exists that is created
   result = cros_build_lib.CommandResult(output=self._branch_name + '\n')
   cros_build_lib.RunCommandCaptureOutput(['git', 'branch'], print_cmd=False,
                                          cwd='.').AndReturn(result)
   self.mox.ReplayAll()
   self.assertTrue(branch.Exists())
   self.mox.VerifyAll()
Exemplo n.º 5
0
    def setUp(self):
        # Always stub RunCommmand out as we use it in every method.
        self.git_mock = self.PatchObject(git, 'RunGit')
        self.start_mock = self.PatchObject(repo_util.Repository, 'StartBranch')

        self._branch_name = 'test_branch'
        self._target_manifest_branch = 'cros/test'
        self._branch = cros_mark_as_stable.GitBranch(
            branch_name=self._branch_name,
            tracking_branch=self._target_manifest_branch,
            cwd='.')
def main(argv):
    parser = GetParser()
    options = parser.parse_args(argv)
    options.Freeze()
    chrome_rev = options.revision

    if options.force_version and chrome_rev not in (
            constants.CHROME_REV_SPEC, constants.CHROME_REV_LATEST):
        parser.error('--force_version is not compatible with the %r '
                     'option.' % (chrome_rev, ))

    overlay_dir = os.path.abspath(_OVERLAY_DIR % {'srcroot': options.srcroot})
    chrome_package_dir = os.path.join(overlay_dir, constants.CHROME_CP)
    version_to_uprev = None
    commit_to_use = None
    sticky_branch = None

    (unstable_ebuild,
     stable_ebuilds) = FindChromeCandidates(chrome_package_dir)

    if chrome_rev == constants.CHROME_REV_LOCAL:
        if 'CHROME_ROOT' in os.environ:
            chrome_root = os.environ['CHROME_ROOT']
        else:
            chrome_root = os.path.join(os.environ['HOME'], 'chrome_root')

        version_to_uprev = _GetTipOfTrunkVersionFile(chrome_root)
        commit_to_use = 'Unknown'
        logging.info('Using local source, versioning is untrustworthy.')
    elif chrome_rev == constants.CHROME_REV_SPEC:
        if '.' in options.force_version:
            version_to_uprev = options.force_version
        else:
            commit_to_use = options.force_version
            if '@' in commit_to_use:
                commit_to_use = commit_to_use.rpartition('@')[2]
            version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
                                                      commit_to_use)
    elif chrome_rev == constants.CHROME_REV_TOT:
        commit_to_use = gob_util.GetTipOfTrunkRevision(options.chrome_url)
        version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
                                                  commit_to_use)
    elif chrome_rev == constants.CHROME_REV_LATEST:
        if options.force_version:
            if '.' not in options.force_version:
                parser.error(
                    '%s only accepts released Chrome versions, not SVN or '
                    'Git revisions.' % (chrome_rev, ))
            version_to_uprev = options.force_version
        else:
            version_to_uprev = GetLatestRelease(options.chrome_url)
    else:
        sticky_ebuild = _GetStickyEBuild(stable_ebuilds)
        sticky_version = sticky_ebuild.chrome_version
        sticky_branch = sticky_version.rpartition('.')[0]
        version_to_uprev = GetLatestRelease(options.chrome_url, sticky_branch)

    stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev,
                                                sticky_branch)

    if stable_candidate:
        logging.info('Stable candidate found %s' % stable_candidate)
    else:
        logging.info('No stable candidate found.')

    tracking_branch = 'remotes/m/%s' % os.path.basename(
        options.tracking_branch)
    existing_branch = git.GetCurrentBranch(chrome_package_dir)
    work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH,
                                                tracking_branch,
                                                chrome_package_dir)
    work_branch.CreateBranch()

    # In the case of uprevving overlays that have patches applied to them,
    # include the patched changes in the stabilizing branch.
    if existing_branch:
        git.RunGit(chrome_package_dir, ['rebase', existing_branch])

    chrome_version_atom = MarkChromeEBuildAsStable(
        stable_candidate, unstable_ebuild, 'chromeos-chrome', chrome_rev,
        version_to_uprev, commit_to_use, chrome_package_dir)
    if chrome_version_atom:
        if options.boards:
            cros_mark_as_stable.CleanStalePackages(options.srcroot,
                                                   options.boards.split(':'),
                                                   [chrome_version_atom])

        # If we did rev Chrome, now is a good time to uprev other packages.
        for other_ebuild in constants.OTHER_CHROME_PACKAGES:
            other_ebuild_name = os.path.basename(other_ebuild)
            other_package_dir = os.path.join(overlay_dir, other_ebuild)
            (other_unstable_ebuild,
             other_stable_ebuilds) = FindChromeCandidates(other_package_dir)
            other_stable_candidate = FindChromeUprevCandidate(
                other_stable_ebuilds, chrome_rev, sticky_branch)
            revved_atom = MarkChromeEBuildAsStable(
                other_stable_candidate, other_unstable_ebuild,
                other_ebuild_name, chrome_rev, version_to_uprev, commit_to_use,
                other_package_dir)
            if revved_atom and options.boards:
                cros_mark_as_stable.CleanStalePackages(
                    options.srcroot, options.boards.split(':'), [revved_atom])

    # Explicit print to communicate to caller.
    if chrome_version_atom:
        print('CHROME_VERSION_ATOM=%s' % chrome_version_atom)
Exemplo n.º 7
0
def main(_argv):
    usage_options = '|'.join(constants.VALID_CHROME_REVISIONS)
    usage = '%s OPTIONS [%s]' % (__file__, usage_options)
    parser = optparse.OptionParser(usage)
    parser.add_option('-b', '--boards', default='x86-generic')
    parser.add_option('-c', '--chrome_url', default=gclient.GetBaseURLs()[0])
    parser.add_option('-f', '--force_revision', default=None)
    parser.add_option('-s',
                      '--srcroot',
                      default=os.path.join(os.environ['HOME'], 'trunk', 'src'),
                      help='Path to the src directory')
    parser.add_option('-t',
                      '--tracking_branch',
                      default='cros/master',
                      help='Branch we are tracking changes against')
    (options, args) = parser.parse_args()

    if len(args) != 1 or args[0] not in constants.VALID_CHROME_REVISIONS:
        parser.error('Commit requires arg set to one of %s.' %
                     constants.VALID_CHROME_REVISIONS)

    overlay_dir = os.path.abspath(_CHROME_OVERLAY_DIR %
                                  {'srcroot': options.srcroot})
    chrome_rev = args[0]
    version_to_uprev = None
    commit_to_use = None
    sticky_branch = None

    (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(overlay_dir)

    if chrome_rev == constants.CHROME_REV_LOCAL:
        if 'CHROME_ROOT' in os.environ:
            chrome_root = os.environ['CHROME_ROOT']
        else:
            chrome_root = os.path.join(os.environ['HOME'], 'chrome_root')

        version_to_uprev = _GetTipOfTrunkVersionFile(chrome_root)
        commit_to_use = 'Unknown'
        cros_build_lib.Info('Using local source, versioning is untrustworthy.')
    elif chrome_rev == constants.CHROME_REV_SPEC:
        commit_to_use = options.force_revision
        if '@' in commit_to_use:
            commit_to_use = ParseMaxRevision(commit_to_use)
        version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
                                                  commit_to_use)
    elif chrome_rev == constants.CHROME_REV_TOT:
        commit_to_use = gclient.GetTipOfTrunkSvnRevision(options.chrome_url)
        version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
                                                  commit_to_use)
    elif chrome_rev == constants.CHROME_REV_LATEST:
        version_to_uprev = _GetLatestRelease(options.chrome_url)
    else:
        sticky_ebuild = _GetStickyEBuild(stable_ebuilds)
        sticky_version = sticky_ebuild.chrome_version
        sticky_branch = sticky_version.rpartition('.')[0]
        version_to_uprev = _GetLatestRelease(options.chrome_url, sticky_branch)

    stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev,
                                                sticky_branch)

    if stable_candidate:
        cros_build_lib.Info('Stable candidate found %s' % stable_candidate)
    else:
        cros_build_lib.Info('No stable candidate found.')

    tracking_branch = 'remotes/m/%s' % os.path.basename(
        options.tracking_branch)
    existing_branch = git.GetCurrentBranch(overlay_dir)
    work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH,
                                                tracking_branch, overlay_dir)
    work_branch.CreateBranch()

    # In the case of uprevving overlays that have patches applied to them,
    # include the patched changes in the stabilizing branch.
    if existing_branch:
        cros_build_lib.RunCommand(['git', 'rebase', existing_branch],
                                  cwd=overlay_dir)

    chrome_version_atom = MarkChromeEBuildAsStable(stable_candidate,
                                                   unstable_ebuild, chrome_rev,
                                                   version_to_uprev,
                                                   commit_to_use, overlay_dir)
    # Explicit print to communicate to caller.
    if chrome_version_atom:
        cros_mark_as_stable.CleanStalePackages(options.boards.split(':'),
                                               [chrome_version_atom])
        print 'CHROME_VERSION_ATOM=%s' % chrome_version_atom
Exemplo n.º 8
0
def UprevStableEBuild(ebuild_dir,
                      commit_to_use,
                      date_of_commit,
                      tracking_branch='cros/master'):
    """Checks if there already if a stable Mojo ebuild for the given commit.

  If there already is a stable Mojo ebuild for the given commit, this
  function does nothing and returns None. Otherwise creates a stabilization
  branch with a single commit that creates a new stable ebuild and deletes
  all other stable ebuilds.

  Args:
    ebuild_dir: Path to the directory holding Mojo ebuilds.
    commit_to_use: The upstream Mojo commit id.
    date_of_commit: The date of the commit.
    tracking_branch: The branch that the stabilization branch should track.

  Returns:
    None or a version atom describing the newly created ebuild.
  """
    # There is no version number or other monotonically increasing value
    # that is suitable to use as a version number except for the point
    # in time that a commit was added to the repository. So we use that
    # for now.
    pvr = date_of_commit.strftime('0.%Y%m%d.%H%M%S-r1')
    mojo_stable_pn = '%s-%s.ebuild' % (MOJO_PN, pvr)

    # Find existing stable ebuilds and only add a new one if there's a
    # newer commit.
    existing_ebuilds = GetStableEBuilds(ebuild_dir)
    if mojo_stable_pn in existing_ebuilds:
        return None

    # OK. First create a stablizing branch.
    tracking_branch_full = 'remotes/m/%s' % os.path.basename(tracking_branch)
    existing_branch = git.GetCurrentBranch(ebuild_dir)
    work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH,
                                                tracking_branch_full,
                                                ebuild_dir)
    work_branch.CreateBranch()

    # In the case of uprevving overlays that have patches applied to them,
    # include the patched changes in the stabilizing branch.
    if existing_branch:
        git.RunGit(ebuild_dir, ['rebase', existing_branch])

    # Create a new ebuild.
    unstable_ebuild_path = os.path.join(
        ebuild_dir, MOJO_PN + portage_util.WORKON_EBUILD_SUFFIX)
    new_stable_ebuild_path = os.path.join(ebuild_dir, mojo_stable_pn)
    variables = {'MOJO_REVISION': commit_to_use}
    portage_util.EBuild.MarkAsStable(unstable_ebuild_path,
                                     new_stable_ebuild_path,
                                     variables,
                                     make_stable=True)

    # Add it to the repo.
    git.RunGit(ebuild_dir, ['add', new_stable_ebuild_path])

    # Nuke the now stale older ebuilds.
    for f in existing_ebuilds:
        git.RunGit(ebuild_dir, ['rm', '-f', f])

    # ... and finally commit the change.
    portage_util.EBuild.CommitChange(
        'Updated %s to upstream commit %s.' % (MOJO_CP, commit_to_use),
        ebuild_dir)
    # Return version atom for newly created ebuild.
    return MOJO_CP + '-' + pvr