# HG changeset patch # User Panos Astithas # Date 1551163195 0 # Tue Feb 26 06:39:55 2019 +0000 # Node ID 9ff4aa05d88146da01176e4d3ec5a1ab9739a7e2 # Parent 39b5c5bb3c0d1807bdaa770ee4ded00d51401a1f Bug 1485117 - Make standalone bootstrap work without a git checkout. r=glandium Differential Revision: https://phabricator.services.mozilla.com/D20426 diff --git a/python/mozboot/bin/bootstrap.py b/python/mozboot/bin/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) diff --git a/python/mozboot/mozboot/bootstrap.py b/python/mozboot/mozboot/bootstrap.py --- a/python/mozboot/mozboot/bootstrap.py +++ b/python/mozboot/mozboot/bootstrap.py @@ -194,23 +194,25 @@ lines: Then restart your shell. ''' 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'): @@ -390,32 +392,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. @@ -425,22 +428,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: @@ -621,25 +624,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)