Explorar o código

Return out_commit from bot_update.ensure_checkout.

out_commit is parsed from got_revision even when set_output_commit is False. This allows for the calling code to implement its own logic for setting output commit, but still use the commit from bot_update if needed.

Example of usage: https://crrev.com/c/6049557.

Bug: 366409421
Change-Id: I49ce89730fe780d7561077f82797b30fad87e65e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6049353
Reviewed-by: Garrett Beaty <gbeaty@google.com>
Commit-Queue: Alex Kravchuk <alexanderkr@google.com>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Alex Kravchuk hai 8 meses
pai
achega
297f5a341c
Modificáronse 2 ficheiros con 19 adicións e 13 borrados
  1. 8 8
      recipes/README.recipes.md
  2. 11 5
      recipes/recipe_modules/bot_update/api.py

+ 8 - 8
recipes/README.recipes.md

@@ -58,18 +58,18 @@
 
 
 Recipe module to ensure a checkout is consistent on a bot.
 Recipe module to ensure a checkout is consistent on a bot.
 
 
-#### **class [BotUpdateApi](/recipes/recipe_modules/bot_update/api.py#71)([RecipeApi][recipe_engine/wkt/RecipeApi]):**
+#### **class [BotUpdateApi](/recipes/recipe_modules/bot_update/api.py#74)([RecipeApi][recipe_engine/wkt/RecipeApi]):**
 
 
-&mdash; **def [\_\_call\_\_](/recipes/recipe_modules/bot_update/api.py#80)(self, name, cmd, \*\*kwargs):**
+&mdash; **def [\_\_call\_\_](/recipes/recipe_modules/bot_update/api.py#83)(self, name, cmd, \*\*kwargs):**
 
 
 Wrapper for easy calling of bot_update.
 Wrapper for easy calling of bot_update.
 
 
-&mdash; **def [deapply\_patch](/recipes/recipe_modules/bot_update/api.py#674)(self, bot_update_result):**
+&mdash; **def [deapply\_patch](/recipes/recipe_modules/bot_update/api.py#680)(self, bot_update_result):**
 
 
 Deapplies a patch, taking care of DEPS and solution revisions properly.
 Deapplies a patch, taking care of DEPS and solution revisions properly.
     
     
 
 
-&mdash; **def [ensure\_checkout](/recipes/recipe_modules/bot_update/api.py#191)(self, gclient_config=None, suffix=None, patch=True, update_presentation=True, patch_root=None, with_branch_heads=False, with_tags=False, no_fetch_tags=False, refs=None, clobber=False, root_solution_revision=None, gerrit_no_reset=False, gerrit_no_rebase_patch_ref=False, assert_one_gerrit_change=True, patch_refs=None, ignore_input_commit=False, add_blamelists=False, set_output_commit=False, step_test_data=None, enforce_fetch=False, download_topics=False, recipe_revision_overrides=None, step_tags=None, \*\*kwargs):**
+&mdash; **def [ensure\_checkout](/recipes/recipe_modules/bot_update/api.py#194)(self, gclient_config=None, suffix=None, patch=True, update_presentation=True, patch_root=None, with_branch_heads=False, with_tags=False, no_fetch_tags=False, refs=None, clobber=False, root_solution_revision=None, gerrit_no_reset=False, gerrit_no_rebase_patch_ref=False, assert_one_gerrit_change=True, patch_refs=None, ignore_input_commit=False, add_blamelists=False, set_output_commit=False, step_test_data=None, enforce_fetch=False, download_topics=False, recipe_revision_overrides=None, step_tags=None, \*\*kwargs):**
 
 
 Args:
 Args:
   * gclient_config: The gclient configuration to use when running bot_update.
   * gclient_config: The gclient configuration to use when running bot_update.
@@ -106,7 +106,7 @@ Args:
     author.
     author.
   * step_tags: a dict {tag name: tag value} of tags to add to the step
   * step_tags: a dict {tag name: tag value} of tags to add to the step
 
 
-&mdash; **def [get\_project\_revision\_properties](/recipes/recipe_modules/bot_update/api.py#651)(self, project_name, gclient_config=None):**
+&mdash; **def [get\_project\_revision\_properties](/recipes/recipe_modules/bot_update/api.py#657)(self, project_name, gclient_config=None):**
 
 
 Returns all property names used for storing the checked-out revision of
 Returns all property names used for storing the checked-out revision of
 a given project.
 a given project.
@@ -120,14 +120,14 @@ Args:
 Returns (list of str): All properties that'll hold the checked-out revision
 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.
     of the given project. An empty list if no such properties exist.
 
 
-&emsp; **@property**<br>&mdash; **def [last\_returned\_properties](/recipes/recipe_modules/bot_update/api.py#99)(self):**
+&emsp; **@property**<br>&mdash; **def [last\_returned\_properties](/recipes/recipe_modules/bot_update/api.py#102)(self):**
 
 
-&mdash; **def [resolve\_fixed\_revision](/recipes/recipe_modules/bot_update/api.py#602)(self, bot_update_result, name):**
+&mdash; **def [resolve\_fixed\_revision](/recipes/recipe_modules/bot_update/api.py#608)(self, bot_update_result, name):**
 
 
 Sets a fixed revision for a single dependency using project revision
 Sets a fixed revision for a single dependency using project revision
 properties.
 properties.
 
 
-&mdash; **def [step\_name](/recipes/recipe_modules/bot_update/api.py#691)(self, patch, suffix):**
+&mdash; **def [step\_name](/recipes/recipe_modules/bot_update/api.py#697)(self, patch, suffix):**
 ### *recipe_modules* / [depot\_tools](/recipes/recipe_modules/depot_tools)
 ### *recipe_modules* / [depot\_tools](/recipes/recipe_modules/depot_tools)
 
 
 [DEPS](/recipes/recipe_modules/depot_tools/__init__.py#7): [recipe\_engine/cipd][recipe_engine/recipe_modules/cipd], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/runtime][recipe_engine/recipe_modules/runtime]
 [DEPS](/recipes/recipe_modules/depot_tools/__init__.py#7): [recipe\_engine/cipd][recipe_engine/recipe_modules/cipd], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/runtime][recipe_engine/recipe_modules/runtime]

+ 11 - 5
recipes/recipe_modules/bot_update/api.py

@@ -56,6 +56,7 @@ class Result:
       repository and revision that was checked out.
       repository and revision that was checked out.
     fixed_revisions: The explicitly requested revisions; a mapping from the
     fixed_revisions: The explicitly requested revisions; a mapping from the
       checkout_dir-relative path to the requested revision.
       checkout_dir-relative path to the requested revision.
+    out_commit: Gitiles output commit derived from got_revision.
   """
   """
   # Directories relevant to the checkout
   # Directories relevant to the checkout
   checkout_dir: Path
   checkout_dir: Path
@@ -67,6 +68,8 @@ class Result:
   manifest: dict[str, ManifestRepo]
   manifest: dict[str, ManifestRepo]
   fixed_revisions: dict[str, str]
   fixed_revisions: dict[str, str]
 
 
+  out_commit: common_pb2.GitilesCommit | None
+
 
 
 class BotUpdateApi(recipe_api.RecipeApi):
 class BotUpdateApi(recipe_api.RecipeApi):
 
 
@@ -501,10 +504,10 @@ class BotUpdateApi(recipe_api.RecipeApi):
             blamelist_pins.append(pin)
             blamelist_pins.append(pin)
           self.m.milo.show_blamelist_for(blamelist_pins)
           self.m.milo.show_blamelist_for(blamelist_pins)
 
 
-        # Set output commit of the build.
-        if (set_output_commit and
-            'got_revision' in self._last_returned_properties and
-            'got_revision' in reverse_rev_map):
+        out_commit = None
+
+        if ('got_revision' in self._last_returned_properties
+            and 'got_revision' in reverse_rev_map):
           # As of April 2019, got_revision describes the output commit,
           # As of April 2019, got_revision describes the output commit,
           # the same commit that Build.output.gitiles_commit describes.
           # the same commit that Build.output.gitiles_commit describes.
           # In particular, users tend to set got_revision to make Milo display
           # In particular, users tend to set got_revision to make Milo display
@@ -546,7 +549,9 @@ class BotUpdateApi(recipe_api.RecipeApi):
                 'Unsupported case. '
                 'Unsupported case. '
                 'Call buildbucket.set_output_gitiles_commit directly.'
                 'Call buildbucket.set_output_gitiles_commit directly.'
             )
             )
-          self.m.buildbucket.set_output_gitiles_commit(out_commit)
+
+          if set_output_commit:
+            self.m.buildbucket.set_output_gitiles_commit(out_commit)
 
 
         # Set the "checkout" path for the main solution.
         # Set the "checkout" path for the main solution.
         # This is used by the Chromium module to figure out where to look for
         # This is used by the Chromium module to figure out where to look for
@@ -570,6 +575,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
         properties=result.get('properties', {}),
         properties=result.get('properties', {}),
         manifest=result.get('manifest', {}),
         manifest=result.get('manifest', {}),
         fixed_revisions=result.get('fixed_revisions', {}),
         fixed_revisions=result.get('fixed_revisions', {}),
+        out_commit=out_commit,
     )
     )
 
 
   def _destination_ref(self, cfg, path):
   def _destination_ref(self, cfg, path):