From be8b9cb5ecf3f0c518594424cb8cb54003cc9015 Mon Sep 17 00:00:00 2001 From: Mitchell Hentges Date: Tue, 3 May 2022 13:40:15 +0000 Subject: [PATCH] Bug 1765361: Only resolve objdir from virtualenv if mozinfo not ancestor r=glandium Virtualenv-based objdir detection doesn't work for instrumented builds, as instrumentation-specific objdirs aren't created. Resolve this by: * Removing redundant cwd-based topsrcdir resolution - the `__file__`-based code path below covers this case. * Only using virtualenv-based resolving if topsrcdir isn't resolved. * Documenting that virtualenv-based resolution is problematic for instrumented builds. Differential Revision: https://phabricator.services.mozilla.com/D144030 --- python/mozbuild/mozbuild/base.py | 34 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/python/mozbuild/mozbuild/base.py b/python/mozbuild/mozbuild/base.py index 5644e955fe21..d1f26aaf7ea1 100644 --- a/python/mozbuild/mozbuild/base.py +++ b/python/mozbuild/mozbuild/base.py @@ -186,24 +186,28 @@ class MozbuildObject(ProcessExecutionMixin): topsrcdir, topobjdir, mozconfig = load_mozinfo(mozinfo_path) break - # We choose an arbitrary file as an indicator that this is a - # srcdir. We go with ourself because why not! - our_path = os.path.join( - dir_path, "python", "mozbuild", "mozbuild", "base.py" - ) - if os.path.isfile(our_path): - topsrcdir = dir_path - break - - # See if we're running from a Python virtualenv that's inside an objdir. - mozinfo_path = os.path.join(os.path.dirname(sys.prefix), "../mozinfo.json") - if detect_virtualenv_mozinfo and os.path.isfile(mozinfo_path): - topsrcdir, topobjdir, mozconfig = load_mozinfo(mozinfo_path) + if not topsrcdir: + # See if we're running from a Python virtualenv that's inside an objdir. + # sys.prefix would look like "$objdir/_virtualenvs/$virtualenv/". + # Note that virtualenv-based objdir detection work for instrumented builds, + # because they aren't created in the scoped "instrumentated" objdir. + # However, working-directory-ancestor-based objdir resolution should fully + # cover that case. + mozinfo_path = os.path.join(sys.prefix, "..", "..", "mozinfo.json") + if detect_virtualenv_mozinfo and os.path.isfile(mozinfo_path): + topsrcdir, topobjdir, mozconfig = load_mozinfo(mozinfo_path) if not topsrcdir: - topsrcdir = os.path.abspath( - os.path.join(os.path.dirname(__file__), "..", "..", "..") + topsrcdir = os.path.normcase( + os.path.abspath( + os.path.join(os.path.dirname(__file__), "..", "..", "..") + ) ) + if sys.platform.startswith("win"): + # A bunch of tests depend on the drive letter being capitalized on + # Windows. Since the sys.path entries are normcase'd, the __file__ + # path has a lowercase drive letter. Work around it with capitalize(). + topsrcdir = topsrcdir.capitalize() topsrcdir = mozpath.normsep(topsrcdir) if topobjdir: