Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | # |
| 4 | # Use of this source code is governed by a BSD-style license |
| 5 | # that can be found in the LICENSE file in the root of the source |
| 6 | # tree. An additional intellectual property rights grant can be found |
| 7 | # in the file PATENTS. All contributing project authors may |
| 8 | # be found in the AUTHORS file in the root of the source tree. |
| 9 | |
Henrik Kjellander | 24db179 | 2016-12-15 10:20:10 +0100 | [diff] [blame] | 10 | """Script to automatically roll dependencies in the WebRTC DEPS file.""" |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 11 | |
| 12 | import argparse |
| 13 | import base64 |
| 14 | import collections |
| 15 | import logging |
| 16 | import os |
| 17 | import re |
| 18 | import subprocess |
| 19 | import sys |
Oleh Prypin | 7f6af7a | 2017-11-01 21:59:32 +0100 | [diff] [blame] | 20 | import urllib2 |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 21 | |
Mirko Bonadei | d866544 | 2018-09-04 12:17:27 +0200 | [diff] [blame] | 22 | def FindSrcDirPath(): |
| 23 | """Returns the abs path to the src/ dir of the project.""" |
| 24 | src_dir = os.path.dirname(os.path.abspath(__file__)) |
| 25 | while os.path.basename(src_dir) != 'src': |
| 26 | src_dir = os.path.normpath(os.path.join(src_dir, os.pardir)) |
| 27 | return src_dir |
| 28 | |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 29 | # Skip these dependencies (list without solution name prefix). |
| 30 | DONT_AUTOROLL_THESE = [ |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | 'src/examples/androidtests/third_party/gradle', |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 32 | ] |
| 33 | |
Yves Gerey | 1548e9a | 2018-09-19 13:52:04 +0200 | [diff] [blame] | 34 | # These dependencies are missing in chromium/src/DEPS, either unused or already |
| 35 | # in-tree. For instance, src/base is a part of the Chromium source git repo, |
| 36 | # but we pull it through a subtree mirror, so therefore it isn't listed in |
| 37 | # Chromium's deps but it is in ours. |
| 38 | WEBRTC_ONLY_DEPS = [ |
| 39 | 'src/base', |
| 40 | 'src/build', |
Oleh Prypin | dcba72b | 2019-02-08 10:39:45 +0100 | [diff] [blame] | 41 | 'src/buildtools', |
Yves Gerey | 26a6b58 | 2018-09-19 15:47:28 +0200 | [diff] [blame] | 42 | 'src/ios', |
Yves Gerey | 1548e9a | 2018-09-19 13:52:04 +0200 | [diff] [blame] | 43 | 'src/testing', |
| 44 | 'src/third_party', |
| 45 | 'src/third_party/findbugs', |
| 46 | 'src/third_party/gtest-parallel', |
Yves Gerey | 1548e9a | 2018-09-19 13:52:04 +0200 | [diff] [blame] | 47 | 'src/third_party/yasm/binaries', |
| 48 | 'src/tools', |
| 49 | ] |
| 50 | |
| 51 | |
Aaron Gable | 2db9c28 | 2017-09-13 11:59:45 -0700 | [diff] [blame] | 52 | WEBRTC_URL = 'https://webrtc.googlesource.com/src' |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 53 | CHROMIUM_SRC_URL = 'https://chromium.googlesource.com/chromium/src' |
| 54 | CHROMIUM_COMMIT_TEMPLATE = CHROMIUM_SRC_URL + '/+/%s' |
Henrik Kjellander | a9c584d | 2015-10-02 09:11:57 +0200 | [diff] [blame] | 55 | CHROMIUM_LOG_TEMPLATE = CHROMIUM_SRC_URL + '/+log/%s' |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 56 | CHROMIUM_FILE_TEMPLATE = CHROMIUM_SRC_URL + '/+/%s/%s' |
| 57 | |
| 58 | COMMIT_POSITION_RE = re.compile('^Cr-Commit-Position: .*#([0-9]+).*$') |
Artem Titov | 2988aca | 2019-05-23 18:31:59 +0200 | [diff] [blame] | 59 | CLANG_REVISION_RE = re.compile(r'^CLANG_REVISION = \'([0-9a-z]+)\'$') |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 60 | ROLL_BRANCH_NAME = 'roll_chromium_revision' |
| 61 | |
| 62 | SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
Mirko Bonadei | d866544 | 2018-09-04 12:17:27 +0200 | [diff] [blame] | 63 | CHECKOUT_SRC_DIR = FindSrcDirPath() |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 64 | CHECKOUT_ROOT_DIR = os.path.realpath(os.path.join(CHECKOUT_SRC_DIR, os.pardir)) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 65 | |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 66 | # Copied from tools/android/roll/android_deps/.../BuildConfigGenerator.groovy. |
| 67 | ANDROID_DEPS_START = r'=== ANDROID_DEPS Generated Code Start ===' |
| 68 | ANDROID_DEPS_END = r'=== ANDROID_DEPS Generated Code End ===' |
| 69 | # Location of automically gathered android deps. |
| 70 | ANDROID_DEPS_PATH = 'src/third_party/android_deps/' |
| 71 | |
Oleh Prypin | e6708f3 | 2018-10-08 14:01:59 +0200 | [diff] [blame] | 72 | NOTIFY_EMAIL = 'webrtc-trooper@grotations.appspotmail.com' |
| 73 | |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 74 | |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 75 | sys.path.append(os.path.join(CHECKOUT_SRC_DIR, 'build')) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 76 | import find_depot_tools |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 77 | |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 78 | find_depot_tools.add_depot_tools_to_path() |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 79 | |
kjellander | 917ba52 | 2015-12-03 00:00:07 -0800 | [diff] [blame] | 80 | CLANG_UPDATE_SCRIPT_URL_PATH = 'tools/clang/scripts/update.py' |
kjellander@webrtc.org | 177567c | 2016-12-22 10:40:28 +0100 | [diff] [blame] | 81 | CLANG_UPDATE_SCRIPT_LOCAL_PATH = os.path.join(CHECKOUT_SRC_DIR, 'tools', |
| 82 | 'clang', 'scripts', 'update.py') |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 83 | |
| 84 | DepsEntry = collections.namedtuple('DepsEntry', 'path url revision') |
Oleh Prypin | 4775b27 | 2018-04-26 22:33:26 +0200 | [diff] [blame] | 85 | ChangedDep = collections.namedtuple( |
| 86 | 'ChangedDep', 'path url current_rev new_rev') |
| 87 | CipdDepsEntry = collections.namedtuple('CipdDepsEntry', 'path packages') |
| 88 | ChangedCipdPackage = collections.namedtuple( |
| 89 | 'ChangedCipdPackage', 'path package current_version new_version') |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 90 | |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 91 | ChromiumRevisionUpdate = collections.namedtuple('ChromiumRevisionUpdate', |
| 92 | ('current_chromium_rev ' |
Artem Titov | 42f0d78 | 2018-06-27 13:23:17 +0200 | [diff] [blame] | 93 | 'new_chromium_rev ')) |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 94 | |
| 95 | |
kjellander | 3860c7f | 2016-01-19 02:04:41 -0800 | [diff] [blame] | 96 | class RollError(Exception): |
| 97 | pass |
| 98 | |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 99 | |
oprypin | 1e64cfa | 2017-07-25 01:57:17 -0700 | [diff] [blame] | 100 | def VarLookup(local_scope): |
| 101 | return lambda var_name: local_scope['vars'][var_name] |
| 102 | |
| 103 | |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 104 | def ParseDepsDict(deps_content): |
| 105 | local_scope = {} |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 106 | global_scope = { |
oprypin | 1e64cfa | 2017-07-25 01:57:17 -0700 | [diff] [blame] | 107 | 'Var': VarLookup(local_scope), |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 108 | 'deps_os': {}, |
| 109 | } |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 110 | exec (deps_content, global_scope, local_scope) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 111 | return local_scope |
| 112 | |
| 113 | |
| 114 | def ParseLocalDepsFile(filename): |
| 115 | with open(filename, 'rb') as f: |
| 116 | deps_content = f.read() |
| 117 | return ParseDepsDict(deps_content) |
| 118 | |
| 119 | |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 120 | def ParseCommitPosition(commit_message): |
| 121 | for line in reversed(commit_message.splitlines()): |
| 122 | m = COMMIT_POSITION_RE.match(line.strip()) |
| 123 | if m: |
Oleh Prypin | 16b2a36 | 2017-12-27 21:03:55 +0100 | [diff] [blame] | 124 | return int(m.group(1)) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 125 | logging.error('Failed to parse commit position id from:\n%s\n', |
| 126 | commit_message) |
| 127 | sys.exit(-1) |
| 128 | |
| 129 | |
| 130 | def _RunCommand(command, working_dir=None, ignore_exit_code=False, |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 131 | extra_env=None, input_data=None): |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 132 | """Runs a command and returns the output from that command. |
| 133 | |
| 134 | If the command fails (exit code != 0), the function will exit the process. |
| 135 | |
| 136 | Returns: |
| 137 | A tuple containing the stdout and stderr outputs as strings. |
| 138 | """ |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 139 | working_dir = working_dir or CHECKOUT_SRC_DIR |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 140 | logging.debug('CMD: %s CWD: %s', ' '.join(command), working_dir) |
| 141 | env = os.environ.copy() |
| 142 | if extra_env: |
Artem Titov | 81f5197 | 2018-06-27 10:31:23 +0200 | [diff] [blame] | 143 | assert all(isinstance(value, str) for value in extra_env.values()) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 144 | logging.debug('extra env: %s', extra_env) |
| 145 | env.update(extra_env) |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 146 | p = subprocess.Popen(command, |
| 147 | stdin=subprocess.PIPE, |
| 148 | stdout=subprocess.PIPE, |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 149 | stderr=subprocess.PIPE, env=env, |
| 150 | cwd=working_dir, universal_newlines=True) |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 151 | std_output, err_output = p.communicate(input_data) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 152 | p.stdout.close() |
| 153 | p.stderr.close() |
| 154 | if not ignore_exit_code and p.returncode != 0: |
| 155 | logging.error('Command failed: %s\n' |
| 156 | 'stdout:\n%s\n' |
| 157 | 'stderr:\n%s\n', ' '.join(command), std_output, err_output) |
| 158 | sys.exit(p.returncode) |
| 159 | return std_output, err_output |
| 160 | |
| 161 | |
| 162 | def _GetBranches(): |
| 163 | """Returns a tuple of active,branches. |
| 164 | |
| 165 | The 'active' is the name of the currently active branch and 'branches' is a |
| 166 | list of all branches. |
| 167 | """ |
| 168 | lines = _RunCommand(['git', 'branch'])[0].split('\n') |
| 169 | branches = [] |
| 170 | active = '' |
| 171 | for line in lines: |
| 172 | if '*' in line: |
| 173 | # The assumption is that the first char will always be the '*'. |
| 174 | active = line[1:].strip() |
| 175 | branches.append(active) |
| 176 | else: |
| 177 | branch = line.strip() |
| 178 | if branch: |
| 179 | branches.append(branch) |
| 180 | return active, branches |
| 181 | |
| 182 | |
| 183 | def _ReadGitilesContent(url): |
| 184 | # Download and decode BASE64 content until |
| 185 | # https://code.google.com/p/gitiles/issues/detail?id=7 is fixed. |
| 186 | base64_content = ReadUrlContent(url + '?format=TEXT') |
| 187 | return base64.b64decode(base64_content[0]) |
| 188 | |
| 189 | |
| 190 | def ReadRemoteCrFile(path_below_src, revision): |
| 191 | """Reads a remote Chromium file of a specific revision. Returns a string.""" |
| 192 | return _ReadGitilesContent(CHROMIUM_FILE_TEMPLATE % (revision, |
| 193 | path_below_src)) |
| 194 | |
| 195 | |
| 196 | def ReadRemoteCrCommit(revision): |
| 197 | """Reads a remote Chromium commit message. Returns a string.""" |
| 198 | return _ReadGitilesContent(CHROMIUM_COMMIT_TEMPLATE % revision) |
| 199 | |
| 200 | |
| 201 | def ReadUrlContent(url): |
| 202 | """Connect to a remote host and read the contents. Returns a list of lines.""" |
Oleh Prypin | 7f6af7a | 2017-11-01 21:59:32 +0100 | [diff] [blame] | 203 | conn = urllib2.urlopen(url) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 204 | try: |
| 205 | return conn.readlines() |
| 206 | except IOError as e: |
| 207 | logging.exception('Error connecting to %s. Error: %s', url, e) |
| 208 | raise |
| 209 | finally: |
| 210 | conn.close() |
| 211 | |
| 212 | |
| 213 | def GetMatchingDepsEntries(depsentry_dict, dir_path): |
| 214 | """Gets all deps entries matching the provided path. |
| 215 | |
| 216 | This list may contain more than one DepsEntry object. |
| 217 | Example: dir_path='src/testing' would give results containing both |
| 218 | 'src/testing/gtest' and 'src/testing/gmock' deps entries for Chromium's DEPS. |
| 219 | Example 2: dir_path='src/build' should return 'src/build' but not |
| 220 | 'src/buildtools'. |
| 221 | |
| 222 | Returns: |
| 223 | A list of DepsEntry objects. |
| 224 | """ |
| 225 | result = [] |
| 226 | for path, depsentry in depsentry_dict.iteritems(): |
| 227 | if path == dir_path: |
| 228 | result.append(depsentry) |
| 229 | else: |
Henrik Kjellander | 14771ac | 2015-06-02 13:10:04 +0200 | [diff] [blame] | 230 | parts = path.split('/') |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 231 | if all(part == parts[i] |
Henrik Kjellander | 14771ac | 2015-06-02 13:10:04 +0200 | [diff] [blame] | 232 | for i, part in enumerate(dir_path.split('/'))): |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 233 | result.append(depsentry) |
| 234 | return result |
| 235 | |
| 236 | |
| 237 | def BuildDepsentryDict(deps_dict): |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 238 | """Builds a dict of paths to DepsEntry objects from a raw parsed deps dict.""" |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 239 | result = {} |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 240 | |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 241 | def AddDepsEntries(deps_subdict): |
Oleh Prypin | 6e9c00f | 2018-02-19 16:24:19 +0100 | [diff] [blame] | 242 | for path, dep in deps_subdict.iteritems(): |
Oleh Prypin | 4775b27 | 2018-04-26 22:33:26 +0200 | [diff] [blame] | 243 | if path in result: |
| 244 | continue |
| 245 | if not isinstance(dep, dict): |
| 246 | dep = {'url': dep} |
| 247 | if dep.get('dep_type') == 'cipd': |
| 248 | result[path] = CipdDepsEntry(path, dep['packages']) |
Oleh Prypin | 6e9c00f | 2018-02-19 16:24:19 +0100 | [diff] [blame] | 249 | else: |
Oleh Prypin | 4092d6f | 2019-02-06 10:06:12 +0100 | [diff] [blame] | 250 | if '@' not in dep['url']: |
| 251 | continue |
Oleh Prypin | 4775b27 | 2018-04-26 22:33:26 +0200 | [diff] [blame] | 252 | url, revision = dep['url'].split('@') |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 253 | result[path] = DepsEntry(path, url, revision) |
| 254 | |
| 255 | AddDepsEntries(deps_dict['deps']) |
| 256 | for deps_os in ['win', 'mac', 'unix', 'android', 'ios', 'unix']: |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 257 | AddDepsEntries(deps_dict.get('deps_os', {}).get(deps_os, {})) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 258 | return result |
| 259 | |
| 260 | |
Oleh Prypin | 4775b27 | 2018-04-26 22:33:26 +0200 | [diff] [blame] | 261 | def _FindChangedCipdPackages(path, old_pkgs, new_pkgs): |
Artem Titov | 41f00de | 2018-11-01 16:35:16 +0100 | [diff] [blame] | 262 | pkgs_equal = ({p['package'] for p in old_pkgs} == |
| 263 | {p['package'] for p in new_pkgs}) |
| 264 | assert pkgs_equal, 'Old: %s\n New: %s' % (old_pkgs, new_pkgs) |
Oleh Prypin | 4775b27 | 2018-04-26 22:33:26 +0200 | [diff] [blame] | 265 | for old_pkg in old_pkgs: |
| 266 | for new_pkg in new_pkgs: |
Oleh Prypin | a8eb1e6 | 2018-07-03 08:47:28 +0200 | [diff] [blame] | 267 | old_version = old_pkg['version'] |
| 268 | new_version = new_pkg['version'] |
Oleh Prypin | 4775b27 | 2018-04-26 22:33:26 +0200 | [diff] [blame] | 269 | if (old_pkg['package'] == new_pkg['package'] and |
| 270 | old_version != new_version): |
| 271 | logging.debug('Roll dependency %s to %s', path, new_version) |
| 272 | yield ChangedCipdPackage(path, old_pkg['package'], |
| 273 | old_version, new_version) |
| 274 | |
| 275 | |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 276 | def _FindNewDeps(old, new): |
| 277 | """ Gather dependencies only in |new| and return corresponding paths. """ |
| 278 | old_entries = set(BuildDepsentryDict(old)) |
| 279 | new_entries = set(BuildDepsentryDict(new)) |
| 280 | return [path for path in new_entries - old_entries |
| 281 | if path not in DONT_AUTOROLL_THESE] |
| 282 | |
| 283 | |
| 284 | def FindAddedDeps(webrtc_deps, new_cr_deps): |
| 285 | """ |
| 286 | Calculate new deps entries of interest. |
| 287 | |
| 288 | Ideally, that would mean: only appearing in chromium DEPS |
| 289 | but transitively used in WebRTC. |
| 290 | |
| 291 | Since it's hard to compute, we restrict ourselves to a well defined subset: |
| 292 | deps sitting in |ANDROID_DEPS_PATH|. |
| 293 | Otherwise, assumes that's a Chromium-only dependency. |
| 294 | |
| 295 | Args: |
| 296 | webrtc_deps: dict of deps as defined in the WebRTC DEPS file. |
| 297 | new_cr_deps: dict of deps as defined in the chromium DEPS file. |
| 298 | |
| 299 | Caveat: Doesn't detect a new package in existing dep. |
| 300 | |
| 301 | Returns: |
| 302 | A tuple consisting of: |
| 303 | A list of paths added dependencies sitting in |ANDROID_DEPS_PATH|. |
| 304 | A list of paths for other added dependencies. |
| 305 | """ |
| 306 | all_added_deps = _FindNewDeps(webrtc_deps, new_cr_deps) |
| 307 | generated_android_deps = [path for path in all_added_deps |
| 308 | if path.startswith(ANDROID_DEPS_PATH)] |
| 309 | other_deps = [path for path in all_added_deps |
| 310 | if path not in generated_android_deps] |
| 311 | return generated_android_deps, other_deps |
| 312 | |
| 313 | |
| 314 | def FindRemovedDeps(webrtc_deps, new_cr_deps): |
| 315 | """ |
| 316 | Calculate obsolete deps entries. |
| 317 | |
| 318 | Ideally, that would mean: no more appearing in chromium DEPS |
| 319 | and not used in WebRTC. |
| 320 | |
| 321 | Since it's hard to compute: |
| 322 | 1/ We restrict ourselves to a well defined subset: |
| 323 | deps sitting in |ANDROID_DEPS_PATH|. |
| 324 | 2/ We rely on existing behavior of CalculateChangeDeps. |
| 325 | I.e. Assumes non-CIPD dependencies are WebRTC-only, don't remove them. |
| 326 | |
| 327 | Args: |
| 328 | webrtc_deps: dict of deps as defined in the WebRTC DEPS file. |
| 329 | new_cr_deps: dict of deps as defined in the chromium DEPS file. |
| 330 | |
| 331 | Caveat: Doesn't detect a deleted package in existing dep. |
| 332 | |
| 333 | Returns: |
| 334 | A tuple consisting of: |
| 335 | A list of paths of dependencies removed from |ANDROID_DEPS_PATH|. |
| 336 | A list of paths of unexpected disappearing dependencies. |
| 337 | """ |
| 338 | all_removed_deps = _FindNewDeps(new_cr_deps, webrtc_deps) |
| 339 | generated_android_deps = [path for path in all_removed_deps |
| 340 | if path.startswith(ANDROID_DEPS_PATH)] |
Yves Gerey | 1548e9a | 2018-09-19 13:52:04 +0200 | [diff] [blame] | 341 | # Webrtc-only dependencies are handled in CalculateChangedDeps. |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 342 | other_deps = [path for path in all_removed_deps |
| 343 | if path not in generated_android_deps and |
Yves Gerey | 1548e9a | 2018-09-19 13:52:04 +0200 | [diff] [blame] | 344 | path not in WEBRTC_ONLY_DEPS] |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 345 | return generated_android_deps, other_deps |
| 346 | |
| 347 | |
kjellander@webrtc.org | 177567c | 2016-12-22 10:40:28 +0100 | [diff] [blame] | 348 | def CalculateChangedDeps(webrtc_deps, new_cr_deps): |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 349 | """ |
kjellander@webrtc.org | 177567c | 2016-12-22 10:40:28 +0100 | [diff] [blame] | 350 | Calculate changed deps entries based on entries defined in the WebRTC DEPS |
| 351 | file: |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 352 | - If a shared dependency with the Chromium DEPS file: roll it to the same |
| 353 | revision as Chromium (i.e. entry in the new_cr_deps dict) |
| 354 | - If it's a Chromium sub-directory, roll it to the HEAD revision (notice |
| 355 | this means it may be ahead of the chromium_revision, but generally these |
| 356 | should be close). |
| 357 | - If it's another DEPS entry (not shared with Chromium), roll it to HEAD |
| 358 | unless it's configured to be skipped. |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 359 | |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 360 | Returns: |
| 361 | A list of ChangedDep objects representing the changed deps. |
| 362 | """ |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 363 | result = [] |
| 364 | webrtc_entries = BuildDepsentryDict(webrtc_deps) |
| 365 | new_cr_entries = BuildDepsentryDict(new_cr_deps) |
| 366 | for path, webrtc_deps_entry in webrtc_entries.iteritems(): |
| 367 | if path in DONT_AUTOROLL_THESE: |
| 368 | continue |
| 369 | cr_deps_entry = new_cr_entries.get(path) |
| 370 | if cr_deps_entry: |
Oleh Prypin | 4775b27 | 2018-04-26 22:33:26 +0200 | [diff] [blame] | 371 | assert type(cr_deps_entry) is type(webrtc_deps_entry) |
| 372 | |
| 373 | if isinstance(cr_deps_entry, CipdDepsEntry): |
| 374 | result.extend(_FindChangedCipdPackages(path, webrtc_deps_entry.packages, |
| 375 | cr_deps_entry.packages)) |
| 376 | continue |
| 377 | |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 378 | # Use the revision from Chromium's DEPS file. |
| 379 | new_rev = cr_deps_entry.revision |
| 380 | assert webrtc_deps_entry.url == cr_deps_entry.url, ( |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 381 | 'WebRTC DEPS entry %s has a different URL (%s) than Chromium (%s).' % |
| 382 | (path, webrtc_deps_entry.url, cr_deps_entry.url)) |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 383 | else: |
Yves Gerey | 3606cab8 | 2018-09-19 19:20:19 +0200 | [diff] [blame] | 384 | if isinstance(webrtc_deps_entry, DepsEntry): |
Oleh Prypin | a8eb1e6 | 2018-07-03 08:47:28 +0200 | [diff] [blame] | 385 | # Use the HEAD of the deps repo. |
| 386 | stdout, _ = _RunCommand(['git', 'ls-remote', webrtc_deps_entry.url, |
| 387 | 'HEAD']) |
| 388 | new_rev = stdout.strip().split('\t')[0] |
| 389 | else: |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 390 | # The dependency has been removed from chromium. |
| 391 | # This is handled by FindRemovedDeps. |
| 392 | continue |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 393 | |
| 394 | # Check if an update is necessary. |
| 395 | if webrtc_deps_entry.revision != new_rev: |
| 396 | logging.debug('Roll dependency %s to %s', path, new_rev) |
| 397 | result.append(ChangedDep(path, webrtc_deps_entry.url, |
| 398 | webrtc_deps_entry.revision, new_rev)) |
kjellander@webrtc.org | 177567c | 2016-12-22 10:40:28 +0100 | [diff] [blame] | 399 | return sorted(result) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 400 | |
| 401 | |
| 402 | def CalculateChangedClang(new_cr_rev): |
| 403 | def GetClangRev(lines): |
| 404 | for line in lines: |
| 405 | match = CLANG_REVISION_RE.match(line) |
| 406 | if match: |
| 407 | return match.group(1) |
kjellander | 3860c7f | 2016-01-19 02:04:41 -0800 | [diff] [blame] | 408 | raise RollError('Could not parse Clang revision!') |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 409 | |
kjellander@webrtc.org | 177567c | 2016-12-22 10:40:28 +0100 | [diff] [blame] | 410 | with open(CLANG_UPDATE_SCRIPT_LOCAL_PATH, 'rb') as f: |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 411 | current_lines = f.readlines() |
| 412 | current_rev = GetClangRev(current_lines) |
| 413 | |
kjellander | 3860c7f | 2016-01-19 02:04:41 -0800 | [diff] [blame] | 414 | new_clang_update_py = ReadRemoteCrFile(CLANG_UPDATE_SCRIPT_URL_PATH, |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 415 | new_cr_rev).splitlines() |
kjellander | 3860c7f | 2016-01-19 02:04:41 -0800 | [diff] [blame] | 416 | new_rev = GetClangRev(new_clang_update_py) |
Henrik Kjellander | a9c584d | 2015-10-02 09:11:57 +0200 | [diff] [blame] | 417 | return ChangedDep(CLANG_UPDATE_SCRIPT_LOCAL_PATH, None, current_rev, new_rev) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 418 | |
| 419 | |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 420 | def GenerateCommitMessage(rev_update, current_commit_pos, new_commit_pos, |
Yves Gerey | 31eb01f | 2018-09-19 17:25:20 +0200 | [diff] [blame] | 421 | changed_deps_list, |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 422 | added_deps_paths=None, |
Yves Gerey | 31eb01f | 2018-09-19 17:25:20 +0200 | [diff] [blame] | 423 | removed_deps_paths=None, |
| 424 | clang_change=None, |
| 425 | ): |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 426 | current_cr_rev = rev_update.current_chromium_rev[0:10] |
| 427 | new_cr_rev = rev_update.new_chromium_rev[0:10] |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 428 | rev_interval = '%s..%s' % (current_cr_rev, new_cr_rev) |
Henrik Kjellander | a9c584d | 2015-10-02 09:11:57 +0200 | [diff] [blame] | 429 | git_number_interval = '%s:%s' % (current_commit_pos, new_commit_pos) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 430 | |
Henrik Kjellander | a9c584d | 2015-10-02 09:11:57 +0200 | [diff] [blame] | 431 | commit_msg = ['Roll chromium_revision %s (%s)\n' % (rev_interval, |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 432 | git_number_interval), |
| 433 | 'Change log: %s' % (CHROMIUM_LOG_TEMPLATE % rev_interval), |
| 434 | 'Full diff: %s\n' % (CHROMIUM_COMMIT_TEMPLATE % |
Artem Titov | 42f0d78 | 2018-06-27 13:23:17 +0200 | [diff] [blame] | 435 | rev_interval)] |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 436 | |
| 437 | def Section(adjective, deps): |
| 438 | noun = 'dependency' if len(deps) == 1 else 'dependencies' |
| 439 | commit_msg.append('%s %s' % (adjective, noun)) |
| 440 | |
Henrik Kjellander | 6c2ba7d | 2015-10-02 09:03:06 +0200 | [diff] [blame] | 441 | tbr_authors = '' |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 442 | if changed_deps_list: |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 443 | Section('Changed', changed_deps_list) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 444 | |
| 445 | for c in changed_deps_list: |
Oleh Prypin | 4775b27 | 2018-04-26 22:33:26 +0200 | [diff] [blame] | 446 | if isinstance(c, ChangedCipdPackage): |
| 447 | commit_msg.append('* %s: %s..%s' % (c.path, c.current_version, |
| 448 | c.new_version)) |
| 449 | else: |
| 450 | commit_msg.append('* %s: %s/+log/%s..%s' % (c.path, c.url, |
| 451 | c.current_rev[0:10], |
| 452 | c.new_rev[0:10])) |
Henrik Kjellander | 6c2ba7d | 2015-10-02 09:03:06 +0200 | [diff] [blame] | 453 | if 'libvpx' in c.path: |
Jerome Jiang | 397b5b5 | 2019-03-29 13:38:39 -0700 | [diff] [blame] | 454 | tbr_authors += 'marpan@webrtc.org, jianj@chromium.org, ' |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 455 | |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 456 | if added_deps_paths: |
| 457 | Section('Added', added_deps_paths) |
| 458 | commit_msg.extend('* %s' % p for p in added_deps_paths) |
| 459 | |
| 460 | if removed_deps_paths: |
| 461 | Section('Removed', removed_deps_paths) |
| 462 | commit_msg.extend('* %s' % p for p in removed_deps_paths) |
| 463 | |
| 464 | if any([changed_deps_list, |
| 465 | added_deps_paths, |
| 466 | removed_deps_paths]): |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 467 | change_url = CHROMIUM_FILE_TEMPLATE % (rev_interval, 'DEPS') |
Henrik Kjellander | a9c584d | 2015-10-02 09:11:57 +0200 | [diff] [blame] | 468 | commit_msg.append('DEPS diff: %s\n' % change_url) |
| 469 | else: |
| 470 | commit_msg.append('No dependencies changed.') |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 471 | |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 472 | if clang_change and clang_change.current_rev != clang_change.new_rev: |
Henrik Kjellander | a9c584d | 2015-10-02 09:11:57 +0200 | [diff] [blame] | 473 | commit_msg.append('Clang version changed %s:%s' % |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 474 | (clang_change.current_rev, clang_change.new_rev)) |
| 475 | change_url = CHROMIUM_FILE_TEMPLATE % (rev_interval, |
| 476 | CLANG_UPDATE_SCRIPT_URL_PATH) |
Henrik Kjellander | 417fec2 | 2015-10-02 13:39:52 +0200 | [diff] [blame] | 477 | commit_msg.append('Details: %s\n' % change_url) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 478 | else: |
Henrik Kjellander | 417fec2 | 2015-10-02 13:39:52 +0200 | [diff] [blame] | 479 | commit_msg.append('No update to Clang.\n') |
Henrik Kjellander | a9c584d | 2015-10-02 09:11:57 +0200 | [diff] [blame] | 480 | |
Edward Lemur | 033a1bf | 2017-09-14 14:50:54 +0200 | [diff] [blame] | 481 | # TBR needs to be non-empty for Gerrit to process it. |
Edward Lemur | 6ef2002 | 2017-09-14 20:46:01 +0200 | [diff] [blame] | 482 | git_author = _RunCommand(['git', 'config', 'user.email'], |
| 483 | working_dir=CHECKOUT_SRC_DIR)[0].splitlines()[0] |
| 484 | tbr_authors = git_author + ',' + tbr_authors |
| 485 | |
Oleh Prypin | dca5a2c | 2018-09-28 15:18:29 +0200 | [diff] [blame] | 486 | commit_msg.append('TBR=%s' % tbr_authors) |
| 487 | commit_msg.append('BUG=None') |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 488 | return '\n'.join(commit_msg) |
| 489 | |
| 490 | |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 491 | def UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content): |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 492 | """Update the DEPS file with the new revision.""" |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 493 | |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 494 | with open(deps_filename, 'rb') as deps_file: |
| 495 | deps_content = deps_file.read() |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 496 | |
| 497 | # Update the chromium_revision variable. |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 498 | deps_content = deps_content.replace(rev_update.current_chromium_rev, |
| 499 | rev_update.new_chromium_rev) |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 500 | |
| 501 | # Add and remove dependencies. For now: only generated android deps. |
| 502 | # Since gclient cannot add or remove deps, we on the fact that |
| 503 | # these android deps are located in one place we can copy/paste. |
| 504 | deps_re = re.compile(ANDROID_DEPS_START + '.*' + ANDROID_DEPS_END, |
| 505 | re.DOTALL) |
| 506 | new_deps = deps_re.search(new_cr_content) |
| 507 | old_deps = deps_re.search(deps_content) |
| 508 | if not new_deps or not old_deps: |
| 509 | faulty = 'Chromium' if not new_deps else 'WebRTC' |
| 510 | raise RollError('Was expecting to find "%s" and "%s"\n' |
| 511 | 'in %s DEPS' |
| 512 | % (ANDROID_DEPS_START, ANDROID_DEPS_END, faulty)) |
| 513 | deps_content = deps_re.sub(new_deps.group(0), deps_content) |
| 514 | |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 515 | with open(deps_filename, 'wb') as deps_file: |
| 516 | deps_file.write(deps_content) |
| 517 | |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 518 | # Update each individual DEPS entry. |
| 519 | for dep in changed_deps: |
kjellander@webrtc.org | 177567c | 2016-12-22 10:40:28 +0100 | [diff] [blame] | 520 | local_dep_dir = os.path.join(CHECKOUT_ROOT_DIR, dep.path) |
| 521 | if not os.path.isdir(local_dep_dir): |
| 522 | raise RollError( |
| 523 | 'Cannot find local directory %s. Either run\n' |
| 524 | 'gclient sync --deps=all\n' |
| 525 | 'or make sure the .gclient file for your solution contains all ' |
| 526 | 'platforms in the target_os list, i.e.\n' |
| 527 | 'target_os = ["android", "unix", "mac", "ios", "win"];\n' |
| 528 | 'Then run "gclient sync" again.' % local_dep_dir) |
Oleh Prypin | 4775b27 | 2018-04-26 22:33:26 +0200 | [diff] [blame] | 529 | if isinstance(dep, ChangedCipdPackage): |
Oleh Prypin | a8eb1e6 | 2018-07-03 08:47:28 +0200 | [diff] [blame] | 530 | package = dep.package.format() # Eliminate double curly brackets |
| 531 | update = '%s:%s@%s' % (dep.path, package, dep.new_version) |
Oleh Prypin | 4775b27 | 2018-04-26 22:33:26 +0200 | [diff] [blame] | 532 | else: |
| 533 | update = '%s@%s' % (dep.path, dep.new_rev) |
| 534 | _RunCommand(['gclient', 'setdep', '--revision', update], |
| 535 | working_dir=CHECKOUT_SRC_DIR) |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 536 | |
| 537 | |
Henrik Kjellander | 1b76ca1 | 2015-06-09 12:58:44 +0200 | [diff] [blame] | 538 | def _IsTreeClean(): |
| 539 | stdout, _ = _RunCommand(['git', 'status', '--porcelain']) |
| 540 | if len(stdout) == 0: |
| 541 | return True |
| 542 | |
| 543 | logging.error('Dirty/unversioned files:\n%s', stdout) |
| 544 | return False |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 545 | |
Henrik Kjellander | 44d5d7b | 2015-09-25 13:21:44 +0200 | [diff] [blame] | 546 | |
| 547 | def _EnsureUpdatedMasterBranch(dry_run): |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 548 | current_branch = _RunCommand( |
| 549 | ['git', 'rev-parse', '--abbrev-ref', 'HEAD'])[0].splitlines()[0] |
| 550 | if current_branch != 'master': |
| 551 | logging.error('Please checkout the master branch and re-run this script.') |
| 552 | if not dry_run: |
| 553 | sys.exit(-1) |
| 554 | |
Henrik Kjellander | 1b76ca1 | 2015-06-09 12:58:44 +0200 | [diff] [blame] | 555 | logging.info('Updating master branch...') |
Henrik Kjellander | 6c2ba7d | 2015-10-02 09:03:06 +0200 | [diff] [blame] | 556 | _RunCommand(['git', 'pull']) |
Henrik Kjellander | 44d5d7b | 2015-09-25 13:21:44 +0200 | [diff] [blame] | 557 | |
| 558 | |
| 559 | def _CreateRollBranch(dry_run): |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 560 | logging.info('Creating roll branch: %s', ROLL_BRANCH_NAME) |
| 561 | if not dry_run: |
| 562 | _RunCommand(['git', 'checkout', '-b', ROLL_BRANCH_NAME]) |
| 563 | |
| 564 | |
| 565 | def _RemovePreviousRollBranch(dry_run): |
| 566 | active_branch, branches = _GetBranches() |
| 567 | if active_branch == ROLL_BRANCH_NAME: |
| 568 | active_branch = 'master' |
| 569 | if ROLL_BRANCH_NAME in branches: |
| 570 | logging.info('Removing previous roll branch (%s)', ROLL_BRANCH_NAME) |
| 571 | if not dry_run: |
| 572 | _RunCommand(['git', 'checkout', active_branch]) |
| 573 | _RunCommand(['git', 'branch', '-D', ROLL_BRANCH_NAME]) |
| 574 | |
| 575 | |
| 576 | def _LocalCommit(commit_msg, dry_run): |
| 577 | logging.info('Committing changes locally.') |
| 578 | if not dry_run: |
| 579 | _RunCommand(['git', 'add', '--update', '.']) |
| 580 | _RunCommand(['git', 'commit', '-m', commit_msg]) |
| 581 | |
| 582 | |
Oleh Prypin | b76767b | 2018-01-02 13:13:23 +0100 | [diff] [blame] | 583 | def ChooseCQMode(skip_cq, cq_over, current_commit_pos, new_commit_pos): |
Oleh Prypin | 65fb17b | 2017-12-27 10:25:24 +0100 | [diff] [blame] | 584 | if skip_cq: |
| 585 | return 0 |
Oleh Prypin | 16b2a36 | 2017-12-27 21:03:55 +0100 | [diff] [blame] | 586 | if (new_commit_pos - current_commit_pos) < cq_over: |
Oleh Prypin | 65fb17b | 2017-12-27 10:25:24 +0100 | [diff] [blame] | 587 | return 1 |
| 588 | return 2 |
| 589 | |
| 590 | |
Oleh Prypin | b76767b | 2018-01-02 13:13:23 +0100 | [diff] [blame] | 591 | def _UploadCL(commit_queue_mode): |
Oleh Prypin | 65fb17b | 2017-12-27 10:25:24 +0100 | [diff] [blame] | 592 | """Upload the committed changes as a changelist to Gerrit. |
| 593 | |
Oleh Prypin | b76767b | 2018-01-02 13:13:23 +0100 | [diff] [blame] | 594 | commit_queue_mode: |
Oleh Prypin | 65fb17b | 2017-12-27 10:25:24 +0100 | [diff] [blame] | 595 | - 2: Submit to commit queue. |
Oleh Prypin | b76767b | 2018-01-02 13:13:23 +0100 | [diff] [blame] | 596 | - 1: Run trybots but do not submit to CQ. |
Oleh Prypin | 65fb17b | 2017-12-27 10:25:24 +0100 | [diff] [blame] | 597 | - 0: Skip CQ, upload only. |
| 598 | """ |
Oleh Prypin | e6708f3 | 2018-10-08 14:01:59 +0200 | [diff] [blame] | 599 | cmd = ['git', 'cl', 'upload', '--force', '--bypass-hooks', '--send-mail'] |
| 600 | cmd.extend(['--cc', NOTIFY_EMAIL]) |
Oleh Prypin | b76767b | 2018-01-02 13:13:23 +0100 | [diff] [blame] | 601 | if commit_queue_mode >= 2: |
| 602 | logging.info('Sending the CL to the CQ...') |
Oleh Prypin | e6708f3 | 2018-10-08 14:01:59 +0200 | [diff] [blame] | 603 | cmd.extend(['--use-commit-queue']) |
Oleh Prypin | b76767b | 2018-01-02 13:13:23 +0100 | [diff] [blame] | 604 | elif commit_queue_mode >= 1: |
| 605 | logging.info('Starting CQ dry run...') |
| 606 | cmd.extend(['--cq-dry-run']) |
Eric Boren | 3ee3c40 | 2018-09-20 09:22:13 -0400 | [diff] [blame] | 607 | extra_env = { |
| 608 | 'EDITOR': 'true', |
| 609 | 'SKIP_GCE_AUTH_FOR_GIT': '1', |
| 610 | } |
| 611 | stdout, stderr = _RunCommand(cmd, extra_env=extra_env) |
| 612 | logging.debug('Output from "git cl upload":\nstdout:\n%s\n\nstderr:\n%s', |
| 613 | stdout, stderr) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 614 | |
| 615 | |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 616 | def GetRollRevisionRanges(opts, webrtc_deps): |
| 617 | current_cr_rev = webrtc_deps['vars']['chromium_revision'] |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 618 | new_cr_rev = opts.revision |
| 619 | if not new_cr_rev: |
| 620 | stdout, _ = _RunCommand(['git', 'ls-remote', CHROMIUM_SRC_URL, 'HEAD']) |
| 621 | head_rev = stdout.strip().split('\t')[0] |
| 622 | logging.info('No revision specified. Using HEAD: %s', head_rev) |
| 623 | new_cr_rev = head_rev |
| 624 | |
Artem Titov | 42f0d78 | 2018-06-27 13:23:17 +0200 | [diff] [blame] | 625 | return ChromiumRevisionUpdate(current_cr_rev, new_cr_rev) |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 626 | |
| 627 | |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 628 | def main(): |
| 629 | p = argparse.ArgumentParser() |
| 630 | p.add_argument('--clean', action='store_true', default=False, |
| 631 | help='Removes any previous local roll branch.') |
| 632 | p.add_argument('-r', '--revision', |
| 633 | help=('Chromium Git revision to roll to. Defaults to the ' |
Henrik Kjellander | 18b042f | 2015-10-02 09:01:39 +0200 | [diff] [blame] | 634 | 'Chromium HEAD revision if omitted.')) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 635 | p.add_argument('--dry-run', action='store_true', default=False, |
| 636 | help=('Calculate changes and modify DEPS, but don\'t create ' |
| 637 | 'any local branch, commit, upload CL or send any ' |
| 638 | 'tryjobs.')) |
kjellander | 665da28 | 2016-12-14 03:57:08 -0800 | [diff] [blame] | 639 | p.add_argument('-i', '--ignore-unclean-workdir', action='store_true', |
| 640 | default=False, |
| 641 | help=('Ignore if the current branch is not master or if there ' |
| 642 | 'are uncommitted changes (default: %(default)s).')) |
Oleh Prypin | 65fb17b | 2017-12-27 10:25:24 +0100 | [diff] [blame] | 643 | grp = p.add_mutually_exclusive_group() |
| 644 | grp.add_argument('--skip-cq', action='store_true', default=False, |
| 645 | help='Skip sending the CL to the CQ (default: %(default)s)') |
| 646 | grp.add_argument('--cq-over', type=int, default=1, |
| 647 | help=('Commit queue dry run if the revision difference ' |
| 648 | 'is below this number (default: %(default)s)')) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 649 | p.add_argument('-v', '--verbose', action='store_true', default=False, |
| 650 | help='Be extra verbose in printing of log messages.') |
| 651 | opts = p.parse_args() |
| 652 | |
| 653 | if opts.verbose: |
| 654 | logging.basicConfig(level=logging.DEBUG) |
| 655 | else: |
| 656 | logging.basicConfig(level=logging.INFO) |
| 657 | |
kjellander | 665da28 | 2016-12-14 03:57:08 -0800 | [diff] [blame] | 658 | if not opts.ignore_unclean_workdir and not _IsTreeClean(): |
Henrik Kjellander | 1b76ca1 | 2015-06-09 12:58:44 +0200 | [diff] [blame] | 659 | logging.error('Please clean your local checkout first.') |
| 660 | return 1 |
| 661 | |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 662 | if opts.clean: |
| 663 | _RemovePreviousRollBranch(opts.dry_run) |
| 664 | |
kjellander | 665da28 | 2016-12-14 03:57:08 -0800 | [diff] [blame] | 665 | if not opts.ignore_unclean_workdir: |
| 666 | _EnsureUpdatedMasterBranch(opts.dry_run) |
Henrik Kjellander | 44d5d7b | 2015-09-25 13:21:44 +0200 | [diff] [blame] | 667 | |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 668 | deps_filename = os.path.join(CHECKOUT_SRC_DIR, 'DEPS') |
| 669 | webrtc_deps = ParseLocalDepsFile(deps_filename) |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 670 | |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 671 | rev_update = GetRollRevisionRanges(opts, webrtc_deps) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 672 | |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 673 | current_commit_pos = ParseCommitPosition( |
| 674 | ReadRemoteCrCommit(rev_update.current_chromium_rev)) |
| 675 | new_commit_pos = ParseCommitPosition( |
| 676 | ReadRemoteCrCommit(rev_update.new_chromium_rev)) |
| 677 | |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 678 | new_cr_content = ReadRemoteCrFile('DEPS', rev_update.new_chromium_rev) |
| 679 | new_cr_deps = ParseDepsDict(new_cr_content) |
kjellander@webrtc.org | 177567c | 2016-12-22 10:40:28 +0100 | [diff] [blame] | 680 | changed_deps = CalculateChangedDeps(webrtc_deps, new_cr_deps) |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 681 | # Discard other deps, assumed to be chromium-only dependencies. |
| 682 | new_generated_android_deps, _ = FindAddedDeps(webrtc_deps, new_cr_deps) |
| 683 | removed_generated_android_deps, other_deps = FindRemovedDeps(webrtc_deps, |
| 684 | new_cr_deps) |
| 685 | if other_deps: |
Yves Gerey | 67e5bd3 | 2019-11-19 14:04:18 +0100 | [diff] [blame^] | 686 | raise RollError('WebRTC DEPS entries are missing from Chromium: %s.\n' |
| 687 | 'Remove them or add them to either ' |
| 688 | 'WEBRTC_ONLY_DEPS or DONT_AUTOROLL_THESE.' % other_deps) |
Artem Titov | a04d140 | 2018-05-11 11:23:00 +0200 | [diff] [blame] | 689 | clang_change = CalculateChangedClang(rev_update.new_chromium_rev) |
Yves Gerey | 31eb01f | 2018-09-19 17:25:20 +0200 | [diff] [blame] | 690 | commit_msg = GenerateCommitMessage( |
| 691 | rev_update, current_commit_pos, new_commit_pos, changed_deps, |
| 692 | added_deps_paths=new_generated_android_deps, |
| 693 | removed_deps_paths=removed_generated_android_deps, |
| 694 | clang_change=clang_change) |
kjellander | 38b6dbc | 2016-12-13 03:35:21 -0800 | [diff] [blame] | 695 | logging.debug('Commit message:\n%s', commit_msg) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 696 | |
| 697 | _CreateRollBranch(opts.dry_run) |
Yves Gerey | 401afd5 | 2018-09-19 09:51:41 +0200 | [diff] [blame] | 698 | if not opts.dry_run: |
| 699 | UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content) |
kjellander | c99bddf | 2017-05-15 02:40:58 -0700 | [diff] [blame] | 700 | if _IsTreeClean(): |
| 701 | logging.info("No DEPS changes detected, skipping CL creation.") |
| 702 | else: |
| 703 | _LocalCommit(commit_msg, opts.dry_run) |
Oleh Prypin | b76767b | 2018-01-02 13:13:23 +0100 | [diff] [blame] | 704 | commit_queue_mode = ChooseCQMode(opts.skip_cq, opts.cq_over, |
| 705 | current_commit_pos, new_commit_pos) |
| 706 | logging.info('Uploading CL...') |
| 707 | if not opts.dry_run: |
| 708 | _UploadCL(commit_queue_mode) |
Henrik Kjellander | 8d3ad82 | 2015-05-26 19:52:05 +0200 | [diff] [blame] | 709 | return 0 |
| 710 | |
| 711 | |
| 712 | if __name__ == '__main__': |
| 713 | sys.exit(main()) |