From cd9f6dc4b1e713e445b0df8e69567982af2459a3 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 27 Oct 2023 18:40:02 +0000 Subject: [PATCH] cros: disable Python caches in citc checkouts Since citc doesn't support gitignore, it doesn't like it when you dirty checkouts with pyc/pyo files. Disable it here when running the launchers. Change-Id: I0fd65da489d477bcc3027cf0059ce7122bb90c6b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4983229 Commit-Queue: Mike Frysinger Reviewed-by: George Engelbrecht --- cros | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/cros b/cros index 3a11efa50..536cc65ff 100755 --- a/cros +++ b/cros @@ -11,11 +11,12 @@ possible. It is intended to used strictly outside of the chroot. """ +import enum import os from pathlib import Path import subprocess import sys -from typing import Optional +from typing import List, NamedTuple, Optional, Tuple # Min version of Python that we *want*. We warn for older versions. MIN_PYTHON_VER_SOFT = (3, 8) @@ -28,7 +29,14 @@ DEPOT_TOOLS_DIR = Path(__file__).resolve().parent CIPD_CACHE_DIR = DEPOT_TOOLS_DIR / '.cipd_bin_cros_python2' -def _FindChromite(path: Path) -> Optional[Path]: +class Checkout(NamedTuple): + """Some details about this checkout.""" + + root: Path + chromite_dir: Path + + +def _FindChromite(path: Path) -> Optional[Checkout]: """Find the chromite dir in a repo, gclient, or submodule checkout.""" path = path.resolve() # Depending on the checkout type (whether repo chromeos or gclient chrome) @@ -48,10 +56,8 @@ def _FindChromite(path: Path) -> Optional[Path]: while path != Path("/"): for root, chromite_git_dir in roots: - if all( - (path / x).exists() - for x in [root, chromite_git_dir]): - return (path / chromite_git_dir).parent + if all((path / x).exists() for x in [root, chromite_git_dir]): + return Checkout(path, (path / chromite_git_dir).parent) path = path.parent return None @@ -100,10 +106,16 @@ def _BootstrapVpython27(): def main(): _CheckPythonVersion() - chromite_dir = _FindChromite(Path.cwd()) + result = _FindChromite(Path.cwd()) target = os.path.basename(sys.argv[0]) - if chromite_dir is None: + if result is None: return _MissingErrorOut(target) + root, chromite_dir = result + + is_citc = (root.parent / ".citc").is_dir() + if is_citc: + # citc workspaces don't like dirty files like pyc. + os.environ["PYTHONDONTWRITEBYTECODE"] = "1" path = chromite_dir / "bin" / target