forked from chromiumembedded/cef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcef_version.py
275 lines (231 loc) · 9.88 KB
/
cef_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# Copyright (c) 2019 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file.
from __future__ import absolute_import
from __future__ import print_function
from file_util import *
import git_util as git
import os
class VersionFormatter:
""" Formats CEF version information. """
def __init__(self, chromium_src_path=None):
if chromium_src_path is None:
# Relative to the current directory.
script_path = os.path.abspath(os.path.dirname(__file__))
chromium_src_path = os.path.abspath(
os.path.join(script_path, os.pardir, os.pardir))
self.src_path = chromium_src_path
assert os.path.isdir(self.src_path), self.src_path
self.cef_path = os.path.join(self.src_path, 'cef')
assert os.path.isdir(self.cef_path), self.cef_path
# Whether to use the old version format by default.
self._old_format_default = \
bool(int(os.environ.get('CEF_OLD_VERSION_FORMAT', '0')))
self.reset()
def reset(self):
""" Reset internal state. """
self._chrome_version = {}
self._cef_version = {}
self._cef_commit = {}
self._branch_version = {}
self._old_version_string = None
self._old_version_parts = {}
self._version_string = None
self._version_parts = {}
def get_chrome_version_components(self):
""" Returns Chrome version components. """
if not bool(self._chrome_version):
file_path = os.path.join(self.src_path, 'chrome', 'VERSION')
assert os.path.isfile(file_path), file_path
read_version_file(file_path, self._chrome_version)
return self._chrome_version
def get_cef_version_components(self):
""" Returns CEF version components. """
if not bool(self._cef_version):
file_path = os.path.join(self.cef_path, 'VERSION.in')
assert os.path.isfile(file_path), file_path
read_version_file(file_path, self._cef_version)
return self._cef_version
def get_cef_commit_components(self):
""" Returns CEF commit components. """
if not bool(self._cef_commit):
hash = git.get_hash(self.cef_path)
number = git.get_commit_number(self.cef_path)
self._cef_commit = {'HASH': hash, 'NUMBER': number}
return self._cef_commit
def get_cef_branch_version_components(self):
""" Computes the CEF branch version. """
if not bool(self._branch_version):
minor = 0
bugfix = 0
# Retrieve the list of commits that have been applied on the current
# branch since branching from origin/master.
hashes = git.get_branch_hashes(self.cef_path)
for hash in hashes:
# Determine if the API hash file was modified by the commit.
found = False
files = git.get_changed_files(self.cef_path, hash)
for file in files:
if file.find('cef_api_hash.h') >= 0:
found = True
break
if found:
minor += 1
bugfix = 0
else:
bugfix += 1
self._branch_version = {'MINOR': minor, 'PATCH': bugfix}
return self._branch_version
def get_chromium_version_string(self):
""" Returns the Chromium version number string. """
chrome_version = self.get_chrome_version_components()
return '%s.%s.%s.%s' % (chrome_version['MAJOR'], chrome_version['MINOR'],
chrome_version['BUILD'], chrome_version['PATCH'])
@staticmethod
def _format_commit_hash(hash):
return 'g%s' % hash[:7]
# Computes old version numbers in the format "X.YYYY.A.gHHHHHHH".
#
# Where:
# - "X" is the CEF major version (currently 3).
# - "YYYY" is the Chromium branch.
# - "A" is an incremental number representing the number of commits in the
# current branch. This is roughly equivalent to the SVN revision number but
# on a per-branch basis and assists people in quickly determining the order
# of builds in the same branch (for bug reports, etc).
# - "gHHHHHHH" is the 7-character abbreviation for the Git commit hash. This
# facilitates lookup of the relevant commit history in Git.
#
# Example: "3.3729.1921.g62d140e"
def _compute_old_version(self):
if not self._old_version_string is None:
return
chrome_version = self.get_chrome_version_components()
cef_version = self.get_cef_version_components()
cef_commit = self.get_cef_commit_components()
cef_commit_hash = self._format_commit_hash(cef_commit['HASH'])
self._old_version_parts = {
'MAJOR': int(cef_version['CEF_MAJOR']),
'MINOR': int(chrome_version['BUILD']),
'PATCH': int(cef_commit['NUMBER'])
}
self._old_version_string = \
'%s.%s.%s.%s' % (cef_version['CEF_MAJOR'], chrome_version['BUILD'],
cef_commit['NUMBER'], cef_commit_hash)
def _get_old_version_string(self):
self._compute_old_version()
return self._old_version_string
def _get_old_version_parts(self):
self._compute_old_version()
return self._old_version_parts
# Computes version numbers in the format:
# - "X.Y.Z+gHHHHHHH+chromium-A.B.C.D" for release branch builds.
# - "X.0.0-master.N+gHHHHHHH+chromium-A.B.C.D" for master branch builds.
#
# Where:
# - "X" is the Chromium major version (e.g. 74).
# - "Y" is an incremental number that starts at 0 when a release branch is
# created and changes only when the CEF C/C++ API changes (similar to how
# the CEF_API_HASH_UNIVERSAL value behaves in cef_version.h) (release branch
# only).
# - "Z" is an incremental number that starts at 0 when a release branch is
# created and changes on each commit, with reset to 0 when "Y" changes
# (release branch only).
# - "N" is an incremental number representing the number of commits (master
# branch only).
# - "gHHHHHHH" is the 7-character abbreviation for the Git commit hash. This
# facilitates lookup of the relevant commit history in Git.
# - "A.B.C.D" is the Chromium version (e.g. 74.0.3729.6).
#
# Examples:
# - "74.0.1+g62d140e+chromium-74.0.3729.6" for a release build.
# - "74.0.0-master.1920+g725ed88+chromium-74.0.3729.0" for a master build.
def _compute_version(self):
if not self._version_string is None:
return
chrome_version = self.get_chrome_version_components()
chrome_major = chrome_version['MAJOR']
chrome_version_part = 'chromium-' + self.get_chromium_version_string()
cef_commit = self.get_cef_commit_components()
cef_commit_hash = self._format_commit_hash(cef_commit['HASH'])
# Determine whether the current commit is on a release branch. For example,
# if using Chrome build 3683, are we on CEF branch "3683" or "origin/3683"?
release_branch = chrome_version['BUILD']
on_release_branch = (
git.is_ancestor(self.cef_path, 'HEAD', release_branch) or
git.is_ancestor(self.cef_path, 'HEAD', 'origin/' + release_branch))
if not on_release_branch:
# Not on a commit that is part of an official named release branch. See
# if we can get the name of the branch we are on (may be just "HEAD").
cef_branch_name = git.get_branch_name(self.cef_path).split('/')[-1]
self._version_parts = {'MAJOR': int(chrome_major), 'MINOR': 0, 'PATCH': 0}
self._version_string = '%s.0.0-%s.%s+%s+%s' % \
(chrome_major, cef_branch_name, cef_commit['NUMBER'],
cef_commit_hash, chrome_version_part)
else:
cef_branch = self.get_cef_branch_version_components()
self._version_parts = {
'MAJOR': int(chrome_major),
'MINOR': cef_branch['MINOR'],
'PATCH': cef_branch['PATCH']
}
self._version_string = '%s.%d.%d+%s+%s' % \
(chrome_major, cef_branch['MINOR'], cef_branch['PATCH'],
cef_commit_hash, chrome_version_part)
def _get_version_string(self):
self._compute_version()
return self._version_string
def _get_version_parts(self):
self._compute_version()
return self._version_parts
def get_version_string(self, oldFormat=None):
""" Returns the CEF version number string based on current checkout state.
"""
if oldFormat is None:
oldFormat = self._old_format_default
if oldFormat:
return self._get_old_version_string()
return self._get_version_string()
def get_version_parts(self, oldFormat=None):
""" Returns the CEF version number parts based on current checkout state.
"""
if oldFormat is None:
oldFormat = self._old_format_default
if oldFormat:
return self._get_old_version_parts()
return self._get_version_parts()
def get_plist_version_string(self, oldFormat=None):
""" Returns the CEF version number string for plist files based on current
checkout state. """
parts = self.get_version_parts(oldFormat=oldFormat)
return "%d.%d.%d.0" % (parts['MAJOR'], parts['MINOR'], parts['PATCH'])
def get_dylib_version_string(self, oldFormat=None):
""" Returns the CEF version number string for dylib files based on current
checkout state. """
parts = self.get_version_parts(oldFormat=oldFormat)
# Dylib format supports a max value of 255 for the 2nd and 3rd components.
return "%d%d.%d.%d" % (parts['MAJOR'], parts['MINOR'], parts['PATCH'] / 255,
parts['PATCH'] % 255)
# Test the module.
if __name__ == "__main__":
import sys
# Optionally specify a format.
formats = ['current', 'old', 'plist', 'dylib']
if len(sys.argv) >= 2:
formats = [sys.argv[1]]
# Optionally specify the path to chromium/src.
chromium_src_path = None
if len(sys.argv) >= 3:
chromium_src_path = sys.argv[2]
formatter = VersionFormatter(chromium_src_path)
for format in formats:
if len(formats) > 1:
print(format)
if format == 'old':
print(formatter.get_version_string(True))
elif format == 'dylib':
print(formatter.get_dylib_version_string())
elif format == 'plist':
print(formatter.get_plist_version_string())
else:
print(formatter.get_version_string(False))