Bug 1743592: Don't resolve/create scoped state_dir in CI r=ahal

We only need a workdir-scoped state_dir when an on-disk virtualenv will
be created for the Mach site.

This change defers the resolution of the state_dir until we know that a
VENV will be created.

Also modify "telemetry.py" so that it isn't creating a
scoped state-dir to compare "sys.executable" against.

Differential Revision: https://phabricator.services.mozilla.com/D132706
This commit is contained in:
Mitchell Hentges 2021-12-03 16:26:45 +00:00
parent 63bf096aef
commit 0fb9e1cb04
3 changed files with 17 additions and 12 deletions

View file

@ -166,13 +166,12 @@ install a recent enough Python 3.
""".strip()
def _activate_python_environment(topsrcdir, state_dir):
def _activate_python_environment(topsrcdir, get_state_dir):
from mach.site import MachSiteManager
mach_environment = MachSiteManager.from_environment(
topsrcdir,
# normpath state_dir to normalize msys-style slashes.
os.path.normpath(state_dir),
get_state_dir,
)
mach_environment.activate()
@ -215,7 +214,11 @@ def initialize(topsrcdir):
from mach.util import setenv, get_state_dir
state_dir = _create_state_dir()
_activate_python_environment(topsrcdir, get_state_dir(True, topsrcdir=topsrcdir))
# normpath state_dir to normalize msys-style slashes.
_activate_python_environment(
topsrcdir, lambda: os.path.normpath(get_state_dir(True, topsrcdir=topsrcdir))
)
import mach.base
import mach.main

View file

@ -20,7 +20,7 @@ import sys
from pathlib import Path
import tempfile
from contextlib import contextmanager
from typing import Optional
from typing import Optional, Callable
from mach.requirements import (
MachEnvRequirements,
@ -219,11 +219,12 @@ class MachSiteManager:
)
@classmethod
def from_environment(cls, topsrcdir: str, state_dir: str):
def from_environment(cls, topsrcdir: str, get_state_dir: Callable[[], str]):
"""
Args:
topsrcdir: The path to the Firefox repo
state_dir: The path to the state_dir, generally ~/.mozbuild
get_state_dir: A function that resolve the path to the workdir-scoped
state_dir, generally ~/.mozbuild/srcdirs/<worktree-based-dir>/
"""
requirements = resolve_requirements(topsrcdir, "mach")
@ -243,14 +244,17 @@ class MachSiteManager:
if not _system_python_env_variable_present():
source = SitePackagesSource.VENV
state_dir = get_state_dir()
elif not external_python.has_pip():
source = SitePackagesSource.NONE
state_dir = None
else:
source = (
SitePackagesSource.SYSTEM
if external_python.provides_any_package("mach", requirements)
else SitePackagesSource.NONE
)
state_dir = None
return cls(
topsrcdir,

View file

@ -16,13 +16,12 @@ import requests
import six.moves.urllib.parse as urllib_parse
from mach.config import ConfigSettings
from mach.site import MozSiteMetadata
from mach.telemetry_interface import NoopTelemetry, GleanTelemetry
from mach.util import get_state_dir
from mozboot.util import get_mach_virtualenv_binary
from mozbuild.base import MozbuildObject, BuildEnvironmentNotFoundException
from mozbuild.settings import TelemetrySettings
from mozbuild.telemetry import filter_args
import mozpack.path
from mozversioncontrol import get_repository_object, InvalidRepoPath
@ -39,9 +38,8 @@ def create_telemetry_from_environment(settings):
doesn't support it.
"""
is_mach_virtualenv = mozpack.path.normpath(sys.executable) == mozpack.path.normpath(
get_mach_virtualenv_binary()
)
active_metadata = MozSiteMetadata.from_runtime()
is_mach_virtualenv = active_metadata and active_metadata.site_name == "mach"
if not (
is_applicable_telemetry_environment()