diff --git a/python/mozbuild/mozbuild/base.py b/python/mozbuild/mozbuild/base.py index d43d74de9333..5644e955fe21 100644 --- a/python/mozbuild/mozbuild/base.py +++ b/python/mozbuild/mozbuild/base.py @@ -186,16 +186,19 @@ class MozbuildObject(ProcessExecutionMixin): topsrcdir, topobjdir, mozconfig = load_mozinfo(mozinfo_path) break - 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) + # 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: topsrcdir = os.path.abspath(