def bootstrap(self): if sys.version_info[0] < 3: print( "This script must be run with Python 3. \n" 'Try "python3 bootstrap.py".' ) sys.exit(1) if self.choice is None: # Like ['1. Firefox for Desktop', '2. Firefox for Android Artifact Mode', ...]. labels = [ "%s. %s" % (i, name) for i, name in enumerate(APPLICATIONS.keys(), 1) ] choices = [" {} [default]".format(labels[0])] choices += [" {}".format(label) for label in labels[1:]] prompt = APPLICATION_CHOICE % "\n".join(choices) prompt_choice = self.instance.prompt_int( prompt=prompt, low=1, high=len(APPLICATIONS), ) name, application = list(APPLICATIONS.items())[prompt_choice - 1] elif self.choice in APPLICATIONS.keys(): name, application = self.choice, APPLICATIONS[self.choice] elif self.choice in APPLICATIONS.values(): name, application = next( (k, v) for k, v in APPLICATIONS.items() if v == self.choice ) else: raise Exception( "Please pick a valid application choice: (%s)" % "/".join(APPLICATIONS.keys()) ) mozconfig_builder = MozconfigBuilder() self.instance.application = application self.instance.artifact_mode = "artifact_mode" in application self.instance.warn_if_pythonpath_is_set() # This doesn't affect any system state and we'd like to bail out as soon # as possible if this check fails. self.instance.ensure_python_modern() state_dir = self.create_state_dir() self.instance.state_dir = state_dir # We need to enable the loading of hgrc in case extensions are # required to open the repo. (checkout_type, checkout_root) = current_firefox_checkout( env=self.instance._hg_cleanenv(load_hgrc=True), hg=which("hg") ) self.instance.validate_environment(checkout_root) self._validate_python_environment() if self.instance.no_system_changes: self.instance.ensure_mach_environment(checkout_root) self.check_telemetry_opt_in(state_dir) self.maybe_install_private_packages_or_exit(state_dir, checkout_root) self._output_mozconfig(application, mozconfig_builder) sys.exit(0) self.instance.install_system_packages() # Install mach environment python packages after system packages. # Some mach packages require building native modules, which require # tools which are installed to the system. self.instance.ensure_mach_environment(checkout_root) # Like 'install_browser_packages' or 'install_mobile_android_packages'. getattr(self.instance, "install_%s_packages" % application)(mozconfig_builder) hg_installed, hg_modern = self.instance.ensure_mercurial_modern() if not self.instance.artifact_mode: self.instance.ensure_rust_modern() # Possibly configure Mercurial, but not if the current checkout or repo # type is Git. if hg_installed and checkout_type == "hg": if not self.instance.no_interactive: configure_hg = self.instance.prompt_yesno(prompt=CONFIGURE_MERCURIAL) else: configure_hg = self.hg_configure if configure_hg: configure_mercurial(which("hg"), state_dir) # Offer to configure Git, if the current checkout or repo type is Git. elif which("git") and checkout_type == "git": should_configure_git = False if not self.instance.no_interactive: should_configure_git = self.instance.prompt_yesno(prompt=CONFIGURE_GIT) else: # Assuming default configuration setting applies to all VCS. should_configure_git = self.hg_configure if should_configure_git: configure_git( which("git"), which("git-cinnabar"), state_dir, checkout_root ) self.check_telemetry_opt_in(state_dir) self.maybe_install_private_packages_or_exit(state_dir, checkout_root) self.check_code_submission(checkout_root) print(FINISHED % name) if not ( which("rustc") and self.instance._parse_version("rustc") >= MODERN_RUST_VERSION ): print( "To build %s, please restart the shell (Start a new terminal window)" % name ) self._output_mozconfig(application, mozconfig_builder)
def bootstrap(self, settings): if self.choice is None: applications = APPLICATIONS if isinstance(self.instance, OSXBootstrapperLight): applications = { key: value for key, value in applications.items() if "artifact_mode" not in value and "mobile_android" not in value } print( 'Note: M1 Macs don\'t support "Artifact Mode", so ' "it has been removed from the list of options below" ) else: print(ARTIFACT_MODE_NOTE) # Like ['1. Firefox for Desktop', '2. Firefox for Android Artifact Mode', ...]. labels = [ "%s. %s" % (i, name) for i, name in enumerate(applications.keys(), 1) ] choices = [" {} [default]".format(labels[0])] choices += [" {}".format(label) for label in labels[1:]] prompt = APPLICATION_CHOICE % "\n".join(choices) prompt_choice = self.instance.prompt_int( prompt=prompt, low=1, high=len(applications) ) name, application = list(applications.items())[prompt_choice - 1] elif self.choice in APPLICATIONS.keys(): name, application = self.choice, APPLICATIONS[self.choice] elif self.choice in APPLICATIONS.values(): name, application = next( (k, v) for k, v in APPLICATIONS.items() if v == self.choice ) else: raise Exception( "Please pick a valid application choice: (%s)" % "/".join(APPLICATIONS.keys()) ) mozconfig_builder = MozconfigBuilder() self.instance.application = application self.instance.artifact_mode = "artifact_mode" in application self.instance.warn_if_pythonpath_is_set() if sys.platform.startswith("darwin") and not os.environ.get( "MACH_I_DO_WANT_TO_USE_ROSETTA" ): # If running on arm64 mac, check whether we're running under # Rosetta and advise against it. proc = subprocess.run( ["sysctl", "-n", "sysctl.proc_translated"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, ) if ( proc.returncode == 0 and proc.stdout.decode("ascii", "replace").strip() == "1" ): print( "Python is being emulated under Rosetta. Please use a native " "Python instead. If you still really want to go ahead, set " "the MACH_I_DO_WANT_TO_USE_ROSETTA environment variable.", file=sys.stderr, ) return 1 state_dir = get_state_dir() self.instance.state_dir = state_dir # We need to enable the loading of hgrc in case extensions are # required to open the repo. (checkout_type, checkout_root) = current_firefox_checkout( env=self.instance._hg_cleanenv(load_hgrc=True), hg=which("hg") ) self.instance.validate_environment(checkout_root) self._validate_python_environment() if self.instance.no_system_changes: self.instance.ensure_mach_environment(checkout_root) self.maybe_install_private_packages_or_exit( state_dir, checkout_root, application ) self._output_mozconfig(application, mozconfig_builder) sys.exit(0) self.instance.install_system_packages() # Install mach environment python packages after system packages. # Some mach packages require building native modules, which require # tools which are installed to the system. self.instance.ensure_mach_environment(checkout_root) # Like 'install_browser_packages' or 'install_mobile_android_packages'. getattr(self.instance, "install_%s_packages" % application)(mozconfig_builder) hg_installed, hg_modern = self.instance.ensure_mercurial_modern() if not self.instance.artifact_mode: self.instance.ensure_rust_modern() # Possibly configure Mercurial, but not if the current checkout or repo # type is Git. if hg_installed and checkout_type == "hg": if not self.instance.no_interactive: configure_hg = self.instance.prompt_yesno(prompt=CONFIGURE_MERCURIAL) else: configure_hg = self.hg_configure if configure_hg: configure_mercurial(which("hg"), state_dir) # Offer to configure Git, if the current checkout or repo type is Git. elif which("git") and checkout_type == "git": should_configure_git = False if not self.instance.no_interactive: should_configure_git = self.instance.prompt_yesno(prompt=CONFIGURE_GIT) else: # Assuming default configuration setting applies to all VCS. should_configure_git = self.hg_configure if should_configure_git: configure_git( which("git"), which("git-cinnabar"), state_dir, checkout_root ) self.maybe_install_private_packages_or_exit( state_dir, checkout_root, application ) self.check_code_submission(checkout_root) # Wait until after moz-phab setup to check telemetry so that employees # will be automatically opted-in. if not self.instance.no_interactive and not settings.mach_telemetry.is_set_up: initialize_telemetry_setting(settings, checkout_root, state_dir) print(FINISHED % name) if not ( which("rustc") and self.instance._parse_version("rustc") >= MODERN_RUST_VERSION ): print( "To build %s, please restart the shell (Start a new terminal window)" % name ) self._output_mozconfig(application, mozconfig_builder)