Bug 1485117 - Make standalone bootstrap work without a git checkout. r=glandium
authorPanos Astithas <past@mozilla.com>
Tue, 26 Feb 2019 06:39:55 +0000
changeset 518920 9ff4aa05d88146da01176e4d3ec5a1ab9739a7e2
parent 518919 63242317442cedd9c5407b6fe5734c61036cb452
child 518921 7ae76ec6dad573ca4313bc1f117f88e1f5be3935
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1485117
milestone67.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 1485117 - Make standalone bootstrap work without a git checkout. r=glandium Differential Revision: https://phabricator.services.mozilla.com/D20426
python/mozboot/bin/bootstrap.py
python/mozboot/mozboot/bootstrap.py
--- a/python/mozboot/bin/bootstrap.py
+++ b/python/mozboot/bin/bootstrap.py
@@ -128,16 +128,20 @@ def ensure_environment(repo_url=None, re
             # This should always work.
             sys.path.append(TEMPDIR)
             from mozboot.bootstrap import Bootstrapper
             return Bootstrapper
 
 
 def main(args):
     parser = OptionParser()
+    parser.add_option('--vcs', dest='vcs',
+                      default='hg',
+                      help='VCS (hg or git) to use for downloading the source code. '
+                      'Uses hg if omitted.')
     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',
@@ -158,17 +162,18 @@ def main(args):
             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 = cls(choice=options.application_choice, no_interactive=options.no_interactive,
+                      vcs=options.vcs)
         dasboot.bootstrap()
 
         return 0
     finally:
         if TEMPDIR is not None:
             shutil.rmtree(TEMPDIR)
 
 
--- a/python/mozboot/mozboot/bootstrap.py
+++ b/python/mozboot/mozboot/bootstrap.py
@@ -230,23 +230,25 @@ def update_or_create_build_telemetry_con
         config.write(f)
     return True
 
 
 class Bootstrapper(object):
     """Main class that performs system bootstrap."""
 
     def __init__(self, finished=FINISHED, choice=None, no_interactive=False,
-                 hg_configure=False, no_system_changes=False, mach_context=None):
+                 hg_configure=False, no_system_changes=False, mach_context=None,
+                 vcs=None):
         self.instance = None
         self.finished = finished
         self.choice = choice
         self.hg_configure = hg_configure
         self.no_system_changes = no_system_changes
         self.mach_context = mach_context
+        self.vcs = vcs
         cls = None
         args = {'no_interactive': no_interactive,
                 'no_system_changes': no_system_changes}
 
         if sys.platform.startswith('linux'):
             distro, version, dist_id = platform.linux_distribution()
 
             if distro in ('CentOS', 'CentOS Linux', 'Fedora'):
@@ -447,32 +449,33 @@ class Bootstrapper(object):
 
         # We need to enable the loading of hgrc in case extensions are
         # required to open the repo.
         r = current_firefox_checkout(check_output=self.instance.check_output,
                                      env=self.instance._hg_cleanenv(load_hgrc=True),
                                      hg=self.instance.which('hg'))
         (checkout_type, checkout_root) = r
 
-        # Possibly configure Mercurial, but not if the current checkout is Git.
-        if hg_installed and state_dir_available and checkout_type != 'git':
+        # Possibly configure Mercurial, but not if the current checkout or repo
+        # type is Git.
+        if hg_installed and state_dir_available and (checkout_type == 'hg' or self.vcs == 'hg'):
             configure_hg = False
             if not self.instance.no_interactive:
                 choice = self.instance.prompt_int(prompt=CONFIGURE_MERCURIAL,
                                                   low=1, high=2)
                 if choice == 1:
                     configure_hg = True
             else:
                 configure_hg = self.hg_configure
 
             if configure_hg:
                 configure_mercurial(self.instance.which('hg'), state_dir)
 
-        # Offer to configure Git, if the current checkout is Git.
-        elif self.instance.which('git') and checkout_type == 'git':
+        # Offer to configure Git, if the current checkout or repo type is Git.
+        elif self.instance.which('git') and (checkout_type == 'git' or self.vcs == 'git'):
             should_configure_git = False
             if not self.instance.no_interactive:
                 choice = self.instance.prompt_int(prompt=CONFIGURE_GIT,
                                                   low=1, high=2)
                 if choice == 1:
                     should_configure_git = True
             else:
                 # Assuming default configuration setting applies to all VCS.
@@ -482,22 +485,22 @@ class Bootstrapper(object):
                 configure_git(self.instance.which('git'), state_dir,
                               checkout_root)
 
         # Offer to clone if we're not inside a clone.
         have_clone = False
 
         if checkout_type:
             have_clone = True
-        elif hg_installed and not self.instance.no_interactive:
+        elif hg_installed and not self.instance.no_interactive and self.vcs == 'hg':
             dest = self.input_clone_dest()
             if dest:
                 have_clone = hg_clone_firefox(self.instance.which('hg'), dest)
                 checkout_root = dest
-        elif self.instance.which('git') and checkout_type == 'git':
+        elif self.instance.which('git') and self.vcs == 'git':
             dest = self.input_clone_dest(False)
             if dest:
                 git = self.instance.which('git')
                 watchman = self.instance.which('watchman')
                 have_clone = git_clone_firefox(git, dest, watchman)
                 checkout_root = dest
 
         if not have_clone:
@@ -680,25 +683,26 @@ def current_firefox_checkout(check_outpu
 
     return (None, None)
 
 
 def update_git_tools(git, root_state_dir, top_src_dir):
     """Update git tools, hooks and extensions"""
     # Bug 1481425 - delete the git-mozreview
     # commit message hook in .git/hooks dir
-    mozreview_commit_hook = os.path.join(top_src_dir, '.git/hooks/commit-msg')
-    if os.path.exists(mozreview_commit_hook):
-        with open(mozreview_commit_hook, 'rb') as f:
-            contents = f.read()
+    if top_src_dir:
+        mozreview_commit_hook = os.path.join(top_src_dir, '.git/hooks/commit-msg')
+        if os.path.exists(mozreview_commit_hook):
+            with open(mozreview_commit_hook, 'rb') as f:
+                contents = f.read()
 
-        if b'MozReview' in contents:
-            print('removing git-mozreview commit message hook...')
-            os.remove(mozreview_commit_hook)
-            print('git-mozreview commit message hook removed.')
+            if b'MozReview' in contents:
+                print('removing git-mozreview commit message hook...')
+                os.remove(mozreview_commit_hook)
+                print('git-mozreview commit message hook removed.')
 
     # Ensure git-cinnabar is up to date.
     cinnabar_dir = os.path.join(root_state_dir, 'git-cinnabar')
 
     # Ensure the latest revision of git-cinnabar is present.
     update_git_repo(git, 'https://github.com/glandium/git-cinnabar.git',
                     cinnabar_dir)