Skip to content

Commit

Permalink
Teach autoroller to roll variables like fuchsia_version.
Browse files Browse the repository at this point in the history
By making this change, we ensure that these variables are not outdated.
Also, remove unnecessary list calls to python generators.

Bug: None
Change-Id: I53babe03da1cb78cf5dc127b7e1f753b63be20de
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/292620
Reviewed-by: Mirko Bonadei <[email protected]>
Commit-Queue: Daniel.L (Byoungchan) Lee <[email protected]>
Cr-Commit-Position: refs/heads/main@{#39267}
  • Loading branch information
bc-lee authored and WebRTC LUCI CQ committed Feb 8, 2023
1 parent b459dea commit e8ac5af
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
39 changes: 35 additions & 4 deletions tools_webrtc/autoroller/roll_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ def FindSrcDirPath():
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')
ChangedVersionEntry = collections.namedtuple(
'ChangedVersionEntry', 'path current_version new_version')

ChromiumRevisionUpdate = collections.namedtuple('ChromiumRevisionUpdate',
('current_chromium_rev '
Expand Down Expand Up @@ -148,7 +151,7 @@ def _RunCommand(command,
logging.debug('CMD: %s CWD: %s', ' '.join(command), working_dir)
env = os.environ.copy()
if extra_env:
assert all(isinstance(value, str) for value in list(extra_env.values()))
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,
Expand Down Expand Up @@ -247,7 +250,7 @@ def GetMatchingDepsEntries(depsentry_dict, dir_path):
A list of DepsEntry objects.
"""
result = []
for path, depsentry in list(depsentry_dict.items()):
for path, depsentry in depsentry_dict.items():
if path == dir_path:
result.append(depsentry)
else:
Expand All @@ -262,7 +265,7 @@ def BuildDepsentryDict(deps_dict):
result = {}

def AddDepsEntries(deps_subdict):
for path, dep in list(deps_subdict.items()):
for path, dep in deps_subdict.items():
if path in result:
continue
if not isinstance(dep, dict):
Expand All @@ -275,9 +278,19 @@ def AddDepsEntries(deps_subdict):
url, revision = dep['url'].split('@')
result[path] = DepsEntry(path, url, revision)

def AddVersionEntry(vars_subdict):
for key, value in vars_subdict.items():
if key in result:
continue
if not key.endswith('_version'):
continue
key = re.sub('_version$', '', key)
result[key] = VersionEntry(value)

AddDepsEntries(deps_dict['deps'])
for deps_os in ['win', 'mac', 'unix', 'android', 'ios', 'unix']:
AddDepsEntries(deps_dict.get('deps_os', {}).get(deps_os, {}))
AddVersionEntry(deps_dict.get('vars', {}))
return result


Expand Down Expand Up @@ -305,6 +318,12 @@ def _FindChangedCipdPackages(path, old_pkgs, new_pkgs):
new_version)


def _FindChangedVars(name, old_version, new_version):
if old_version != new_version:
logging.debug('Roll dependency %s to %s', name, new_version)
yield ChangedVersionEntry(name, old_version, new_version)


def _FindNewDeps(old, new):
""" Gather dependencies only in `new` and return corresponding paths. """
old_entries = set(BuildDepsentryDict(old))
Expand Down Expand Up @@ -400,7 +419,7 @@ def CalculateChangedDeps(webrtc_deps, new_cr_deps):
result = []
webrtc_entries = BuildDepsentryDict(webrtc_deps)
new_cr_entries = BuildDepsentryDict(new_cr_deps)
for path, webrtc_deps_entry in list(webrtc_entries.items()):
for path, webrtc_deps_entry in webrtc_entries.items():
if path in DONT_AUTOROLL_THESE:
continue
cr_deps_entry = new_cr_entries.get(path)
Expand All @@ -413,6 +432,12 @@ def CalculateChangedDeps(webrtc_deps, new_cr_deps):
cr_deps_entry.packages))
continue

if isinstance(cr_deps_entry, VersionEntry):
result.extend(
_FindChangedVars(path, webrtc_deps_entry.version,
cr_deps_entry.version))
continue

# Use the revision from Chromium's DEPS file.
new_rev = cr_deps_entry.revision
assert webrtc_deps_entry.url == cr_deps_entry.url, (
Expand Down Expand Up @@ -488,6 +513,9 @@ def Section(adjective, deps):
if isinstance(c, ChangedCipdPackage):
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))
else:
commit_msg.append('* %s: %s/+log/%s..%s' %
(c.path, c.url, c.current_rev[0:10], c.new_rev[0:10]))
Expand Down Expand Up @@ -547,6 +575,9 @@ def UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content):

# Update each individual DEPS entry.
for dep in changed_deps:
if isinstance(dep, ChangedVersionEntry):
deps_content = deps_content.replace(dep.current_version, dep.new_version)
continue
local_dep_dir = os.path.join(CHECKOUT_ROOT_DIR, dep.path)
if not os.path.isdir(local_dep_dir):
raise RollError(
Expand Down
33 changes: 19 additions & 14 deletions tools_webrtc/autoroller/unittests/roll_deps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,24 @@ def testCalculateChangedDeps(self):
BUILD_NEW_REV)
changed_deps = CalculateChangedDeps(webrtc_deps, new_cr_deps)

self.assertEqual(len(changed_deps), 3)
self.assertEqual(changed_deps[0].path, 'src/build')
self.assertEqual(changed_deps[0].current_rev, BUILD_OLD_REV)
self.assertEqual(changed_deps[0].new_rev, BUILD_NEW_REV)

self.assertEqual(changed_deps[1].path, 'src/buildtools/linux64')
self.assertEqual(changed_deps[1].package, 'gn/gn/linux-amd64')
self.assertEqual(changed_deps[1].current_version,
self.assertEqual(len(changed_deps), 4)
self.assertEqual(changed_deps[0].path, 'fuchsia')
self.assertEqual(changed_deps[0].current_version, 'version:10.20221201.3.1')
self.assertEqual(changed_deps[0].new_version, 'version:11.20230207.1.1')

self.assertEqual(changed_deps[1].path, 'src/build')
self.assertEqual(changed_deps[1].current_rev, BUILD_OLD_REV)
self.assertEqual(changed_deps[1].new_rev, BUILD_NEW_REV)

self.assertEqual(changed_deps[2].path, 'src/buildtools/linux64')
self.assertEqual(changed_deps[2].package, 'gn/gn/linux-amd64')
self.assertEqual(changed_deps[2].current_version,
'git_revision:69ec4fca1fa69ddadae13f9e6b7507efa0675263')
self.assertEqual(changed_deps[1].new_version, 'git_revision:new-revision')
self.assertEqual(changed_deps[2].new_version, 'git_revision:new-revision')

self.assertEqual(changed_deps[2].path, 'src/third_party/depot_tools')
self.assertEqual(changed_deps[2].current_rev, DEPOTTOOLS_OLD_REV)
self.assertEqual(changed_deps[2].new_rev, DEPOTTOOLS_NEW_REV)
self.assertEqual(changed_deps[3].path, 'src/third_party/depot_tools')
self.assertEqual(changed_deps[3].current_rev, DEPOTTOOLS_OLD_REV)
self.assertEqual(changed_deps[3].new_rev, DEPOTTOOLS_NEW_REV)

def testWithDistinctDeps(self):
"""Check CalculateChangedDeps works when deps are added/removed."""
Expand Down Expand Up @@ -252,8 +256,9 @@ def testMissingDepsIsDetected(self):
webrtc_deps = ParseLocalDepsFile(self._webrtc_depsfile)
new_cr_deps = ParseLocalDepsFile(self._new_cr_depsfile_android)
_, other_paths = FindRemovedDeps(webrtc_deps, new_cr_deps)
self.assertEqual(other_paths,
['src/buildtools/linux64', 'src/third_party/depot_tools'])
self.assertEqual(
other_paths,
['fuchsia', 'src/buildtools/linux64', 'src/third_party/depot_tools'])

def testExpectedDepsIsNotReportedMissing(self):
"""Some deps musn't be seen as missing, even if absent from Chromium."""
Expand Down
1 change: 1 addition & 0 deletions tools_webrtc/autoroller/unittests/testdata/roll_deps/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
vars = {
'chromium_git': 'https://chromium.googlesource.com',
'chromium_revision': '1b9c098a08e40114e44b6c1ec33ddf95c40b901d',
'fuchsia_version': 'version:10.20221201.3.1',
}

deps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ vars = {

# This is updated compared to the DEPS file.
'depot_tools_revision': '1206a353e40abb70d8454eb9af53db0ad10b713c',
'fuchsia_version': 'version:11.20230207.1.1',
}

deps = {
Expand Down

0 comments on commit e8ac5af

Please sign in to comment.