Bug 1245969 - Support fetching bootstrap files from an arbitrary revision draft
authorGregory Szorc <gps@mozilla.com>
Fri, 18 Nov 2016 16:07:48 -0800
changeset 441534 1dcd43dd2a7b04e2bb714349033a456ea5158f3e
parent 441533 3310a15cbefbe9d1f30b12cb4531db797e597e8c
child 441535 ecda3d4fd7b29ed1b35a284d8929bfde8195e54f
push id36442
push userbmo:gps@mozilla.com
push dateSat, 19 Nov 2016 01:00:57 +0000
bugs1245969
milestone53.0a1
Bug 1245969 - Support fetching bootstrap files from an arbitrary revision This is needed so we can test the bootstrapper on Try. MozReview-Commit-ID: B5SN26YIdaw
python/mozboot/bin/bootstrap.py
--- a/python/mozboot/bin/bootstrap.py
+++ b/python/mozboot/bin/bootstrap.py
@@ -51,24 +51,24 @@ def setup_proxy():
     # intended for all protocols. Python doesn't currently automatically
     # detect this like it does for http_proxy and https_proxy.
     if 'ALL_PROXY' in os.environ and 'https_proxy' not in os.environ:
         os.environ['https_proxy'] = os.environ['ALL_PROXY']
     if 'ALL_PROXY' in os.environ and 'http_proxy' not in os.environ:
         os.environ['http_proxy'] = os.environ['ALL_PROXY']
 
 
-def fetch_files(repo_url, repo_type):
+def fetch_files(repo_url, repo_rev, repo_type):
     setup_proxy()
     repo_url = repo_url.rstrip('/')
 
     files = {}
 
     if repo_type == 'hgweb':
-        url = repo_url + '/archive/default.zip/python/mozboot'
+        url = repo_url + '/archive/%s.zip/python/mozboot' % repo_rev
         req = urlopen(url=url, timeout=30)
         data = StringIO(req.read())
         data.seek(0)
         zip = zipfile.ZipFile(data, 'r')
         for f in zip.infolist():
             # The paths are prefixed with the repo and revision name before the
             # directory name.
             offset = f.filename.find(REPOSITORY_PATH_PREFIX) + len(REPOSITORY_PATH_PREFIX)
@@ -80,17 +80,17 @@ def fetch_files(repo_url, repo_type):
 
             files[name] = zip.read(f)
     else:
         raise NotImplementedError('Not sure how to handle repo type.', repo_type)
 
     return files
 
 
-def ensure_environment(repo_url=None, repo_type=None):
+def ensure_environment(repo_url=None, repo_rev=None, repo_type=None):
     """Ensure we can load the Python modules necessary to perform bootstrap."""
 
     try:
         from mozboot.bootstrap import Bootstrapper
         return Bootstrapper
     except ImportError:
         # The first fallback is to assume we are running from a tree checkout
         # and have the files in a sibling directory.
@@ -101,17 +101,17 @@ def ensure_environment(repo_url=None, re
         try:
             from mozboot.bootstrap import Bootstrapper
             return Bootstrapper
         except ImportError:
             sys.path.pop()
 
             # The next fallback is to download the files from the source
             # repository.
-            files = fetch_files(repo_url, repo_type)
+            files = fetch_files(repo_url, repo_rev, repo_type)
 
             # Install them into a temporary location. They will be deleted
             # after this script has finished executing.
             global TEMPDIR
             TEMPDIR = tempfile.mkdtemp()
 
             for relpath in files.keys():
                 destpath = os.path.join(TEMPDIR, relpath)
@@ -130,32 +130,36 @@ def ensure_environment(repo_url=None, re
 
 
 def main(args):
     parser = OptionParser()
     parser.add_option('-r', '--repo-url', dest='repo_url',
                       default='https://hg.mozilla.org/mozilla-central/',
                       help='Base URL of source control repository where bootstrap files can '
                       'be downloaded.')
+    parser.add_option('--repo-rev', dest='repo_rev',
+                      default='default',
+                      help='Revision of files in repository to fetch')
     parser.add_option('--repo-type', dest='repo_type',
                       default='hgweb',
                       help='The type of the repository. This defines how we fetch file '
                       'content. Like --repo, you should not need to set this.')
 
     parser.add_option('--application-choice', dest='application_choice',
                       help='Pass in an application choice (desktop/android) instead of using the '
                       'default interactive prompt.')
     parser.add_option('--no-interactive', dest='no_interactive', action='store_true',
                       help='Answer yes to any (Y/n) interactive prompts.')
 
     options, leftover = parser.parse_args(args)
 
     try:
         try:
-            cls = ensure_environment(options.repo_url, options.repo_type)
+            cls = ensure_environment(options.repo_url, options.repo_rev,
+                                     options.repo_type)
         except Exception as e:
             print('Could not load the bootstrap Python environment.\n')
             print('This should never happen. Consider filing a bug.\n')
             print('\n')
             print(e)
             return 1
         dasboot = cls(choice=options.application_choice, no_interactive=options.no_interactive)
         dasboot.bootstrap()