From 095ba09dda3ef0c3d804cb4013121661c9aca5a8 Mon Sep 17 00:00:00 2001 From: byron jones Date: Wed, 19 Feb 2020 05:28:32 +0000 Subject: [PATCH] Bug 1495394 - add `mach install-moz-phab` command; r=firefox-build-system-reviewers,chmanchester Install moz-phab using the correct command for the current operating system as per moz-phab's documentation. Differential Revision: https://phabricator.services.mozilla.com/D59139 --HG-- extra : moz-landing-system : lando --- build/mach_bootstrap.py | 1 + python/mozboot/mozboot/bootstrap.py | 11 +++++ tools/phabricator/mach_commands.py | 71 +++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 tools/phabricator/mach_commands.py diff --git a/build/mach_bootstrap.py b/build/mach_bootstrap.py index 7ef6214181ad..32a3540ad764 100644 --- a/build/mach_bootstrap.py +++ b/build/mach_bootstrap.py @@ -74,6 +74,7 @@ MACH_MODULES = [ 'tools/lint/mach_commands.py', 'tools/mach_commands.py', 'tools/moztreedocs/mach_commands.py', + 'tools/phabricator/mach_commands.py', 'tools/power/mach_commands.py', 'tools/tryselect/mach_commands.py', 'tools/vcs/mach_commands.py', diff --git a/python/mozboot/mozboot/bootstrap.py b/python/mozboot/mozboot/bootstrap.py index 0b9068d49bc7..dbe5b649bfe9 100644 --- a/python/mozboot/mozboot/bootstrap.py +++ b/python/mozboot/mozboot/bootstrap.py @@ -206,6 +206,14 @@ like to opt out of data collection, select (N) at the prompt. Would you like to enable build system telemetry?''' +MOZ_PHAB_ADVERTISE = ''' +If you plan on submitting changes to Firefox use the following command to +install the review submission tool "moz-phab": + + mach install-moz-phab +''' + + def update_or_create_build_telemetry_config(path): """Write a mach config file enabling build telemetry to `path`. If the file does not exist, create it. If it exists, add the new setting to the existing data. @@ -526,6 +534,9 @@ class Bootstrapper(object): >= MODERN_RUST_VERSION): print("To build %s, please restart the shell (Start a new terminal window)" % name) + if not self.instance.which("moz-phab"): + print(MOZ_PHAB_ADVERTISE) + # Like 'suggest_browser_mozconfig' or 'suggest_mobile_android_mozconfig'. getattr(self.instance, 'suggest_%s_mozconfig' % application)() diff --git a/tools/phabricator/mach_commands.py b/tools/phabricator/mach_commands.py new file mode 100644 index 000000000000..1cd2e3a79f7a --- /dev/null +++ b/tools/phabricator/mach_commands.py @@ -0,0 +1,71 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, # You can obtain one at http://mozilla.org/MPL/2.0/. + +from __future__ import absolute_import, unicode_literals + +from mach.decorators import CommandProvider, Command, CommandArgument +from mozbuild.base import MachCommandBase + + +@CommandProvider +class PhabricatorCommandProvider(MachCommandBase): + @Command( + "install-moz-phab", + category="misc", + description="Install patch submission tool.", + ) + @CommandArgument( + "--force", + "-f", + action="store_true", + help="Force installation even if already installed.", + ) + def install_moz_phab(self, force=False): + import logging + import shutil + import subprocess + import sys + + existing = shutil.which("moz-phab") + if existing and not force: + self.log( + logging.ERROR, + "already_installed", + {}, + "moz-phab is already installed in %s." % existing, + ) + sys.exit(1) + + command = ["pip3", "install", "--upgrade", "MozPhab"] + + if ( + sys.platform.startswith("linux") + or sys.platform.startswith("openbsd") + or sys.platform.startswith("dragonfly") + or sys.platform.startswith("freebsd") + ): + # On all Linux and BSD distros we default to a user installation. + command.append("--user") + + elif sys.platform.startswith("darwin"): + # On MacOS we require brew or ports, which work better without --user. + pass + + elif sys.platform.startswith("win32") or sys.platform.startswith("msys"): + # Likewise for Windows we assume a system level install is preferred. + pass + + else: + # Unsupported, default to --user. + self.log( + logging.WARNING, + "unsupported_platform", + {}, + "Unsupported platform (%s), assuming per-user installation." + % sys.platform, + ) + command.append("--user") + + self.log(logging.INFO, "run", {}, "Installing moz-phab") + subprocess.run(command)