Commit a16ccaf1 authored by Aaron Gable's avatar Aaron Gable Committed by Commit Bot

bot_update: use patch repo instead of project if it is mapped

This is a step away from patch_project, which was a holdover
from Rietveld. Instead of mapping "projects" (which are
poorly-defined and not guaranteed to be unique) to subpaths,
instead map repository urls (which are at least unique).

Eventually we may be able to compute this directly from DEPS
instead of hardcoding the mapping here, but at least this is
a step in the right direction.

Bug: 765633
Change-Id: Idd65984fc6edefcbedb0438d38c2338b10b7e8e5
Reviewed-on: https://chromium-review.googlesource.com/690776
Commit-Queue: Aaron Gable <agable@chromium.org>
Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
parent 2da7cbd7
...@@ -227,17 +227,19 @@ Wrapper for easy calling of gclient steps. ...@@ -227,17 +227,19 @@ Wrapper for easy calling of gclient steps.
Remove all index.lock files. If a previous run of git crashed, bot was Remove all index.lock files. If a previous run of git crashed, bot was
reset, etc... we might end up with leftover index.lock files. reset, etc... we might end up with leftover index.lock files.
&mdash; **def [calculate\_patch\_root](/recipes/recipe_modules/gclient/api.py#309)(self, patch_project, gclient_config=None):** &mdash; **def [calculate\_patch\_root](/recipes/recipe_modules/gclient/api.py#309)(self, patch_project, gclient_config=None, patch_repo=None):**
Returns path where a patch should be applied to based patch_project. Returns path where a patch should be applied to based patch_project.
Maps "patch_project" to a path of directories relative to checkout's root, Maps the patch's repo to a path of directories relative to checkout's root,
which describe where to place the patch. which describe where to place the patch. If no mapping is found for the
repo url, falls back to trying to find a mapping for the old-style
"patch_project".
For now, considers only first solution (c.solutions[0]), but in theory can For now, considers only first solution (c.solutions[0]), but in theory can
be extended to all of them. be extended to all of them.
See patch_projects solution config property. See patch_projects and repo_path_map solution config property.
Returns: Returns:
Relative path, including solution's root. Relative path, including solution's root.
...@@ -283,7 +285,7 @@ Chromium config. This may happen for one of two reasons: ...@@ -283,7 +285,7 @@ Chromium config. This may happen for one of two reasons:
&mdash; **def [runhooks](/recipes/recipe_modules/gclient/api.py#268)(self, args=None, name='runhooks', \*\*kwargs):** &mdash; **def [runhooks](/recipes/recipe_modules/gclient/api.py#268)(self, args=None, name='runhooks', \*\*kwargs):**
&mdash; **def [set\_patch\_project\_revision](/recipes/recipe_modules/gclient/api.py#336)(self, patch_project, gclient_config=None):** &mdash; **def [set\_patch\_project\_revision](/recipes/recipe_modules/gclient/api.py#341)(self, patch_project, gclient_config=None):**
Updates config revision corresponding to patch_project. Updates config revision corresponding to patch_project.
...@@ -780,7 +782,7 @@ like checkout or compile), and some of these tests have failed. ...@@ -780,7 +782,7 @@ like checkout or compile), and some of these tests have failed.
[DEPS](/recipes/recipe_modules/gclient/tests/patch_project.py#9): [gclient](#recipe_modules-gclient), [recipe\_engine/properties][recipe_engine/recipe_modules/properties] [DEPS](/recipes/recipe_modules/gclient/tests/patch_project.py#9): [gclient](#recipe_modules-gclient), [recipe\_engine/properties][recipe_engine/recipe_modules/properties]
&mdash; **def [RunSteps](/recipes/recipe_modules/gclient/tests/patch_project.py#20)(api, patch_project):** &mdash; **def [RunSteps](/recipes/recipe_modules/gclient/tests/patch_project.py#21)(api, patch_project, patch_repository_url):**
### *recipes* / [gerrit:examples/full](/recipes/recipe_modules/gerrit/examples/full.py) ### *recipes* / [gerrit:examples/full](/recipes/recipe_modules/gerrit/examples/full.py)
[DEPS](/recipes/recipe_modules/gerrit/examples/full.py#5): [gerrit](#recipe_modules-gerrit), [recipe\_engine/step][recipe_engine/recipe_modules/step] [DEPS](/recipes/recipe_modules/gerrit/examples/full.py#5): [gerrit](#recipe_modules-gerrit), [recipe\_engine/step][recipe_engine/recipe_modules/step]
......
...@@ -109,7 +109,7 @@ class BotUpdateApi(recipe_api.RecipeApi): ...@@ -109,7 +109,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
root = patch_root root = patch_root
if root is None: if root is None:
root = self.m.gclient.calculate_patch_root( root = self.m.gclient.calculate_patch_root(
self.m.properties.get('patch_project'), cfg) self.m.properties.get('patch_project'), cfg, self._repository)
if patch: if patch:
issue = issue or self._issue issue = issue or self._issue
......
...@@ -33,6 +33,9 @@ def RunSteps(api): ...@@ -33,6 +33,9 @@ def RunSteps(api):
api.gclient.c.patch_projects['v8/v8'] = ('src/v8', 'HEAD') api.gclient.c.patch_projects['v8/v8'] = ('src/v8', 'HEAD')
api.gclient.c.patch_projects['angle/angle'] = ('src/third_party/angle', api.gclient.c.patch_projects['angle/angle'] = ('src/third_party/angle',
'HEAD') 'HEAD')
api.gclient.c.repo_path_map['https://webrtc.googlesource.com/src'] = (
'src/third_party/webrtc', 'HEAD')
patch = api.properties.get('patch', True) patch = api.properties.get('patch', True)
clobber = True if api.properties.get('clobber') else False clobber = True if api.properties.get('clobber') else False
no_shallow = True if api.properties.get('no_shallow') else False no_shallow = True if api.properties.get('no_shallow') else False
...@@ -233,3 +236,9 @@ def GenTests(api): ...@@ -233,3 +236,9 @@ def GenTests(api):
'event.patchSet.ref': 'refs/changes/11/338811/3', 'event.patchSet.ref': 'refs/changes/11/338811/3',
} }
) )
yield api.test('tryjob_gerrit_webrtc') + api.properties.tryserver(
gerrit_project='src',
git_url='https://webrtc.googlesource.com/src',
patch_issue=338811,
patch_set=3,
)
...@@ -306,16 +306,19 @@ class GclientApi(recipe_api.RecipeApi): ...@@ -306,16 +306,19 @@ class GclientApi(recipe_api.RecipeApi):
infra_step=True, infra_step=True,
) )
def calculate_patch_root(self, patch_project, gclient_config=None): def calculate_patch_root(self, patch_project, gclient_config=None,
patch_repo=None):
"""Returns path where a patch should be applied to based patch_project. """Returns path where a patch should be applied to based patch_project.
Maps "patch_project" to a path of directories relative to checkout's root, Maps the patch's repo to a path of directories relative to checkout's root,
which describe where to place the patch. which describe where to place the patch. If no mapping is found for the
repo url, falls back to trying to find a mapping for the old-style
"patch_project".
For now, considers only first solution (c.solutions[0]), but in theory can For now, considers only first solution (c.solutions[0]), but in theory can
be extended to all of them. be extended to all of them.
See patch_projects solution config property. See patch_projects and repo_path_map solution config property.
Returns: Returns:
Relative path, including solution's root. Relative path, including solution's root.
...@@ -323,15 +326,17 @@ class GclientApi(recipe_api.RecipeApi): ...@@ -323,15 +326,17 @@ class GclientApi(recipe_api.RecipeApi):
solution root. solution root.
""" """
cfg = gclient_config or self.c cfg = gclient_config or self.c
root, _ = cfg.patch_projects.get(patch_project, ('', '')) root, _ = cfg.repo_path_map.get(patch_repo, ('', ''))
if root: if not root:
# Note, that c.patch_projects contains patch roots as root, _ = cfg.patch_projects.get(patch_project, ('', ''))
# slash(/)-separated path, which are roots of the respective project repos if not root:
# and include actual solution name in them. # Failure case - assume patch is for first solution, as this is what most
return self.m.path.join(*root.split('/')) # projects rely on.
# Default case - assume patch is for first solution, as this is what most return cfg.solutions[0].name
# projects rely on. # Note, that c.patch_projects contains patch roots as
return cfg.solutions[0].name # slash(/)-separated path, which are roots of the respective project repos
# and include actual solution name in them.
return self.m.path.join(*root.split('/'))
def set_patch_project_revision(self, patch_project, gclient_config=None): def set_patch_project_revision(self, patch_project, gclient_config=None):
"""Updates config revision corresponding to patch_project. """Updates config revision corresponding to patch_project.
......
...@@ -81,6 +81,8 @@ def BaseConfig(USE_MIRROR=True, CACHE_DIR=None, ...@@ -81,6 +81,8 @@ def BaseConfig(USE_MIRROR=True, CACHE_DIR=None,
# then a patch to Angle project can be applied to a chromium src's # then a patch to Angle project can be applied to a chromium src's
# checkout after first updating Angle's repo to its master's HEAD. # checkout after first updating Angle's repo to its master's HEAD.
patch_projects = Dict(value_type=tuple, hidden=True), patch_projects = Dict(value_type=tuple, hidden=True),
# Same as the above, except the keys are full repo URLs.
repo_path_map = Dict(value_type=tuple, hidden=True),
# Check out refs/branch-heads. # Check out refs/branch-heads.
# TODO (machenbach): Only implemented for bot_update atm. # TODO (machenbach): Only implemented for bot_update atm.
......
...@@ -13,20 +13,24 @@ DEPS = [ ...@@ -13,20 +13,24 @@ DEPS = [
PROPERTIES = { PROPERTIES = {
'patch_project': recipe_api.Property(), 'patch_project': recipe_api.Property(None),
'patch_repository_url': recipe_api.Property(None),
} }
def RunSteps(api, patch_project): def RunSteps(api, patch_project, patch_repository_url):
src_cfg = api.gclient.make_config(CACHE_DIR='[ROOT]/git_cache') src_cfg = api.gclient.make_config(CACHE_DIR='[ROOT]/git_cache')
soln = src_cfg.solutions.add() soln = src_cfg.solutions.add()
soln.name = 'src' soln.name = 'src'
soln.url = 'https://chromium.googlesource.com/chromium/src.git' soln.url = 'https://chromium.googlesource.com/chromium/src.git'
src_cfg.patch_projects['v8'] = ('src/v8', 'HEAD') src_cfg.patch_projects['v8'] = ('src/v8', 'HEAD')
src_cfg.patch_projects['v8/v8'] = ('src/v8', 'HEAD') src_cfg.patch_projects['v8/v8'] = ('src/v8', 'HEAD')
src_cfg.repo_path_map['https://webrtc.googlesource.com'] = (
'src/third_party/webrtc', 'HEAD')
api.gclient.c = src_cfg api.gclient.c = src_cfg
patch_root = api.gclient.calculate_patch_root(patch_project) patch_root = api.gclient.calculate_patch_root(
patch_project, None, patch_repository_url)
api.gclient.set_patch_project_revision(patch_project) api.gclient.set_patch_project_revision(patch_project)
...@@ -43,3 +47,10 @@ def GenTests(api): ...@@ -43,3 +47,10 @@ def GenTests(api):
api.properties(patch_project='v8') + api.properties(patch_project='v8') +
api.post_process(post_process.DropExpectation) api.post_process(post_process.DropExpectation)
) )
yield (
api.test('webrtc') +
api.properties(
patch_repository_url='https://webrtc.googlesource.com/src') +
api.post_process(post_process.DropExpectation)
)
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