Bug 1740123: Allow invoking Mach outside of MozillaBuild r=glandium
Assuming that the `MOZILLABUILD` environment variable is set, allow invoking Mach from non-MozillaBuild terminals. Note that MozillaBuild still needs to be installed, and the `MOZILLABUILD` environment variable will have to be set. For future reference: when I tried setting this up with Windows Store's Python 3.9, I encountered issues when running binaries installed via `pip`: it would fail with `abort: failed to load Python DLL python3x.dll`. Differential Revision: https://phabricator.services.mozilla.com/D133936
This commit is contained in:
@@ -8,6 +8,7 @@ import math
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
import __builtin__ as builtins
|
||||
@@ -150,6 +151,39 @@ def _activate_python_environment(topsrcdir, get_state_dir):
|
||||
mach_environment.activate()
|
||||
|
||||
|
||||
def _maybe_activate_mozillabuild_environment():
|
||||
if sys.platform != "win32":
|
||||
return
|
||||
|
||||
mozillabuild = Path(os.environ.get("MOZILLABUILD", r"C:\mozilla-build"))
|
||||
assert mozillabuild.exists(), (
|
||||
f'MozillaBuild was not found at "{mozillabuild}".\n'
|
||||
"If it's installed in a different location, please "
|
||||
'set the "MOZILLABUILD" environment variable '
|
||||
"accordingly."
|
||||
)
|
||||
|
||||
for entry in os.environ.get("PATH", "").split(":"):
|
||||
entry = Path(entry)
|
||||
if mozillabuild in entry.parents:
|
||||
# We're already running with MozillaBuild directories in our PATH: either
|
||||
# that's because we're inside the MozillaBuild shell, or the active developer
|
||||
# has manually set up the PATH entries.
|
||||
return
|
||||
|
||||
use_msys2 = (mozillabuild / "msys2").exists()
|
||||
if use_msys2:
|
||||
mozillabuild_msys_tools_path = mozillabuild / "msys2" / "usr" / "bin"
|
||||
else:
|
||||
mozillabuild_msys_tools_path = mozillabuild / "msys" / "bin"
|
||||
|
||||
os.environ.setdefault("MOZILLABUILD", str(mozillabuild))
|
||||
os.environ["PATH"] += (
|
||||
f"{os.pathsep}{mozillabuild_msys_tools_path}"
|
||||
f"{os.pathsep}{mozillabuild / 'bin'}"
|
||||
)
|
||||
|
||||
|
||||
def initialize(topsrcdir):
|
||||
# This directory was deleted in bug 1666345, but there may be some ignored
|
||||
# files here. We can safely just delete it for the user so they don't have
|
||||
@@ -178,6 +212,7 @@ def initialize(topsrcdir):
|
||||
_activate_python_environment(
|
||||
topsrcdir, lambda: os.path.normpath(get_state_dir(True, topsrcdir=topsrcdir))
|
||||
)
|
||||
_maybe_activate_mozillabuild_environment()
|
||||
|
||||
import mach.base
|
||||
import mach.main
|
||||
|
||||
Reference in New Issue
Block a user