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
This commit is contained in:
Mitchell Hentges 2022-05-03 13:40:15 +00:00
parent 903cce1100
commit be8b9cb5ec

View File

@ -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: