Bug 1512188 - Consolidate VCS checkout from args logic; r=tomprince,dustin
authorGregory Szorc <gps@mozilla.com>
Mon, 31 Dec 2018 18:50:34 +0000
changeset 509323 6d8260b9f12f702f7be273620204f85f6c75d092
parent 509322 a0d4382b904b0cbd9fc152c8b53b120fed317ea3
child 509324 807f9818930a9992834f1770bd2fa10147019c81
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstomprince, dustin
bugs1512188
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1512188 - Consolidate VCS checkout from args logic; r=tomprince,dustin We create a minimal wrapper function to call collect_vcs_options() and vcs_checkout(). We could consolidate this logic into vcs_checkout(). But I don't have strong feelings about doing that. Differential Revision: https://phabricator.services.mozilla.com/D13821
taskcluster/scripts/run-task
--- a/taskcluster/scripts/run-task
+++ b/taskcluster/scripts/run-task
@@ -535,25 +535,46 @@ def collect_vcs_options(args, project):
     # reasons. Switch to mozilla-unified because robustcheckout works best
     # with it.
     if base_repo == 'https://hg.mozilla.org/mozilla-central':
         base_repo = 'https://hg.mozilla.org/mozilla-unified'
 
     return {
         'store-path': store_path,
         'project': project,
+        'env-prefix': env_prefix,
         'checkout': checkout,
         'sparse-profile': sparse_profile,
         'base-repo': base_repo,
         'head-repo': head_repo,
         'revision': revision,
         'branch': branch,
     }
 
 
+def vcs_checkout_from_args(args, project):
+    options = collect_vcs_options(args, project)
+
+    if not options['checkout']:
+        if options['branch'] and not options['revision']:
+            print('task should be defined in terms of non-symbolic revision')
+            sys.exit(1)
+        return
+
+    os.environ['%s_HEAD_REV' % options['env-prefix']] = vcs_checkout(
+        options['head-repo'],
+        options['checkout'],
+        options['store-path'],
+        base_repo=options['base-repo'],
+        revision=options['revision'],
+        fetch_hgfingerprint=args.fetch_hgfingerprint,
+        branch=options['branch'],
+        sparse_profile=options['sparse-profile'])
+
+
 def main(args):
     print_line(b'setup', b'run-task started in %s\n' % os.getcwd().encode('utf-8'))
     running_as_root = IS_POSIX and os.getuid() == 0
 
     # Arguments up to '--' are ours. After are for the main task
     # to be executed.
     try:
         i = args.index('--')
@@ -717,54 +738,18 @@ def main(args):
         print_line(b'setup', b'running as %s:%s\n' % (
             args.user.encode('utf-8'), args.group.encode('utf-8')))
 
         os.setgroups(gids)
         os.umask(0o22)
         os.setresgid(gid, gid, gid)
         os.setresuid(uid, uid, uid)
 
-    # Checkout the repository, setting the GECKO_HEAD_REV to the current
-    # revision hash. Revision hashes have priority over symbolic revisions. We
-    # disallow running tasks with symbolic revisions unless they have been
-    # resolved by a checkout.
-    gecko_options = collect_vcs_options(args, 'gecko')
-
-    if gecko_options['checkout']:
-        os.environ['GECKO_HEAD_REV'] = vcs_checkout(
-            gecko_options['head-repo'],
-            gecko_options['checkout'],
-            gecko_options['store-path'],
-            fetch_hgfingerprint=args.fetch_hgfingerprint,
-            base_repo=gecko_options['base-repo'],
-            revision=gecko_options['revision'],
-            branch=gecko_options['branch'],
-            sparse_profile=gecko_options['sparse-profile'])
-    elif gecko_options['branch'] and not gecko_options['revision']:
-        print('task should be defined in terms of non-symbolic revision')
-        return 1
-
-    # Checkout the repository, setting the COMM_HEAD_REV to the current
-    # revision hash. Revision hashes have priority over symbolic revisions. We
-    # disallow running tasks with symbolic revisions unless they have been
-    # resolved by a checkout.
-    comm_options = collect_vcs_options(args, 'comm')
-    if comm_options['checkout']:
-        os.environ['COMM_HEAD_REV'] = vcs_checkout(
-            comm_options['head-repo'],
-            comm_options['checkout'],
-            comm_options['store-path'],
-            fetch_hgfingerprint=args.fetch_hgfingerprint,
-            base_repo=comm_options['base-repo'],
-            revision=comm_options['revision'],
-            branch=comm_options['branch'],
-            sparse_profile=comm_options['sparse-profile'])
-    elif comm_options['branch'] and not comm_options['revision']:
-        print('task should be defined in terms of non-symbolic revision')
-        return 1
+    vcs_checkout_from_args(args, 'gecko')
+    vcs_checkout_from_args(args, 'comm')
 
     try:
         if 'GECKO_PATH' in os.environ:
             os.environ['GECKO_PATH'] = os.path.abspath(os.environ['GECKO_PATH'])
 
         if 'MOZ_FETCHES' in os.environ:
             fetch_artifacts()