From 61727a2cbbed75373d2a630f205cf8f4087b5650 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Wed, 23 Dec 2015 14:25:37 -0800 Subject: [PATCH] Bug 1216817 - Part 5: Run |mach artifact install| automatically when asked. r=glandium It turns out to be much easier to hook |mach artifact install| into config.status and |mach build| than to hook into client.mk. The additional virtualenv package avoids an import error when running |mach artifact install|. --HG-- extra : commitid : EnfWU0uyRfQ extra : rebase_source : f7d11fc4c542f9798712c013c4319d92d40c28e5 --- build/virtualenv_packages.txt | 1 + python/mozbuild/mozbuild/base.py | 2 +- python/mozbuild/mozbuild/config_status.py | 6 +++++ python/mozbuild/mozbuild/mach_commands.py | 29 +++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/build/virtualenv_packages.txt b/build/virtualenv_packages.txt index 3b000729afd8..96ad3303f71b 100644 --- a/build/virtualenv_packages.txt +++ b/build/virtualenv_packages.txt @@ -33,3 +33,4 @@ requests.pth:python/requests rsa.pth:python/rsa futures.pth:python/futures ecc.pth:python/PyECC +xpcshell.pth:testing/xpcshell diff --git a/python/mozbuild/mozbuild/base.py b/python/mozbuild/mozbuild/base.py index e1feaa36fd41..b0e3d4f52689 100644 --- a/python/mozbuild/mozbuild/base.py +++ b/python/mozbuild/mozbuild/base.py @@ -257,7 +257,7 @@ class MozbuildObject(ProcessExecutionMixin): config_status = os.path.join(self.topobjdir, 'config.status') if not os.path.exists(config_status): - raise Exception('config.status not available. Run configure.') + raise BuildEnvironmentNotFoundException('config.status not available. Run configure.') self._config_environment = \ ConfigEnvironment.from_config_status(config_status) diff --git a/python/mozbuild/mozbuild/config_status.py b/python/mozbuild/mozbuild/config_status.py index 273899cd71aa..c2996d1b5d51 100644 --- a/python/mozbuild/mozbuild/config_status.py +++ b/python/mozbuild/mozbuild/config_status.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, print_function import logging import os +import subprocess import sys import time @@ -209,3 +210,8 @@ def config_status(topobjdir='.', topsrcdir='.', if MachCommandConditions.is_android(env): if 'AndroidEclipse' not in options.backend: print(ANDROID_IDE_ADVERTISEMENT) + + if env.substs['MOZ_ARTIFACT_BUILDS']: + # Execute |mach artifact install| from the top source directory. + os.chdir(topsrcdir) + return subprocess.check_call([sys.executable, os.path.join(topsrcdir, 'mach'), 'artifact', 'install']) diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py index f1f16431a97b..1c80814fc3e2 100644 --- a/python/mozbuild/mozbuild/mach_commands.py +++ b/python/mozbuild/mozbuild/mach_commands.py @@ -25,6 +25,7 @@ from mach.decorators import ( from mach.mixin.logging import LoggingMixin from mozbuild.base import ( + BuildEnvironmentNotFoundException, MachCommandBase, MachCommandConditions as conditions, MozbuildObject, @@ -381,6 +382,9 @@ class Build(MachCommandBase): line_handler=output.on_line, log=False, print_directory=False) + if self.substs['MOZ_ARTIFACT_BUILDS']: + self._run_mach_artifact_install() + # Build target pairs. for make_dir, make_target in target_pairs: # We don't display build status messages during partial @@ -395,6 +399,19 @@ class Build(MachCommandBase): if status != 0: break else: + try: + if self.substs['MOZ_ARTIFACT_BUILDS']: + self._run_mach_artifact_install() + except BuildEnvironmentNotFoundException: + # Can't read self.substs from config.status? That means we + # need to run configure. The client.mk invocation below + # will configure, which will run config.status, which will + # invoke |mach artifact install| itself before continuing + # the build. Therefore, we needn't install artifacts + # ourselves. + self.log(logging.DEBUG, 'artifact', + {}, "Not running |mach artifact install| -- it will be run by client.mk.") + monitor.start_resource_recording() status = self._run_make(srcdir=True, filename='client.mk', line_handler=output.on_line, log=False, print_directory=False, @@ -602,6 +619,18 @@ class Build(MachCommandBase): return self._run_command_in_objdir(args=args, pass_thru=True, ensure_exit_code=False) + def _run_mach_artifact_install(self): + # We'd like to launch artifact using + # self._mach_context.commands.dispatch. However, artifact activates + # the virtualenv, which plays badly with the rest of this code. + # Therefore, we run |mach artifact install| in a new process (and + # throw an exception if it fails). + self.log(logging.INFO, 'artifact', + {}, "Running |mach artifact install|.") + args = [os.path.join(self.topsrcdir, 'mach'), 'artifact', 'install'] + self._run_command_in_srcdir(args=args, + pass_thru=True, ensure_exit_code=True) + @CommandProvider class Doctor(MachCommandBase): """Provide commands for diagnosing common build environment problems"""