From 93f69da3b2e4e2bb6c612008c2732184865eec24 Mon Sep 17 00:00:00 2001 From: Michael Achenbach Date: Fri, 21 Apr 2017 15:39:09 +0200 Subject: [PATCH] Support merging got_revision mappings during transition phase. A few rare recipes use two or more solutions side-by-side. This allows switching one solution in isolation to use the new mapping. Bug: 713356 Change-Id: Id51f2f777681401843004577a4de65a6c5d1e4a6 Reviewed-on: https://chromium-review.googlesource.com/484341 Commit-Queue: Andrii Shyshkalov Reviewed-by: Andrii Shyshkalov --- recipes/recipe_modules/bot_update/api.py | 20 ++++---------------- recipes/recipe_modules/gclient/api.py | 18 ++++++++++++++++++ recipes/recipe_modules/gclient/example.py | 2 ++ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/recipes/recipe_modules/bot_update/api.py b/recipes/recipe_modules/bot_update/api.py index 3ee464c9c..69b01bbe5 100644 --- a/recipes/recipe_modules/bot_update/api.py +++ b/recipes/recipe_modules/bot_update/api.py @@ -171,17 +171,7 @@ class BotUpdateApi(recipe_api.RecipeApi): self.m.gclient.set_patch_project_revision( self.m.properties.get('patch_project'), cfg) - # TODO(machenbach): Deprecate rev_map. We'll do a three-way dance. - # When all users of got_revision_mapping use got_revision_reverse_mapping - # we can remove the old one. Make sure nobody uses both. - rev_map = cfg.got_revision_mapping.as_jsonish() - reverse_rev_map = cfg.got_revision_reverse_mapping.as_jsonish() - assert not rev_map or not reverse_rev_map - if rev_map: - reverse_rev_map = {v: k for k, v in rev_map.iteritems()} - - # Make sure we never have duplicate values in the old map. - assert len(rev_map) == len(reverse_rev_map) + reverse_rev_map = self.m.gclient.got_revision_reverse_mapping(cfg) flags = [ # What do we want to check out (spec/root/rev/reverse_rev_map). @@ -378,15 +368,13 @@ class BotUpdateApi(recipe_api.RecipeApi): Returns (list of str): All properties that'll hold the checked-out revision of the given project. An empty list if no such properties exist. """ - cfg = self.m.gclient.c - if cfg.got_revision_mapping: - prop = cfg.got_revision_mapping.get(project_name) - return [prop] if prop else [] # Sort for determinism. We might have several properties for the same # project, e.g. got_revision and got_webrtc_revision. + rev_reverse_map = self.m.gclient.got_revision_reverse_mapping( + self.m.gclient.c) return sorted( prop - for prop, project in cfg.got_revision_reverse_mapping.iteritems() + for prop, project in rev_reverse_map.iteritems() if project == project_name ) diff --git a/recipes/recipe_modules/gclient/api.py b/recipes/recipe_modules/gclient/api.py index 744f95233..cda984a46 100644 --- a/recipes/recipe_modules/gclient/api.py +++ b/recipes/recipe_modules/gclient/api.py @@ -126,6 +126,24 @@ class GclientApi(recipe_api.RecipeApi): def config_to_pythonish(cfg): return jsonish_to_python(cfg.as_jsonish(), True) + # TODO(machenbach): Remove this method when the old mapping is deprecated. + @staticmethod + def got_revision_reverse_mapping(cfg): + """Returns the merged got_revision_reverse_mapping. + + Returns (dict): A mapping from property name -> project name. It merges the + values of the deprecated got_revision_mapping and the new + got_revision_reverse_mapping. + """ + rev_map = cfg.got_revision_mapping.as_jsonish() + reverse_rev_map = cfg.got_revision_reverse_mapping.as_jsonish() + combined_length = len(rev_map) + len(reverse_rev_map) + reverse_rev_map.update({v: k for k, v in rev_map.iteritems()}) + + # Make sure we never have duplicate values in the old map. + assert combined_length == len(reverse_rev_map) + return reverse_rev_map + def resolve_revision(self, revision): if hasattr(revision, 'resolve'): return revision.resolve(self.m.properties) diff --git a/recipes/recipe_modules/gclient/example.py b/recipes/recipe_modules/gclient/example.py index a7fd46309..43aaaf40c 100644 --- a/recipes/recipe_modules/gclient/example.py +++ b/recipes/recipe_modules/gclient/example.py @@ -86,6 +86,8 @@ def RunSteps(api): gclient_config=bl_cfg, with_branch_heads=True) + api.gclient.got_revision_reverse_mapping(bl_cfg) + api.gclient.break_locks() del api.gclient.spec_alias