cbuildbot: Ensure release_tag is set before Report stage runs.

Even if the sync stage does not finish the release_tag run attribute
must be set before the Report stage runs.  This change ensures that by
calling _SetReleaseTag() again before the finally block which contains
the Report stage.

BUG=chromium:339123
TEST=buildbot/run_tests
TEST=cbuildbot --remote --debug --buildnumber=15486 \
  x86-alex-paladin

Change-Id: Ia21ab2f685e7e9a0e3b825c30f1a028edadabae5
Reviewed-on: https://chromium-review.googlesource.com/184380
Reviewed-by: David James <davidjames@chromium.org>
Commit-Queue: Matt Tennant <mtennant@chromium.org>
Tested-by: Matt Tennant <mtennant@chromium.org>
diff --git a/scripts/cbuildbot.py b/scripts/cbuildbot.py
index 862cc99..34d2643 100644
--- a/scripts/cbuildbot.py
+++ b/scripts/cbuildbot.py
@@ -168,10 +168,12 @@
   def _SetReleaseTag(self):
     """Sets the release tag from the manifest manager.
 
-    Must be run after sync stage as syncing enables us to have a release tag.
+    Must be run after sync stage as syncing enables us to have a release tag,
+    and must be run before any usage of attrs.release_tag.
 
     TODO(mtennant): Find a bottleneck place in syncing that can set this
-    directly.  Be careful, as there are several kinds of syncing stages.
+    directly.  Be careful, as there are several kinds of syncing stages, and
+    sync stages have been known to abort with sys.exit calls.
     """
     manifest_manager = getattr(self._run.attrs, 'manifest_manager', None)
     if manifest_manager:
@@ -193,6 +195,14 @@
     stage_instance = self._GetStageInstance(stage, *args, **kwargs)
     return stage_instance.Run()
 
+  def _RunSyncStage(self, sync_instance):
+    """Run given |sync_instance| stage and be sure attrs.release_tag set."""
+    try:
+      sync_instance.Run()
+    finally:
+      self._SetReleaseTag()
+
+
   def GetSyncInstance(self):
     """Returns an instance of a SyncStage that should be run.
 
@@ -314,8 +324,7 @@
     try:
       self.Initialize()
       sync_instance = self.GetSyncInstance()
-      sync_instance.Run()
-      self._SetReleaseTag()
+      self._RunSyncStage(sync_instance)
 
       if self._run.ShouldPatchAfterSync():
         # Filter out patches to manifest, since PatchChangesStage can't handle