Commit 02986a9f authored by Mitchell Hentges's avatar Mitchell Hentges
Browse files

Bug 1745508: Update reference to checkout-specific mach venv r=ahal,a=dsmith

The regressing bug 1739067 forgot to update this reference to the
Mach venv. As part of this, the logic for resolving the
"checkout-specific state_dir" was updated to be smarter with
Windows case-insensitive paths.

Differential Revision: https://phabricator.services.mozilla.com/D133547
parent 4970461a
Loading
Loading
Loading
Loading
+22 −14
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ class MachSiteManager:
    def __init__(
        self,
        topsrcdir: str,
        state_dir: Optional[str],
        checkout_scoped_state_dir: Optional[str],
        requirements: MachEnvRequirements,
        external_python: "ExternalPythonSite",
        site_packages_source: SitePackagesSource,
@@ -196,7 +196,8 @@ class MachSiteManager:
        """
        Args:
            topsrcdir: The path to the Firefox repo
            state_dir: The path to the state_dir, generally ~/.mozbuild
            checkout_scoped_state_dir: The path to the checkout-scoped state_dir,
                generally ~/.mozbuild/srcdirs/<checkout-based-dir>/
            requirements: The requirements associated with the Mach site, parsed from
                the file at build/mach_virtualenv_packages.txt
            external_python: The external Python site that was used to invoke Mach.
@@ -208,7 +209,11 @@ class MachSiteManager:
        self._external_python = external_python
        self._site_packages_source = site_packages_source
        self._requirements = requirements
        self._virtualenv_root = _mach_virtualenv_root(state_dir) if state_dir else None
        self._virtualenv_root = (
            _mach_virtualenv_root(checkout_scoped_state_dir)
            if checkout_scoped_state_dir
            else None
        )
        self._metadata = MozSiteMetadata(
            sys.hexversion,
            "mach",
@@ -223,8 +228,8 @@ class MachSiteManager:
        """
        Args:
            topsrcdir: The path to the Firefox repo
            get_state_dir: A function that resolve the path to the workdir-scoped
                state_dir, generally ~/.mozbuild/srcdirs/<worktree-based-dir>/
            get_state_dir: A function that resolve the path to the checkout-scoped
                state_dir, generally ~/.mozbuild/srcdirs/<checkout-based-dir>/
        """

        requirements = resolve_requirements(topsrcdir, "mach")
@@ -393,7 +398,7 @@ class CommandSiteManager:
    def __init__(
        self,
        topsrcdir: str,
        state_dir: str,
        checkout_scoped_state_dir: Optional[str],
        virtualenv_root: str,
        site_name: str,
        active_metadata: MozSiteMetadata,
@@ -403,7 +408,8 @@ class CommandSiteManager:
        """
        Args:
            topsrcdir: The path to the Firefox repo
            state_dir: The path to the state_dir, generally ~/.mozbuild
            checkout_scoped_state_dir: The path to the checkout-scoped state_dir,
                generally ~/.mozbuild/srcdirs/<checkout-based-dir>/
            virtualenv_root: The path to the virtualenv associated with this site
            site_name: The name of this site, such as "build"
            active_metadata: The currently-active moz-managed site
@@ -413,7 +419,7 @@ class CommandSiteManager:
                the file at build/<site_name>_virtualenv_packages.txt
        """
        self._topsrcdir = topsrcdir
        self._state_dir = state_dir
        self._checkout_scoped_state_dir = checkout_scoped_state_dir
        self.virtualenv_root = virtualenv_root
        self._site_name = site_name
        self._virtualenv = PythonVirtualenv(self.virtualenv_root)
@@ -436,14 +442,15 @@ class CommandSiteManager:
    def from_environment(
        cls,
        topsrcdir: str,
        state_dir: str,
        checkout_scoped_state_dir: Optional[str],
        site_name: str,
        command_virtualenvs_dir: str,
    ):
        """
        Args:
            topsrcdir: The path to the Firefox repo
            state_dir: The path to the state_dir, generally ~/.mozbuild
            checkout_scoped_state_dir: The path to the checkout-scoped state_dir,
                generally ~/.mozbuild/srcdirs/<checkout-based-dir>/
            site_name: The name of this site, such as "build"
            command_virtualenvs_dir: The location under which this site's virtualenv
            should be created
@@ -476,7 +483,7 @@ class CommandSiteManager:

        return cls(
            topsrcdir,
            state_dir,
            checkout_scoped_state_dir,
            os.path.join(command_virtualenvs_dir, site_name),
            site_name,
            active_metadata,
@@ -593,9 +600,10 @@ class CommandSiteManager:
            lines.extend(self._external_python.all_site_packages_dirs())
        elif mach_site_packages_source == SitePackagesSource.VENV:
            # When Mach is using its on-disk virtualenv, add its site-packages directory.
            assert self._checkout_scoped_state_dir
            lines.append(
                PythonVirtualenv(
                    _mach_virtualenv_root(self._state_dir)
                    _mach_virtualenv_root(self._checkout_scoped_state_dir)
                ).site_packages_dir()
            )

@@ -1049,5 +1057,5 @@ def _is_venv_up_to_date(
    return True


def _mach_virtualenv_root(state_dir):
    return os.path.join(state_dir, "_virtualenvs", "mach")
def _mach_virtualenv_root(checkout_scoped_state_dir):
    return os.path.join(checkout_scoped_state_dir, "_virtualenvs", "mach")
+4 −0
Original line number Diff line number Diff line
@@ -60,6 +60,10 @@ def get_state_dir(specific_to_topsrcdir=False, topsrcdir=None):
        topsrcdir = os.path.abspath(
            MozbuildObject.from_environment(cwd=os.path.dirname(__file__)).topsrcdir
        )

    # Ensure that the topsrcdir is a consistent string before hashing it.
    topsrcdir = os.path.normcase(os.path.normpath(topsrcdir))

    # Shortening to 12 characters makes these directories a bit more manageable
    # in a terminal and is more than good enough for this purpose.
    srcdir_hash = hashlib.sha256(topsrcdir.encode("utf-8")).hexdigest()[:12]
+1 −1
Original line number Diff line number Diff line
@@ -295,7 +295,7 @@ class MozbuildObject(ProcessExecutionMixin):
        if self._virtualenv_manager is None:
            self._virtualenv_manager = CommandSiteManager.from_environment(
                self.topsrcdir,
                get_state_dir(),
                get_state_dir(specific_to_topsrcdir=True, topsrcdir=self.topsrcdir),
                self._virtualenv_name,
                os.path.join(self.topobjdir, "_virtualenvs"),
            )
+2 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ except Exception:
    psutil = None

from mach.mixin.logging import LoggingMixin
from mach.util import get_state_dir
import mozfile
from mozsystemmonitor.resourcemonitor import SystemResourceMonitor
from mozterm.widgets import Footer
@@ -1511,7 +1512,7 @@ class BuildDriver(MozbuildObject):

        build_site = CommandSiteManager.from_environment(
            self.topsrcdir,
            self.statedir,
            get_state_dir(specific_to_topsrcdir=True, topsrcdir=self.topsrcdir),
            "build",
            os.path.join(self.topobjdir, "_virtualenvs"),
        )
+1 −1
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ def setup(app):
    topsrcdir = manager.topsrcdir
    site = CommandSiteManager.from_environment(
        topsrcdir,
        get_state_dir(),
        get_state_dir(specific_to_topsrcdir=True, topsrcdir=topsrcdir),
        "common",
        os.path.join(app.outdir, "_venv"),
    )