Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
make_version.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5#
6# This python script creates a version string in a C++ file.
7
8from __future__ import print_function
9
10import argparse
11import hashlib
12import os
13import sys
14import utils
15
16# When these files change, snapshots created by the VM are potentially no longer
17# backwards-compatible.
18VM_SNAPSHOT_FILES = [
19 # Header files.
20 'app_snapshot.h',
21 'datastream.h',
22 'image_snapshot.h',
23 'object.h',
24 'raw_object.h',
25 'snapshot.h',
26 'symbols.h',
27 # Source files.
28 'app_snapshot.cc',
29 'dart.cc',
30 'dart_api_impl.cc',
31 'image_snapshot.cc',
32 'object.cc',
33 'raw_object.cc',
34 'snapshot.cc',
35 'symbols.cc',
36]
37
38
40 vmhash = hashlib.md5()
41 for vmfilename in VM_SNAPSHOT_FILES:
42 vmfilepath = os.path.join(utils.DART_DIR, 'runtime', 'vm', vmfilename)
43 with open(vmfilepath, 'rb') as vmfile:
44 vmhash.update(vmfile.read())
45 return vmhash.hexdigest()
46
47
48def GetSemanticVersionFormat(no_git_hash):
49 version_format = '{{SEMANTIC_SDK_VERSION}}'
50 return version_format
51
52
54 no_git_hash,
55 no_sdk_hash,
56 version_file=None,
57 git_revision_file=None,
58 git_timestamp_file=None):
59 semantic_sdk_version = utils.GetVersion(no_git_hash, version_file,
60 git_revision_file)
61 semantic_version_format = GetSemanticVersionFormat(no_git_hash)
62 version_str = (semantic_sdk_version
63 if version_file else semantic_version_format)
64
65 version = version.replace('{{VERSION_STR}}', version_str)
66
67 version = version.replace('{{SEMANTIC_SDK_VERSION}}', semantic_sdk_version)
68
69 git_hash = None
70 # If we need SDK hash and git usage is not suppressed then try to get it.
71 if not no_sdk_hash and not no_git_hash:
72 git_hash = utils.GetShortGitHash()
73 if git_hash is None or len(git_hash) != 10:
74 git_hash = '0000000000'
75 version = version.replace('{{GIT_HASH}}', git_hash)
76
77 channel = utils.GetChannel()
78 version = version.replace('{{CHANNEL}}', channel)
79
80 version_time = None
81 if not no_git_hash:
82 version_time = utils.GetGitTimestamp(git_timestamp_file)
83 if version_time == None:
84 version_time = 'Unknown timestamp'
85 version = version.replace('{{COMMIT_TIME}}', version_time)
86
87 snapshot_hash = MakeSnapshotHashString()
88 version = version.replace('{{SNAPSHOT_HASH}}', snapshot_hash)
89
90 return version
91
92
93def main():
94 try:
95 # Parse input.
96 parser = argparse.ArgumentParser()
97 parser.add_argument('--input', help='Input template file.')
98 parser.add_argument(
99 '--no-git-hash',
100 action='store_true',
101 default=False,
102 help=('Don\'t try to call git to derive things like '
103 'git revision hash.'))
104 parser.add_argument(
105 '--no-sdk-hash',
106 action='store_true',
107 default=False,
108 help='Use null SDK hash to disable SDK verification in the VM')
109 parser.add_argument('--output', help='output file name')
110 parser.add_argument('-q',
111 '--quiet',
112 action='store_true',
113 default=False,
114 help='DEPRECATED: Does nothing!')
115 parser.add_argument('--version-file', help='Path to the VERSION file.')
116 parser.add_argument('--git-revision-file',
117 help='Path to the GIT_REVISION file.')
118 parser.add_argument('--git-timestamp-file',
119 help='Path to the GIT_TIMESTAMP file.')
120 parser.add_argument(
121 '--format',
122 default='{{VERSION_STR}}',
123 help='Version format used if no input template is given.')
124
125 args = parser.parse_args()
126
127 # If there is no input template, then write the bare version string to
128 # args.output. If there is no args.output, then write the version
129 # string to stdout.
130
131 version_template = ''
132 if args.input:
133 version_template = open(args.input).read()
134 elif not args.format is None:
135 version_template = args.format
136 else:
137 raise 'No version template given! Set either --input or --format.'
138
139 version = FormatVersionString(version_template, args.no_git_hash,
140 args.no_sdk_hash, args.version_file,
141 args.git_revision_file,
142 args.git_timestamp_file)
143
144 if args.output:
145 with open(args.output, 'w') as fh:
146 fh.write(version)
147 else:
148 sys.stdout.write(version)
149
150 return 0
151
152 except Exception as inst:
153 sys.stderr.write('make_version.py exception\n')
154 sys.stderr.write(str(inst))
155 sys.stderr.write('\n')
156
157 return -1
158
159
160if __name__ == '__main__':
161 sys.exit(main())
static bool read(SkStream *stream, void *buffer, size_t amount)
Definition main.py:1
FormatVersionString(version, no_git_hash, no_sdk_hash, version_file=None, git_revision_file=None, git_timestamp_file=None)
GetSemanticVersionFormat(no_git_hash)
GetChannel(version_file=None)
Definition utils.py:376
GetShortGitHash(repo_path=DART_DIR)
Definition utils.py:443
GetGitTimestamp(git_timestamp_file=None, repo_path=DART_DIR)
Definition utils.py:458
GetVersion(no_git_hash=False, version_file=None, git_revision_file=None)
Definition utils.py:357