Bug 1512188 - make VCS checkout options generic; r=tomprince,dustin
authorGregory Szorc <gps@mozilla.com>
Mon, 31 Dec 2018 18:52:30 +0000
changeset 509319 315bb83dabea111b7620b3c8ddb0b50d47c17052
parent 509318 6e13c0c6c7c1fc5d45358c707e582726ec94b857
child 509320 0af08435172d476b85c57f2c64eb652497594c0e
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 - make VCS checkout options generic; r=tomprince,dustin We currently manage VCS checkout arguments as one-offs for each project. This isn't scalable and results in a bit of copy-pasta. Let's make the VCS checkout arguments generic so we can have the same control for all repositories. This commit focuses on consolidating the existing argument parser code. It stops short of further unification, which will be done in subsequent commits. Differential Revision: https://phabricator.services.mozilla.com/D13815
taskcluster/scripts/run-task
--- a/taskcluster/scripts/run-task
+++ b/taskcluster/scripts/run-task
@@ -497,16 +497,40 @@ def fetch_artifacts():
         print(FETCH_CONTENT_NOT_FOUND)
         sys.exit(1)
 
     cmd = [fetch_content, 'task-artifacts']
     subprocess.run(cmd, check=True, env=os.environ)
     print_line(b'fetches', b'finished fetching artifacts\n')
 
 
+def add_vcs_arguments(parser, project, name):
+    """Adds arguments to ArgumentParser to control VCS options for a project."""
+
+    parser.add_argument('--%s-checkout' % project,
+                        help='Directory where %s checkout should be created' %
+                             name)
+    parser.add_argument('--%s-sparse-profile' % project,
+                        help='Path to sparse profile for %s checkout' % name)
+
+
+def collect_vcs_options(args, project):
+    checkout = getattr(args, '%s_checkout' % project)
+    sparse_profile = getattr(args, '%s_sparse_profile' % project)
+
+    if checkout:
+        checkout = os.path.expanduser(checkout)
+
+    return {
+        'project': project,
+        'checkout': checkout,
+        'sparse-profile': 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('--')
@@ -514,31 +538,27 @@ def main(args):
         task_args = args[i + 1:]
     except ValueError:
         our_args = args
         task_args = []
 
     parser = argparse.ArgumentParser()
     parser.add_argument('--user', default='worker', help='user to run as')
     parser.add_argument('--group', default='worker', help='group to run as')
-    parser.add_argument('--gecko-checkout',
-                        help='Directory where Gecko checkout should be created')
-    parser.add_argument('--gecko-sparse-profile',
-                        help='Path to sparse checkout profile to use')
-    parser.add_argument('--comm-checkout',
-                        help='Directory where Comm checkout should be created')
+
+    add_vcs_arguments(parser, 'gecko', 'Firefox')
+    add_vcs_arguments(parser, 'comm', 'Comm')
+
     parser.add_argument('--fetch-hgfingerprint', action='store_true',
                         help='Fetch the latest hgfingerprint from the secrets store, '
                         'using the taskclsuerProxy')
 
     args = parser.parse_args(our_args)
 
     # expand ~ in some paths
-    if args.gecko_checkout:
-        args.gecko_checkout = os.path.expanduser(args.gecko_checkout)
     if 'HG_STORE_PATH' in os.environ:
         os.environ['HG_STORE_PATH'] = os.path.expanduser(os.environ['HG_STORE_PATH'])
 
     uid = gid = gids = None
     if IS_POSIX and running_as_root:
         user, group, gids = get_posix_user_group(args.user, args.group)
         uid = user.pw_uid
         gid = group.gr_gid
@@ -682,54 +702,58 @@ def main(args):
         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.
-    if args.gecko_checkout:
+    gecko_options = collect_vcs_options(args, 'gecko')
+
+    if gecko_options['checkout']:
         base_repo = os.environ.get('GECKO_BASE_REPOSITORY')
         # Some callers set the base repository to mozilla-central for historical
         # 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'
 
         os.environ['GECKO_HEAD_REV'] = vcs_checkout(
             os.environ['GECKO_HEAD_REPOSITORY'],
-            args.gecko_checkout,
+            gecko_options['checkout'],
             os.environ['HG_STORE_PATH'],
             fetch_hgfingerprint=args.fetch_hgfingerprint,
             base_repo=base_repo,
             revision=os.environ.get('GECKO_HEAD_REV'),
             branch=os.environ.get('GECKO_HEAD_REF'),
-            sparse_profile=args.gecko_sparse_profile)
+            sparse_profile=gecko_options['sparse-profile'])
 
     elif not os.environ.get('GECKO_HEAD_REV') and \
             os.environ.get('GECKO_HEAD_REF'):
         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.
-    if args.comm_checkout:
+    comm_options = collect_vcs_options(args, 'comm')
+    if comm_options['checkout']:
         base_repo = os.environ.get('COMM_BASE_REPOSITORY')
 
         os.environ['COMM_HEAD_REV'] = vcs_checkout(
             os.environ['COMM_HEAD_REPOSITORY'],
-            args.comm_checkout,
+            comm_options['checkout'],
             os.environ['HG_STORE_PATH'],
             fetch_hgfingerprint=args.fetch_hgfingerprint,
             base_repo=base_repo,
             revision=os.environ.get('COMM_HEAD_REV'),
-            branch=os.environ.get('COMM_HEAD_REF'))
+            branch=os.environ.get('COMM_HEAD_REF'),
+            sparse_profile=comm_options['sparse-profile'])
 
     elif not os.environ.get('COMM_HEAD_REV') and \
             os.environ.get('COMM_HEAD_REF'):
         print('task should be defined in terms of non-symbolic revision')
         return 1
 
     try:
         if 'GECKO_PATH' in os.environ: