def GetVersion(version_file_name):
    with open(version_file_name, 'r') as version_file:
        lines = [line.strip() for line in version_file.readlines()]
        lines = [line for line in lines if not line.startswith('#')]
        if len(lines) != 1:
            raise Exception('Version file ' + version_file +
                            ' is expected to have exactly one line')
        version = lines[0].strip()
        utils.check_basic_semver_version(
            version, 'in version file ' + version_file_name)
        return version
Esempio n. 2
0
def GetVersion():
    with open(VERSION_FILE, 'r') as version_file:
        lines = version_file.readlines()
        if len(lines) != 1:
            raise Exception('Version file ' + VERSION_FILE +
                            ' is expected to have exactly one line')
        version = lines[0].strip()
        if (version == '1.0.1'):
            raise Exception('Version file ' + VERSION_FILE +
                            'cannot have version 1.0.1')
        if (version == '1.0.0'):
            version = '1.0.1'
        utils.check_basic_semver_version(version,
                                         'in version file ' + VERSION_FILE)
        return version
Esempio n. 3
0
def prepare_branch(args):
    branch_version = args.new_dev_branch[0]
    commithash = args.new_dev_branch[1]

    current_semver = utils.check_basic_semver_version(
        R8_DEV_BRANCH, ", current release branch version should be x.y", 2)
    semver = utils.check_basic_semver_version(
        branch_version, ", release branch version should be x.y", 2)
    if not semver.larger_than(current_semver):
        print('New branch version "' + branch_version +
              '" must be strictly larger than the current "' + R8_DEV_BRANCH +
              '"')
        sys.exit(1)

    def make_branch(options):
        with utils.TempDir() as temp:
            subprocess.check_call(['git', 'clone', utils.REPO_SOURCE, temp])
            with utils.ChangedWorkingDirectory(temp):
                subprocess.check_call(
                    ['git', 'branch', branch_version, commithash])

                subprocess.check_call(['git', 'checkout', branch_version])

                # Rewrite the version, commit and validate.
                old_version = 'master'
                full_version = branch_version + '.0-dev'
                version_prefix = 'LABEL = "'
                sed(version_prefix + old_version,
                    version_prefix + full_version, R8_VERSION_FILE)

                subprocess.check_call(
                    ['git', 'commit', '-a', '-m',
                     'Version %s' % full_version])

                version_diff_output = subprocess.check_output(
                    ['git', 'diff', '%s..HEAD' % commithash])

                validate_version_change_diff(version_diff_output, old_version,
                                             full_version)

                # Double check that we want to create a new release branch.
                if not options.dry_run:
                    input = raw_input('Create new branch for %s [y/N]:' %
                                      branch_version)
                    if input != 'y':
                        print 'Aborting new branch for %s' % branch_version
                        sys.exit(1)

                maybe_check_call(
                    options,
                    ['git', 'push', 'origin',
                     'HEAD:%s' % branch_version])
                maybe_tag(options, full_version)

                print(
                    'Updating tools/r8_release.py to make new dev releases on %s'
                    % branch_version)

                subprocess.check_call(
                    ['git', 'new-branch', 'update-release-script'])

                # Check this file for the setting of the current dev branch.
                result = None
                for line in open(THIS_FILE_RELATIVE, 'r'):
                    result = re.match(r"^R8_DEV_BRANCH = '(\d+).(\d+)'", line)
                    if result:
                        break
                if not result or not result.group(1):
                    print 'Failed to find version label in %s' % THIS_FILE_RELATIVE
                    sys.exit(1)

                # Update this file with the new dev branch.
                sed(
                    "R8_DEV_BRANCH = '%s.%s" %
                    (result.group(1), result.group(2)),
                    "R8_DEV_BRANCH = '%s.%s" %
                    (str(semver.major), str(semver.minor)), THIS_FILE_RELATIVE)

                message = \
                    'Prepare %s for branch %s' % (THIS_FILE_RELATIVE, branch_version)
                subprocess.check_call(['git', 'commit', '-a', '-m', message])

                branch_diff_output = subprocess.check_output(
                    ['git', 'diff', 'HEAD~'])

                validate_branch_change_diff(branch_diff_output, R8_DEV_BRANCH,
                                            branch_version)

                maybe_check_call(options,
                                 ['git', 'cl', 'upload', '-f', '-m', message])

                print
                print 'Make sure to send out the branch change CL for review.'
                print

    return make_branch