Commit 2765df34 authored by John Chen's avatar John Chen Committed by Commit Bot

[ChromeDriver] Use Chrome version in release branches

ChromeDriver built in Chrome release branches now embeds Chrome version
number (e.g., 69.0.3497.23) instead of ChromeDriver version (e.g., 2.41).

Bug: chromedriver:2080
Change-Id: I8727b0c42ad3d59a0833345a596a4bdbce83b282
Reviewed-on: https://chromium-review.googlesource.com/1166229
Commit-Queue: John Chen <johnchen@chromium.org>
Reviewed-by: default avatarCaleb Rouleau <crouleau@chromium.org>
Reviewed-by: default avatarJonathon Kereliuk <kereliuk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581945}
parent 6a14eff6
...@@ -198,6 +198,7 @@ action("embed_version_in_cpp") { ...@@ -198,6 +198,7 @@ action("embed_version_in_cpp") {
inputs = [ inputs = [
"cpp_source.py", "cpp_source.py",
"VERSION", "VERSION",
"//chrome/VERSION",
# We don't actually use LASTCHANGE as an input file. It is updated # We don't actually use LASTCHANGE as an input file. It is updated
# whenever a different Git revision is checked out, at which point # whenever a different Git revision is checked out, at which point
...@@ -210,8 +211,10 @@ action("embed_version_in_cpp") { ...@@ -210,8 +211,10 @@ action("embed_version_in_cpp") {
] ]
args = [ args = [
"--version-file", "--chromedriver-version-file",
rebase_path("VERSION", root_build_dir), rebase_path("VERSION", root_build_dir),
"--chrome-version-file",
rebase_path("//chrome/VERSION", root_build_dir),
"--directory", "--directory",
rebase_path(target_gen_dir, root_build_dir), rebase_path(target_gen_dir, root_build_dir),
] ]
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""Embeds Chrome user data files in C++ code.""" """Embeds version string in C++ code for ChromeDriver."""
import optparse import optparse
import os import os
...@@ -17,27 +17,91 @@ sys.path.insert(0, os.path.join(chrome_paths.GetSrc(), 'build', 'util')) ...@@ -17,27 +17,91 @@ sys.path.insert(0, os.path.join(chrome_paths.GetSrc(), 'build', 'util'))
import lastchange import lastchange
def get_release_version(chrome_version_file, version_info):
"""Return version string appropriate for a release branch.
Args:
chrome_version_file: name of Chrome's version file, e.g., chrome/VERSION.
version_info: VersionInfo object returned from lastchange.FetchVersionInfo.
"""
# Release branch revision has the format
# '26c10db8bff36a8b6fc073c0f38b1e9493cabb04-refs/branch-heads/3515@{#5}'.
match = re.match('[0-9a-fA-F]+-refs/branch-heads/\d+@{#\d+}',
version_info.revision)
if not match:
# revision is not the expected format, probably not in a release branch.
return None
# Parse Chrome version file, which should have four lines of key=value,
# giving the major, minor, build, and patch number.
values = {}
for line in open(chrome_version_file, 'r').readlines():
key, val = line.rstrip('\r\n').split('=', 1)
values[key] = val
# Result is based on Chrome version number, e.g.,
# '70.0.3516.0 (26c10db8bff36a8b6fc073c0f38b1e9493cabb04)'.
return '%s.%s.%s.%s (%s)' % (
values['MAJOR'], values['MINOR'], values['BUILD'], values['PATCH'],
version_info.revision_id)
def get_master_version(chromedriver_version, version_info):
"""Return version string appropriate for the master branch.
Args:
chromedriver_version: ChromeDriver version, e.g., '2.41'.
version_info: VersionInfo object returned from lastchange.FetchVersionInfo.
"""
# Master branch revision has the format
# 'cc009559c91323445dec7e2f545298bf10726eaf-refs/heads/master@{#581331}'.
# We need to grab the commit position (e.g., '581331') near the end.
match = re.match('[0-9a-fA-F]+-refs/heads/master@{#(\d+)}',
version_info.revision)
if not match:
# revision is not the expected format, probably not in the master branch.
return None
# result is based on legacy style ChromeDriver version number, e.g.,
# '2.41.581331 (cc009559c91323445dec7e2f545298bf10726eaf)'.
commit_position = match.group(1)
return '%s.%s (%s)' % (
chromedriver_version, commit_position, version_info.revision_id)
def main(): def main():
parser = optparse.OptionParser() parser = optparse.OptionParser()
parser.add_option('', '--version-file') parser.add_option('', '--chromedriver-version-file')
parser.add_option('', '--chrome-version-file')
parser.add_option( parser.add_option(
'', '--directory', type='string', default='.', '', '--directory', type='string', default='.',
help='Path to directory where the cc/h file should be created') help='Path to directory where the cc/h file should be created')
options, _ = parser.parse_args() options, _ = parser.parse_args()
version = open(options.version_file, 'r').read().strip() chromedriver_version = open(
revision = lastchange.FetchVersionInfo(None).revision options.chromedriver_version_file, 'r').read().strip()
if revision: # Get a VersionInfo object corresponding to the Git commit we are at.
match = re.match('([0-9a-fA-F]+)(-refs/heads/master@{#(\d+)})?', revision) # On success, version_info.revision_id is a 40-digit Git hash,
if match: # and version_info.revision is a longer string with more information.
git_hash = match.group(1) # On failure, version_info is None.
commit_position = match.group(3) version_info = lastchange.FetchGitRevision(None, None)
if commit_position:
version += '.' + commit_position if version_info:
version += ' (%s)' % git_hash version = get_release_version(options.chrome_version_file, version_info)
else:
version += ' (%s)' % revision if not version:
version = get_master_version(chromedriver_version, version_info)
if not version:
# Not in a known branch, but has Git revision.
version = '%s (%s)' % (chromedriver_version, version_info.revision_id)
else:
# Git command failed for some reason. Just use ChromeDriver version string.
version = chromedriver_version
global_string_map = { global_string_map = {
'kChromeDriverVersion': version 'kChromeDriverVersion': version
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment