Bug 1744884 - Move win_to_msys_path helper function outside of Bootstrapper class to mach/util.py so that it can be used elsewhere. r=firefox-build-system-reviewers,mhentges

Added usage during `configure_git` for cinnabar directory location
instructions for adding to PATH.

Differential Revision: https://phabricator.services.mozilla.com/D135266
This commit is contained in:
ahochheiden 2022-01-21 19:35:49 +00:00
parent 72bb536e37
commit 80a93642e9
3 changed files with 22 additions and 17 deletions

View File

@ -8,7 +8,7 @@ import hashlib
import os
import sys
from pathlib import Path
from pathlib import Path, PurePosixPath
from typing import Optional
@ -88,6 +88,17 @@ def get_state_dir(specific_to_topsrcdir=False, topsrcdir=None):
return state_dir
def win_to_msys_path(path: Path):
"""Convert a windows-style path to msys-style."""
drive, path = os.path.splitdrive(path)
path = "/".join(path.split("\\"))
if drive:
if path[0] == "/":
path = path[1:]
path = f"/{drive[:-1]}/{path}"
return PurePosixPath(path)
def to_optional_path(path: Optional[Path]):
if path:
return Path(path)

View File

@ -10,7 +10,6 @@ import re
import subprocess
import sys
from pathlib import PurePosixPath
from pathlib import Path
from distutils.version import LooseVersion
@ -20,7 +19,7 @@ from mozboot.util import (
MINIMUM_RUST_VERSION,
)
from mozfile import which
from mach.util import to_optional_path
from mach.util import to_optional_path, win_to_msys_path
# NOTE: This script is intended to be run with a vanilla Python install. We
# have to rely on the standard library instead of Python 2+3 helpers like
@ -752,16 +751,6 @@ class BaseBootstrapper(object):
cargo_bin = cargo_home / "bin"
return cargo_home, cargo_bin
def win_to_msys_path(self, path: Path):
"""Convert a windows-style path to msys style."""
drive, path = os.path.splitdrive(path)
path = "/".join(path.split("\\"))
if drive:
if path[0] == "/":
path = path[1:]
path = f"/{drive[:-1]}/{path}"
return PurePosixPath(path)
def print_rust_path_advice(self, template, cargo_home: Path, cargo_bin: Path):
# Suggest ~/.cargo/env if it exists.
if (cargo_home / "env").exists():
@ -771,7 +760,7 @@ class BaseBootstrapper(object):
# so fall back to a manual PATH update. Bootstrap
# only runs under msys, so a unix-style shell command
# is appropriate there.
cargo_bin = self.win_to_msys_path(cargo_bin)
cargo_bin = win_to_msys_path(cargo_bin)
cmd = f"export PATH={cargo_bin}:$PATH"
print(template % {"cargo_bin": cargo_bin, "cmd": cmd})

View File

@ -15,7 +15,13 @@ import time
from typing import Optional
from pathlib import Path
from distutils.version import LooseVersion
from mach.util import get_state_dir, UserError, to_optional_path, to_optional_str
from mach.util import (
get_state_dir,
UserError,
to_optional_path,
to_optional_str,
win_to_msys_path,
)
from mach.telemetry import initialize_telemetry_setting
from mozboot.base import MODERN_RUST_VERSION
from mozboot.centosfedora import CentOSFedoraBootstrapper
@ -633,8 +639,7 @@ def configure_git(
if "MOZILLABUILD" in os.environ:
# Slightly modify the path on Windows to be correct
# for the copy/paste into the .bash_profile
cinnabar_dir = "/" + cinnabar_dir
cinnabar_dir = cinnabar_dir.replace(":", "")
cinnabar_dir = win_to_msys_path(cinnabar_dir)
print(
ADD_GIT_CINNABAR_PATH.format(