Bug 1525688 - Lazily import mozbuild.base in mozboot/util.py. r=ahal
authorTooru Fujisawa <arai_a@mac.com>
Thu, 07 Feb 2019 16:10:12 +0000
changeset 457641 bd2e27b25f57df6cc351839b14aa0e81cb73dc50
parent 457640 19cf89dc14e6976f556c4d7fd82ace219668a45e
child 457642 61b408c4e663b4cffd7c40b3702bc7f79874c9c5
push id35516
push userrmaries@mozilla.com
push dateFri, 08 Feb 2019 04:23:26 +0000
treeherdermozilla-central@d599d1a73a3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1525688
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 1525688 - Lazily import mozbuild.base in mozboot/util.py. r=ahal Differential Revision: https://phabricator.services.mozilla.com/D18986
python/mozboot/mozboot/util.py
--- a/python/mozboot/mozboot/util.py
+++ b/python/mozboot/mozboot/util.py
@@ -1,17 +1,16 @@
 # 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, print_function
 
 import hashlib
 import os
-from mozbuild.base import MozbuildObject
 
 here = os.path.join(os.path.dirname(__file__))
 
 
 def get_state_dir(srcdir=False):
     """Obtain path to a directory to hold state.
 
     Args:
@@ -20,16 +19,21 @@ def get_state_dir(srcdir=False):
 
     Returns:
         A path to the state dir (str)
     """
     state_dir = os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser('~/.mozbuild'))
     if not srcdir:
         return state_dir
 
+    # This function can be called without the build virutualenv, and in that
+    # case srcdir is supposed to be False. Import mozbuild here to avoid
+    # breaking that usage.
+    from mozbuild.base import MozbuildObject
+
     srcdir = os.path.abspath(MozbuildObject.from_environment(cwd=here).topsrcdir)
     # Shortening to 12 characters makes these directories a bit more manageable
     # in a terminal and is more than good enough for this purpose.
     srcdir_hash = hashlib.sha256(srcdir).hexdigest()[:12]
 
     state_dir = os.path.join(state_dir, 'srcdirs', '{}-{}'.format(
         os.path.basename(srcdir), srcdir_hash))