Skip to content

Commit

Permalink
Bug 1675675 - Only put mach_bootstrap paths in PYTHONPATH for mach py…
Browse files Browse the repository at this point in the history
…thon --no-virtualenv. r=firefox-build-system-reviewers,rstewart

With PYTHONPATH containing other directories, such as the python ones,
bad things can happen when the python script that is being run then
goes on to subprocess.Popen a python process for a different virtualenv,
or a different version, or whatever.

Differential Revision: https://phabricator.services.mozilla.com/D96155
  • Loading branch information
glandium committed Nov 6, 2020
1 parent a6367ad commit af94e85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 8 additions & 4 deletions build/mach_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ def handle_package(package):
yield path


def mach_sys_path(mozilla_dir):
return [
os.path.join(mozilla_dir, path)
for path in search_path(mozilla_dir, "build/mach_virtualenv_packages.txt")
]


def bootstrap(topsrcdir, mozilla_dir=None):
if mozilla_dir is None:
mozilla_dir = topsrcdir
Expand All @@ -198,10 +205,7 @@ def bootstrap(topsrcdir, mozilla_dir=None):
# case. For default behavior, we educate users and give them an opportunity
# to react. We always exit after creating the directory because users don't
# like surprises.
sys.path[0:0] = [
os.path.join(mozilla_dir, path)
for path in search_path(mozilla_dir, "build/mach_virtualenv_packages.txt")
]
sys.path[0:0] = mach_sys_path(mozilla_dir)
import mach.base
import mach.main
from mach.util import setenv
Expand Down
4 changes: 3 additions & 1 deletion python/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ def python(self, no_virtualenv, exec_file, ipython, args):
}

if no_virtualenv:
from mach_bootstrap import mach_sys_path

python_path = sys.executable
append_env["PYTHONPATH"] = os.pathsep.join(sys.path)
append_env["PYTHONPATH"] = os.pathsep.join(mach_sys_path(self.topsrcdir))
else:
self.activate_virtualenv()
python_path = self.virtualenv_manager.python_path
Expand Down

0 comments on commit af94e85

Please sign in to comment.