Update pylintrc to a pep-8 like style

In particular, this requires reformatting
- autoroller/
- PRESUBMIT.py
- infra/config/PRESUBMIT.py
- get_landmines.py
- download_vs_toolchain.py
as well as some manual fixes.

This CL is preparation to updating the autoroller so that we can roll DEPS from chromium.

No-Try: True
Bug: libyuv:358992053
Change-Id: I090a09c6fa61beff2427a0537bca371f0839fa3e
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/6105550
Reviewed-by: Mirko Bonadei <mbonadei@chromium.org>
Reviewed-by: Jeremy Leconte <jleconte@google.com>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
This commit is contained in:
Björn Terelius 2024-12-18 14:02:45 +01:00 committed by libyuv LUCI CQ
parent 2c682f8d59
commit 37e88ecc68
7 changed files with 792 additions and 635 deletions

View File

@ -9,11 +9,16 @@
# Runs PRESUBMIT.py in py3 mode by git cl presubmit.
USE_PYTHON3 = True
def _CommonChecks(input_api, output_api):
"""Checks common to both upload and commit."""
results = []
results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
files_to_skip=(r'^base[\\\/].*\.py$',
results.extend(
input_api.canned_checks.RunPylint(
input_api,
output_api,
files_to_skip=(
r'^base[\\\/].*\.py$',
r'^build[\\\/].*\.py$',
r'^buildtools[\\\/].*\.py$',
r'^ios[\\\/].*\.py$',
@ -23,13 +28,17 @@ def _CommonChecks(input_api, output_api):
r'^tools[\\\/].*\.py$',
# TODO(kjellander): should arguably be checked.
r'^tools_libyuv[\\\/]valgrind[\\\/].*\.py$',
r'^xcodebuild.*[\\\/].*\.py$',),
disabled_warnings=['F0401', # Failed to import x
r'^xcodebuild.*[\\\/].*\.py$',
),
disabled_warnings=[
'F0401', # Failed to import x
'E0611', # No package y in x
'W0232', # Class has no __init__ method
],
pylintrc='pylintrc',
version='2.7'))
version='2.7',
)
)
return results
@ -37,7 +46,8 @@ def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(_CommonChecks(input_api, output_api))
results.extend(
input_api.canned_checks.CheckGNFormatted(input_api, output_api))
input_api.canned_checks.CheckGNFormatted(input_api, output_api)
)
return results
@ -45,8 +55,11 @@ def CheckChangeOnCommit(input_api, output_api):
results = []
results.extend(_CommonChecks(input_api, output_api))
results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeWasUploaded(
input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasDescription(
input_api, output_api))
results.extend(
input_api.canned_checks.CheckChangeWasUploaded(input_api, output_api)
)
results.extend(
input_api.canned_checks.CheckChangeHasDescription(input_api,
output_api)
)
return results

View File

@ -6,8 +6,12 @@ USE_PYTHON3 = True
def CheckChangeOnUpload(input_api, output_api):
return input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api)
return input_api.canned_checks.CheckChangedLUCIConfigs(
input_api, output_api
)
def CheckChangeOnCommit(input_api, output_api):
return input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api)
return input_api.canned_checks.CheckChangedLUCIConfigs(
input_api, output_api
)

View File

@ -13,5 +13,37 @@ reports=no
[FORMAT]
# We use two spaces for indents, instead of the usual four spaces or tab.
# Maximum number of characters on a single line.
max-line-length=79
# We use four spaces for indents.
indent-string=' '
[BASIC]
# List of builtins function names that should not be used, separated by a comma
bad-functions=map,filter,apply,input
# Naming style matching correct module names.
module-naming-style=snake_case
# Naming style matching correct constant names.
const-naming-style=UPPER_CASE
# Naming style matching correct class names.
class-naming-style=PascalCase
# Naming style matching correct function names.
function-naming-style=snake_case
# Regular expression matching correct method names.
method-rgx=([a-z_][a-z0-9_]{2,}|setUp|tearDown)$
# Naming style matching correct attribute names.
attr-naming-style=snake_case
# Naming style matching correct argument names.
argument-naming-style=snake_case
# Naming style matching correct variable names.
variable-naming-style=snake_case

View File

@ -19,6 +19,7 @@ import re
import subprocess
import sys
import urllib.request
import find_depot_tools
def FindSrcDirPath():
@ -85,27 +86,30 @@ ANDROID_DEPS_END = r'=== ANDROID_DEPS Generated Code End ==='
ANDROID_DEPS_PATH = 'src/third_party/android_deps/'
sys.path.append(os.path.join(CHECKOUT_SRC_DIR, 'build'))
import find_depot_tools
find_depot_tools.add_depot_tools_to_path()
CLANG_UPDATE_SCRIPT_URL_PATH = 'tools/clang/scripts/update.py'
CLANG_UPDATE_SCRIPT_LOCAL_PATH = os.path.join(CHECKOUT_SRC_DIR, 'tools',
'clang', 'scripts', 'update.py')
CLANG_UPDATE_SCRIPT_LOCAL_PATH = os.path.join(
CHECKOUT_SRC_DIR, 'tools', 'clang', 'scripts', 'update.py'
)
DepsEntry = collections.namedtuple('DepsEntry', 'path url revision')
ChangedDep = collections.namedtuple('ChangedDep',
'path url current_rev new_rev')
ChangedDep = collections.namedtuple(
'ChangedDep', 'path url current_rev new_rev'
)
CipdDepsEntry = collections.namedtuple('CipdDepsEntry', 'path packages')
VersionEntry = collections.namedtuple('VersionEntry', 'version')
ChangedCipdPackage = collections.namedtuple(
'ChangedCipdPackage', 'path package current_version new_version')
'ChangedCipdPackage', 'path package current_version new_version'
)
ChangedVersionEntry = collections.namedtuple(
'ChangedVersionEntry', 'path current_version new_version')
'ChangedVersionEntry', 'path current_version new_version'
)
ChromiumRevisionUpdate = collections.namedtuple('ChromiumRevisionUpdate',
('current_chromium_rev '
'new_chromium_rev '))
ChromiumRevisionUpdate = collections.namedtuple(
'ChromiumRevisionUpdate', 'current_chromium_rev new_chromium_rev '
)
class RollError(Exception):
@ -142,16 +146,19 @@ def ParseCommitPosition(commit_message):
m = COMMIT_POSITION_RE.match(line.strip())
if m:
return int(m.group(1))
logging.error('Failed to parse commit position id from:\n%s\n',
commit_message)
logging.error(
'Failed to parse commit position id from:\n%s\n', commit_message
)
sys.exit(-1)
def _RunCommand(command,
def _RunCommand(
command,
working_dir=None,
ignore_exit_code=False,
extra_env=None,
input_data=None):
input_data=None,
):
"""Runs a command and returns the output from that command.
If the command fails (exit code != 0), the function will exit the process.
@ -166,20 +173,25 @@ def _RunCommand(command,
assert all(isinstance(value, str) for value in extra_env.values())
logging.debug('extra env: %s', extra_env)
env.update(extra_env)
p = subprocess.Popen(command,
p = subprocess.Popen(
command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env,
cwd=working_dir,
universal_newlines=True)
universal_newlines=True,
)
std_output, err_output = p.communicate(input_data)
p.stdout.close()
p.stderr.close()
if not ignore_exit_code and p.returncode != 0:
logging.error('Command failed: %s\n'
'stdout:\n%s\n'
'stderr:\n%s\n', ' '.join(command), std_output, err_output)
logging.error(
'Command failed: %s\nstdout:\n%s\nstderr:\n%s\n',
' '.join(command),
std_output,
err_output,
)
sys.exit(p.returncode)
return std_output, err_output
@ -218,11 +230,13 @@ def ReadRemoteCrFile(path_below_src, revision):
Args:
path_below_src: A path to the target file relative to src dir.
revision: Revision to read.
Returns:
A string with file content.
"""
return _ReadGitilesContent(CHROMIUM_FILE_TEMPLATE %
(revision, path_below_src))
return _ReadGitilesContent(
CHROMIUM_FILE_TEMPLATE % (revision, path_below_src)
)
def ReadRemoteCrCommit(revision):
@ -235,6 +249,7 @@ def ReadUrlContent(url):
Args:
url: URL to connect to.
Returns:
A list of lines.
"""
@ -267,7 +282,9 @@ def GetMatchingDepsEntries(depsentry_dict, dir_path):
result.append(depsentry)
else:
parts = path.split('/')
if all(part == parts[i] for i, part in enumerate(dir_path.split('/'))):
if all(
part == parts[i] for i, part in enumerate(dir_path.split('/'))
):
result.append(depsentry)
return result
@ -309,25 +326,29 @@ def BuildDepsentryDict(deps_dict):
def _FindChangedCipdPackages(path, old_pkgs, new_pkgs):
old_pkgs_names = {p['package'] for p in old_pkgs}
new_pkgs_names = {p['package'] for p in new_pkgs}
pkgs_equal = (old_pkgs_names == new_pkgs_names)
pkgs_equal = old_pkgs_names == new_pkgs_names
added_pkgs = [p for p in new_pkgs_names if p not in old_pkgs_names]
removed_pkgs = [p for p in old_pkgs_names if p not in new_pkgs_names]
assert pkgs_equal, ('Old: %s\n New: %s.\nYou need to do a manual roll '
assert pkgs_equal, (
'Old: %s\n New: %s.\nYou need to do a manual roll '
'and remove/add entries in DEPS so the old and new '
'list match.\nMost likely, you should add \"%s\" and '
'remove \"%s\"' %
(old_pkgs, new_pkgs, added_pkgs, removed_pkgs))
'list match.\nMost likely, you should add "%s" and '
'remove "%s"' % (old_pkgs, new_pkgs, added_pkgs, removed_pkgs)
)
for old_pkg in old_pkgs:
for new_pkg in new_pkgs:
old_version = old_pkg['version']
new_version = new_pkg['version']
if (old_pkg['package'] == new_pkg['package']
and old_version != new_version):
if (
old_pkg['package'] == new_pkg['package']
and old_version != new_version
):
logging.debug('Roll dependency %s to %s', path, new_version)
yield ChangedCipdPackage(path, old_pkg['package'], old_version,
new_version)
yield ChangedCipdPackage(
path, old_pkg['package'], old_version, new_version
)
def _FindChangedVars(name, old_version, new_version):
@ -337,18 +358,18 @@ def _FindChangedVars(name, old_version, new_version):
def _FindNewDeps(old, new):
""" Gather dependencies only in `new` and return corresponding paths. """
"""Gather dependencies only in `new` and return corresponding paths."""
old_entries = set(BuildDepsentryDict(old))
new_entries = set(BuildDepsentryDict(new))
return [
path for path in new_entries - old_entries
path
for path in new_entries - old_entries
if path not in DONT_AUTOROLL_THESE
]
def FindAddedDeps(libyuv_deps, new_cr_deps):
"""
Calculate new deps entries of interest.
"""Calculate new deps entries of interest.
Ideally, that would mean: only appearing in chromium DEPS
but transitively used in LibYUV.
@ -379,8 +400,7 @@ def FindAddedDeps(libyuv_deps, new_cr_deps):
def FindRemovedDeps(libyuv_deps, new_cr_deps):
"""
Calculate obsolete deps entries.
"""Calculate obsolete deps entries.
Ideally, that would mean: no more appearing in chromium DEPS
and not used in LibYUV.
@ -403,19 +423,23 @@ def FindRemovedDeps(libyuv_deps, new_cr_deps):
A list of paths of unexpected disappearing dependencies.
"""
all_removed_deps = _FindNewDeps(new_cr_deps, libyuv_deps)
generated_android_deps = sorted(
[path for path in all_removed_deps if path.startswith(ANDROID_DEPS_PATH)])
generated_android_deps = sorted([
path for path in all_removed_deps if path.startswith(ANDROID_DEPS_PATH)
])
# Webrtc-only dependencies are handled in CalculateChangedDeps.
other_deps = sorted([
path for path in all_removed_deps
path
for path in all_removed_deps
if path not in generated_android_deps and path not in LIBYUV_ONLY_DEPS
])
return generated_android_deps, other_deps
def CalculateChangedDeps(libyuv_deps, new_cr_deps):
"""
Calculate changed deps entries based on entries defined in the LibYUV DEPS
"""Calculate changed deps entries based on entries defined in the LibYUV
DEPS
file:
- If a shared dependency with the Chromium DEPS file: roll it to the same
revision as Chromium (i.e. entry in the new_cr_deps dict)
@ -440,26 +464,36 @@ def CalculateChangedDeps(libyuv_deps, new_cr_deps):
if isinstance(cr_deps_entry, CipdDepsEntry):
result.extend(
_FindChangedCipdPackages(path, libyuv_deps_entry.packages,
cr_deps_entry.packages))
_FindChangedCipdPackages(
path, libyuv_deps_entry.packages, cr_deps_entry.packages # pylint: disable=line-too-long
)
)
continue
if isinstance(cr_deps_entry, VersionEntry):
result.extend(
_FindChangedVars(path, libyuv_deps_entry.version,
cr_deps_entry.version))
_FindChangedVars(
path, libyuv_deps_entry.version, cr_deps_entry.version
)
)
continue
# Use the revision from Chromium's DEPS file.
new_rev = cr_deps_entry.revision
assert libyuv_deps_entry.url == cr_deps_entry.url, (
'LibYUV DEPS entry %s has a different URL %s than Chromium %s.' %
(path, libyuv_deps_entry.url, cr_deps_entry.url))
'LibYUV DEPS entry %s has a different URL %s than Chromium %s.'
% (
path,
libyuv_deps_entry.url,
cr_deps_entry.url,
)
)
else:
if isinstance(libyuv_deps_entry, DepsEntry):
# Use the HEAD of the deps repo.
stdout, _ = _RunCommand(
['git', 'ls-remote', libyuv_deps_entry.url, 'HEAD'])
['git', 'ls-remote', libyuv_deps_entry.url, 'HEAD']
)
new_rev = stdout.strip().split('\t')[0]
else:
# The dependency has been removed from chromium.
@ -470,8 +504,13 @@ def CalculateChangedDeps(libyuv_deps, new_cr_deps):
if libyuv_deps_entry.revision != new_rev:
logging.debug('Roll dependency %s to %s', path, new_rev)
result.append(
ChangedDep(path, libyuv_deps_entry.url, libyuv_deps_entry.revision,
new_rev))
ChangedDep(
path,
libyuv_deps_entry.url,
libyuv_deps_entry.revision,
new_rev,
)
)
return sorted(result)
@ -488,10 +527,13 @@ def CalculateChangedClang(new_cr_rev):
current_lines = f.readlines()
current_rev = GetClangRev(current_lines)
new_clang_update_py = ReadRemoteCrFile(CLANG_UPDATE_SCRIPT_URL_PATH,
new_cr_rev).splitlines()
new_clang_update_py = ReadRemoteCrFile(
CLANG_UPDATE_SCRIPT_URL_PATH, new_cr_rev
).splitlines()
new_rev = GetClangRev(new_clang_update_py)
return ChangedDep(CLANG_UPDATE_SCRIPT_LOCAL_PATH, None, current_rev, new_rev)
return ChangedDep(
CLANG_UPDATE_SCRIPT_LOCAL_PATH, None, current_rev, new_rev
)
def GenerateCommitMessage(
@ -509,9 +551,10 @@ def GenerateCommitMessage(
git_number_interval = '%s:%s' % (current_commit_pos, new_commit_pos)
commit_msg = [
'Roll chromium_revision %s (%s)\n' % (rev_interval, git_number_interval),
'Roll chromium_revision %s (%s)\n'
% (rev_interval, git_number_interval),
'Change log: %s' % (CHROMIUM_LOG_TEMPLATE % rev_interval),
'Full diff: %s\n' % (CHROMIUM_COMMIT_TEMPLATE % rev_interval)
'Full diff: %s\n' % (CHROMIUM_COMMIT_TEMPLATE % rev_interval),
]
def Section(adjective, deps):
@ -523,14 +566,19 @@ def GenerateCommitMessage(
for c in changed_deps_list:
if isinstance(c, ChangedCipdPackage):
commit_msg.append('* %s: %s..%s' %
(c.path, c.current_version, c.new_version))
commit_msg.append(
'* %s: %s..%s' % (c.path, c.current_version, c.new_version)
)
elif isinstance(c, ChangedVersionEntry):
commit_msg.append('* %s_vesion: %s..%s' %
(c.path, c.current_version, c.new_version))
commit_msg.append(
'* %s_vesion: %s..%s'
% (c.path, c.current_version, c.new_version)
)
else:
commit_msg.append('* %s: %s/+log/%s..%s' %
(c.path, c.url, c.current_rev[0:10], c.new_rev[0:10]))
commit_msg.append(
'* %s: %s/+log/%s..%s'
% (c.path, c.url, c.current_rev[0:10], c.new_rev[0:10])
)
if added_deps_paths:
Section('Added', added_deps_paths)
@ -547,10 +595,14 @@ def GenerateCommitMessage(
commit_msg.append('No dependencies changed.')
if clang_change and clang_change.current_rev != clang_change.new_rev:
commit_msg.append('Clang version changed %s:%s' %
(clang_change.current_rev, clang_change.new_rev))
change_url = CHROMIUM_FILE_TEMPLATE % (rev_interval,
CLANG_UPDATE_SCRIPT_URL_PATH)
commit_msg.append(
'Clang version changed %s:%s'
% (clang_change.current_rev, clang_change.new_rev)
)
change_url = CHROMIUM_FILE_TEMPLATE % (
rev_interval,
CLANG_UPDATE_SCRIPT_URL_PATH,
)
commit_msg.append('Details: %s\n' % change_url)
else:
commit_msg.append('No update to Clang.\n')
@ -566,25 +618,31 @@ def UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content):
deps_content = deps_file.read().decode('utf-8')
# Update the chromium_revision variable.
deps_content = deps_content.replace(rev_update.current_chromium_rev,
rev_update.new_chromium_rev)
deps_content = deps_content.replace(
rev_update.current_chromium_rev, rev_update.new_chromium_rev
)
# Add and remove dependencies. For now: only generated android deps.
# Since gclient cannot add or remove deps, we on the fact that
# these android deps are located in one place we can copy/paste.
deps_re = re.compile(ANDROID_DEPS_START + '.*' + ANDROID_DEPS_END, re.DOTALL)
deps_re = re.compile(
ANDROID_DEPS_START + '.*' + ANDROID_DEPS_END, re.DOTALL
)
new_deps = deps_re.search(new_cr_content)
old_deps = deps_re.search(deps_content)
if not new_deps or not old_deps:
faulty = 'Chromium' if not new_deps else 'LibYUV'
raise RollError('Was expecting to find "%s" and "%s"\n'
'in %s DEPS' %
(ANDROID_DEPS_START, ANDROID_DEPS_END, faulty))
raise RollError(
'Was expecting to find "%s" and "%s"\nin %s DEPS'
% (ANDROID_DEPS_START, ANDROID_DEPS_END, faulty)
)
deps_content = deps_re.sub(new_deps.group(0), deps_content)
for dep in changed_deps:
if isinstance(dep, ChangedVersionEntry):
deps_content = deps_content.replace(dep.current_version, dep.new_version)
deps_content = deps_content.replace(
dep.current_version, dep.new_version
)
with open(deps_filename, 'wb') as deps_file:
deps_file.write(deps_content.encode('utf-8'))
@ -599,17 +657,20 @@ def UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content):
raise RollError(
'Cannot find local directory %s. Either run\n'
'gclient sync --deps=all\n'
'or make sure the .gclient file for your solution contains all '
'platforms in the target_os list, i.e.\n'
'or make sure the .gclient file for your solution contains '
'all platforms in the target_os list, i.e.\n'
'target_os = ["android", "unix", "mac", "ios", "win"];\n'
'Then run "gclient sync" again.' % local_dep_dir)
'Then run "gclient sync" again.' % local_dep_dir
)
if isinstance(dep, ChangedCipdPackage):
package = dep.package.format() # Eliminate double curly brackets
update = '%s:%s@%s' % (dep.path, package, dep.new_version)
else:
update = '%s@%s' % (dep.path, dep.new_rev)
_RunCommand(['gclient', 'setdep', '--revision', update],
working_dir=CHECKOUT_SRC_DIR)
_RunCommand(
['gclient', 'setdep', '--revision', update],
working_dir=CHECKOUT_SRC_DIR,
)
def _IsTreeClean():
@ -622,10 +683,11 @@ def _IsTreeClean():
def _EnsureUpdatedMainBranch(dry_run):
current_branch = _RunCommand(['git', 'rev-parse', '--abbrev-ref',
'HEAD'])[0].splitlines()[0]
current_branch = _RunCommand(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])[
0
].splitlines()[0]
if current_branch != 'main':
logging.error('Please checkout the main branch and re-run this script.')
logging.error('Please checkout the main branch and re-run this script.') # pylint: disable=line-too-long
if not dry_run:
sys.exit(-1)
@ -666,10 +728,9 @@ def ChooseCQMode(skip_cq, cq_over, current_commit_pos, new_commit_pos):
def _GetCcRecipients(changed_deps_list):
"""Returns a list of emails to notify based on the changed deps list.
"""
"""Returns a list of emails to notify based on the changed deps list."""
cc_recipients = []
for c in changed_deps_list:
for _ in changed_deps_list:
pass
return cc_recipients
@ -701,8 +762,11 @@ def _UploadCL(commit_queue_mode, add_cc=None):
'SKIP_GCE_AUTH_FOR_GIT': '1',
}
stdout, stderr = _RunCommand(cmd, extra_env=extra_env)
logging.debug('Output from "git cl upload":\nstdout:\n%s\n\nstderr:\n%s',
stdout, stderr)
logging.debug(
'Output from "git cl upload":\nstdout:\n%s\n\nstderr:\n%s',
stdout,
stderr,
)
def GetRollRevisionRanges(opts, libyuv_deps):
@ -719,41 +783,63 @@ def GetRollRevisionRanges(opts, libyuv_deps):
def main():
p = argparse.ArgumentParser()
p.add_argument('--clean',
p.add_argument(
'--clean',
action='store_true',
default=False,
help='Removes any previous local roll branch.')
p.add_argument('-r',
help='Removes any previous local roll branch.',
)
p.add_argument(
'-r',
'--revision',
help=('Chromium Git revision to roll to. Defaults to the '
'Chromium HEAD revision if omitted.'))
p.add_argument('--dry-run',
help=(
'Chromium Git revision to roll to. Defaults to the '
'Chromium HEAD revision if omitted.'
),
)
p.add_argument(
'--dry-run',
action='store_true',
default=False,
help=('Calculate changes and modify DEPS, but don\'t create '
help=(
"Calculate changes and modify DEPS, but don't create "
'any local branch, commit, upload CL or send any '
'tryjobs.'))
p.add_argument('-i',
'tryjobs.'
),
)
p.add_argument(
'-i',
'--ignore-unclean-workdir',
action='store_true',
default=False,
help=('Ignore if the current branch is not main or if there '
'are uncommitted changes (default: %(default)s).'))
help=(
'Ignore if the current branch is not main or if there '
'are uncommitted changes (default: %(default)s).'
),
)
grp = p.add_mutually_exclusive_group()
grp.add_argument('--skip-cq',
grp.add_argument(
'--skip-cq',
action='store_true',
default=False,
help='Skip sending the CL to the CQ (default: %(default)s)')
grp.add_argument('--cq-over',
help='Skip sending the CL to the CQ (default: %(default)s)',
)
grp.add_argument(
'--cq-over',
type=int,
default=1,
help=('Commit queue dry run if the revision difference '
'is below this number (default: %(default)s)'))
p.add_argument('-v',
help=(
'Commit queue dry run if the revision difference '
'is below this number (default: %(default)s)'
),
)
p.add_argument(
'-v',
'--verbose',
action='store_true',
default=False,
help='Be extra verbose in printing of log messages.')
help='Be extra verbose in printing of log messages.',
)
opts = p.parse_args()
if opts.verbose:
@ -777,9 +863,11 @@ def main():
rev_update = GetRollRevisionRanges(opts, libyuv_deps)
current_commit_pos = ParseCommitPosition(
ReadRemoteCrCommit(rev_update.current_chromium_rev))
ReadRemoteCrCommit(rev_update.current_chromium_rev)
)
new_commit_pos = ParseCommitPosition(
ReadRemoteCrCommit(rev_update.new_chromium_rev))
ReadRemoteCrCommit(rev_update.new_chromium_rev)
)
new_cr_content = ReadRemoteCrFile('DEPS', rev_update.new_chromium_rev)
new_cr_deps = ParseDepsDict(new_cr_content)
@ -787,11 +875,14 @@ def main():
# Discard other deps, assumed to be chromium-only dependencies.
new_generated_android_deps, _ = FindAddedDeps(libyuv_deps, new_cr_deps)
removed_generated_android_deps, other_deps = FindRemovedDeps(
libyuv_deps, new_cr_deps)
libyuv_deps, new_cr_deps
)
if other_deps:
raise RollError('LibYUV DEPS entries are missing from Chromium: %s.\n'
raise RollError(
'LibYUV DEPS entries are missing from Chromium: %s.\n'
'Remove them or add them to either '
'LIBYUV_ONLY_DEPS or DONT_AUTOROLL_THESE.' % other_deps)
'LIBYUV_ONLY_DEPS or DONT_AUTOROLL_THESE.' % other_deps
)
clang_change = CalculateChangedClang(rev_update.new_chromium_rev)
commit_msg = GenerateCommitMessage(
rev_update,
@ -800,18 +891,20 @@ def main():
changed_deps,
added_deps_paths=new_generated_android_deps,
removed_deps_paths=removed_generated_android_deps,
clang_change=clang_change)
clang_change=clang_change,
)
logging.debug('Commit message:\n%s', commit_msg)
_CreateRollBranch(opts.dry_run)
if not opts.dry_run:
UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content)
if _IsTreeClean():
logging.info("No DEPS changes detected, skipping CL creation.")
logging.info('No DEPS changes detected, skipping CL creation.')
else:
_LocalCommit(commit_msg, opts.dry_run)
commit_queue_mode = ChooseCQMode(opts.skip_cq, opts.cq_over,
current_commit_pos, new_commit_pos)
commit_queue_mode = ChooseCQMode(
opts.skip_cq, opts.cq_over, current_commit_pos, new_commit_pos
)
logging.info('Uploading CL...')
if not opts.dry_run:
_UploadCL(commit_queue_mode, _GetCcRecipients(changed_deps))

View File

@ -16,8 +16,7 @@ import tempfile
import unittest
import roll_deps
from roll_deps import CalculateChangedDeps, GetMatchingDepsEntries, \
ParseDepsDict, ParseLocalDepsFile, UpdateDepsFile
from roll_deps import CalculateChangedDeps, GetMatchingDepsEntries, ParseDepsDict, ParseLocalDepsFile, UpdateDepsFile # pylint: disable=line-too-long
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_DIR = os.path.join(SCRIPT_DIR, os.pardir)
@ -45,7 +44,8 @@ class TestError(Exception):
pass
class FakeCmd():
class FakeCmd:
def __init__(self):
self.expectations = []
@ -58,20 +58,28 @@ class FakeCmd():
raise TestError('Got unexpected\n%s\n%s' % (args, kwargs))
exp_args, exp_kwargs, exp_returns = self.expectations.pop(0)
if args != exp_args or kwargs != exp_kwargs:
message = 'Expected:\n args: %s\n kwargs: %s\n' % (exp_args, exp_kwargs)
message = 'Expected:\n args: %s\n kwargs: %s\n' % (
exp_args,
exp_kwargs,
)
message += 'Got:\n args: %s\n kwargs: %s\n' % (args, kwargs)
raise TestError(message)
return exp_returns
class TestRollChromiumRevision(unittest.TestCase):
def setUp(self):
self._output_dir = tempfile.mkdtemp()
for test_file in glob.glob(os.path.join(SCRIPT_DIR, 'testdata', '*')):
shutil.copy(test_file, self._output_dir)
self._libyuv_depsfile = os.path.join(self._output_dir, 'DEPS')
self._old_cr_depsfile = os.path.join(self._output_dir, 'DEPS.chromium.old')
self._new_cr_depsfile = os.path.join(self._output_dir, 'DEPS.chromium.new')
self._old_cr_depsfile = os.path.join(
self._output_dir, 'DEPS.chromium.old'
)
self._new_cr_depsfile = os.path.join(
self._output_dir, 'DEPS.chromium.new'
)
self.fake = FakeCmd()
self.old_RunCommand = getattr(roll_deps, '_RunCommand')
@ -94,8 +102,10 @@ class TestRollChromiumRevision(unittest.TestCase):
UpdateDepsFile(self._libyuv_depsfile, current_rev, new_rev, [])
with open(self._libyuv_depsfile, 'r') as deps_file:
deps_contents = deps_file.read()
self.assertTrue(new_rev in deps_contents,
'Failed to find %s in\n%s' % (new_rev, deps_contents))
self.assertTrue(
new_rev in deps_contents,
'Failed to find %s in\n%s' % (new_rev, deps_contents),
)
def testParseDepsDict(self):
with open(self._libyuv_depsfile, 'r') as deps_file:
@ -104,7 +114,10 @@ class TestRollChromiumRevision(unittest.TestCase):
vars_dict = local_scope['vars']
def assertVar(variable_name):
self.assertEqual(vars_dict[variable_name], TEST_DATA_VARS[variable_name])
self.assertEqual(
vars_dict[variable_name], TEST_DATA_VARS[variable_name]
)
assertVar('chromium_git')
assertVar('chromium_revision')
self.assertEqual(len(local_scope['deps']), 3)
@ -124,8 +137,11 @@ class TestRollChromiumRevision(unittest.TestCase):
self.assertEqual(entries[0], DEPS_ENTRIES['src/build'])
def testCalculateChangedDeps(self):
_SetupGitLsRemoteCall(self.fake,
'https://chromium.googlesource.com/chromium/src/build', BUILD_NEW_REV)
_SetupGitLsRemoteCall(
self.fake,
'https://chromium.googlesource.com/chromium/src/build',
BUILD_NEW_REV,
)
libyuv_deps = ParseLocalDepsFile(self._libyuv_depsfile)
new_cr_deps = ParseLocalDepsFile(self._new_cr_depsfile)
changed_deps = CalculateChangedDeps(libyuv_deps, new_cr_deps)

View File

@ -9,23 +9,22 @@
# be found in the AUTHORS file in the root of the source tree.
"""
This file emits the list of reasons why a particular build needs to be clobbered
(or a list of 'landmines').
This file emits the list of reasons why a particular build needs to be
clobbered (or a list of 'landmines').
"""
import sys
def print_landmines():
"""
ALL LANDMINES ARE EMITTED FROM HERE.
"""
"""ALL LANDMINES ARE EMITTED FROM HERE."""
# DO NOT add landmines as part of a regular CL. Landmines are a last-effort
# bandaid fix if a CL that got landed has a build dependency bug and all bots
# need to be cleaned up. If you're writing a new CL that causes build
# bandaid fix if a CL that got landed has a build dependency bug and all
# bots need to be cleaned up. If you're writing a new CL that causes build
# dependency problems, fix the dependency problems instead of adding a
# landmine.
# See the Chromium version in src/build/get_landmines.py for usage examples.
# See the Chromium version in src/build/get_landmines.py for usage
# examples.
print('Clobber to remove GYP artifacts after switching bots to GN.')
print('Another try to remove GYP artifacts after switching bots to GN.')