2016-07-14 19:46:57 +00:00
|
|
|
#!/usr/bin/env python
|
2012-12-06 08:52:32 +00:00
|
|
|
# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
|
|
# for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
# BSD-style license that can be found in the LICENSE file.
|
|
|
|
#
|
|
|
|
# This python script creates a version string in a C++ file.
|
|
|
|
|
2019-11-10 21:09:58 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2020-07-07 06:08:20 +00:00
|
|
|
import argparse
|
2014-09-09 01:44:48 +00:00
|
|
|
import hashlib
|
|
|
|
import os
|
2012-12-06 08:52:32 +00:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import utils
|
|
|
|
|
2014-09-09 01:44:48 +00:00
|
|
|
# When these files change, snapshots created by the VM are potentially no longer
|
|
|
|
# backwards-compatible.
|
2019-08-05 20:34:31 +00:00
|
|
|
VM_SNAPSHOT_FILES = [
|
|
|
|
# Header files.
|
|
|
|
'clustered_snapshot.h',
|
|
|
|
'datastream.h',
|
|
|
|
'image_snapshot.h',
|
|
|
|
'object.h',
|
|
|
|
'raw_object.h',
|
|
|
|
'snapshot.h',
|
|
|
|
'snapshot_ids.h',
|
|
|
|
'symbols.h',
|
|
|
|
# Source files.
|
|
|
|
'clustered_snapshot.cc',
|
|
|
|
'dart.cc',
|
|
|
|
'dart_api_impl.cc',
|
|
|
|
'image_snapshot.cc',
|
|
|
|
'object.cc',
|
|
|
|
'raw_object.cc',
|
|
|
|
'raw_object_snapshot.cc',
|
|
|
|
'snapshot.cc',
|
|
|
|
'symbols.cc',
|
2014-09-09 01:44:48 +00:00
|
|
|
]
|
|
|
|
|
2019-08-05 20:34:31 +00:00
|
|
|
|
2020-06-26 18:54:17 +00:00
|
|
|
def MakeSnapshotHashString():
|
|
|
|
vmhash = hashlib.md5()
|
|
|
|
for vmfilename in VM_SNAPSHOT_FILES:
|
|
|
|
vmfilepath = os.path.join(utils.DART_DIR, 'runtime', 'vm', vmfilename)
|
2020-07-07 06:08:20 +00:00
|
|
|
with open(vmfilepath, 'rb') as vmfile:
|
|
|
|
vmhash.update(vmfile.read())
|
2020-06-26 18:54:17 +00:00
|
|
|
return vmhash.hexdigest()
|
2020-06-26 13:35:42 +00:00
|
|
|
|
|
|
|
|
2020-07-07 06:08:20 +00:00
|
|
|
def GetSemanticVersionFormat(no_git_hash, custom_for_pub):
|
|
|
|
version_format = '{{SEMANTIC_SDK_VERSION}}'
|
|
|
|
|
|
|
|
if custom_for_pub and utils.GetChannel() == 'be':
|
|
|
|
if no_git_hash:
|
|
|
|
version_format = '{{LATEST}}.{{PUB_CUSTOM}}'
|
|
|
|
else:
|
|
|
|
version_format = '{{LATEST}}.{{PUB_CUSTOM}}-{{GIT_HASH}}'
|
|
|
|
|
|
|
|
return version_format
|
|
|
|
|
|
|
|
|
|
|
|
def FormatVersionString(version,
|
|
|
|
no_git_hash,
|
|
|
|
custom_for_pub,
|
|
|
|
version_file=None,
|
|
|
|
git_revision_file=None):
|
|
|
|
use_git_hash = not no_git_hash
|
|
|
|
|
|
|
|
semantic_sdk_version = utils.GetSemanticSDKVersion(no_git_hash,
|
|
|
|
version_file,
|
|
|
|
git_revision_file)
|
|
|
|
semantic_version_format = GetSemanticVersionFormat(no_git_hash,
|
|
|
|
custom_for_pub)
|
|
|
|
version_str = (semantic_sdk_version
|
|
|
|
if version_file else semantic_version_format)
|
|
|
|
|
|
|
|
version = version.replace('{{VERSION_STR}}', version_str)
|
|
|
|
|
|
|
|
version = version.replace('{{SEMANTIC_SDK_VERSION}}', semantic_sdk_version)
|
|
|
|
|
|
|
|
if custom_for_pub:
|
|
|
|
# LATEST is only used for custom_for_pub.
|
|
|
|
latest = None
|
|
|
|
if use_git_hash:
|
|
|
|
# If grabbing the dev tag fails, then fall back on the default VERSION file.
|
|
|
|
latest = utils.GetLatestDevTag()
|
|
|
|
if not latest:
|
|
|
|
latest = utils.GetSemanticSDKVersion(no_git_hash=True)
|
|
|
|
version = version.replace('{{LATEST}}', latest)
|
|
|
|
|
|
|
|
version = version.replace('{{PUB_CUSTOM}}', custom_for_pub)
|
|
|
|
|
|
|
|
git_hash = None
|
|
|
|
if use_git_hash:
|
|
|
|
git_hash = utils.GetShortGitHash()
|
|
|
|
if git_hash is None or len(git_hash) != 10:
|
|
|
|
git_hash = '0000000000'
|
|
|
|
version = version.replace('{{GIT_HASH}}', git_hash)
|
2019-08-05 20:34:31 +00:00
|
|
|
|
2020-03-23 10:00:03 +00:00
|
|
|
channel = utils.GetChannel()
|
2020-07-07 06:08:20 +00:00
|
|
|
version = version.replace('{{CHANNEL}}', channel)
|
|
|
|
|
|
|
|
version_time = None
|
|
|
|
if use_git_hash:
|
|
|
|
version_time = utils.GetGitTimestamp()
|
|
|
|
if version_time == None:
|
|
|
|
version_time = 'Unknown timestamp'
|
|
|
|
version = version.replace('{{COMMIT_TIME}}', version_time.decode('utf-8'))
|
|
|
|
|
2019-08-05 20:34:31 +00:00
|
|
|
snapshot_hash = MakeSnapshotHashString()
|
2020-07-07 06:08:20 +00:00
|
|
|
version = version.replace('{{SNAPSHOT_HASH}}', snapshot_hash)
|
|
|
|
|
|
|
|
return version
|
2012-12-06 08:52:32 +00:00
|
|
|
|
|
|
|
|
2020-07-07 06:08:20 +00:00
|
|
|
def main():
|
2019-08-05 20:34:31 +00:00
|
|
|
try:
|
|
|
|
# Parse input.
|
2020-07-07 06:08:20 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
'--custom_for_pub',
|
|
|
|
help=('Generates a version string that works with pub that '
|
|
|
|
'includes the given string. This is silently ignored on '
|
|
|
|
'channels other than be.'))
|
|
|
|
parser.add_argument('--input', help='Input template file.')
|
|
|
|
parser.add_argument(
|
|
|
|
'--no_git_hash',
|
|
|
|
action='store_true',
|
2020-06-26 18:54:17 +00:00
|
|
|
default=False,
|
2020-07-07 06:08:20 +00:00
|
|
|
help=('Don\'t try to call git to derive things like '
|
|
|
|
'git revision hash.'))
|
|
|
|
parser.add_argument('--output', help='output file name')
|
|
|
|
parser.add_argument('-q',
|
|
|
|
'--quiet',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='DEPRECATED: Does nothing!')
|
|
|
|
parser.add_argument('--version-file', help='Path to the VERSION file.')
|
|
|
|
parser.add_argument('--git-revision-file',
|
|
|
|
help='Path to the GIT_REVISION file.')
|
|
|
|
parser.add_argument(
|
|
|
|
'--format',
|
|
|
|
default='{{VERSION_STR}}',
|
|
|
|
help='Version format used if no input template is given.')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
2019-08-05 20:34:31 +00:00
|
|
|
|
|
|
|
# If there is no input template, then write the bare version string to
|
2020-07-07 06:08:20 +00:00
|
|
|
# args.output. If there is no args.output, then write the version
|
2019-08-05 20:34:31 +00:00
|
|
|
# string to stdout.
|
2020-07-07 06:08:20 +00:00
|
|
|
|
|
|
|
version_template = ''
|
|
|
|
if args.input:
|
|
|
|
version_template = open(args.input).read()
|
|
|
|
elif not args.format is None:
|
|
|
|
version_template = args.format
|
|
|
|
else:
|
|
|
|
raise 'No version template given! Set either --input or --format.'
|
|
|
|
|
|
|
|
version = FormatVersionString(version_template, args.no_git_hash,
|
|
|
|
args.custom_for_pub, args.version_file,
|
|
|
|
args.git_revision_file)
|
|
|
|
|
|
|
|
if args.output:
|
|
|
|
with open(args.output, 'w') as fh:
|
|
|
|
fh.write(version)
|
|
|
|
else:
|
|
|
|
sys.stdout.write(version)
|
2019-08-05 20:34:31 +00:00
|
|
|
|
|
|
|
return 0
|
2020-07-07 06:08:20 +00:00
|
|
|
|
2019-08-05 20:34:31 +00:00
|
|
|
except Exception as inst:
|
|
|
|
sys.stderr.write('make_version.py exception\n')
|
|
|
|
sys.stderr.write(str(inst))
|
|
|
|
sys.stderr.write('\n')
|
2020-07-07 06:08:20 +00:00
|
|
|
|
2019-08-05 20:34:31 +00:00
|
|
|
return -1
|
|
|
|
|
2012-12-06 08:52:32 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-07-07 06:08:20 +00:00
|
|
|
sys.exit(main())
|