Browse Source

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 <vapier@chromium.org>
Reviewed-by: George Engelbrecht <engeg@google.com>
Mike Frysinger 1 year ago
parent
commit
cd9f6dc4b1
1 changed files with 20 additions and 8 deletions
  1. 20 8
      cros

+ 20 - 8
cros

@@ -11,11 +11,12 @@ possible.
 It is intended to used strictly outside of the chroot.
 It is intended to used strictly outside of the chroot.
 """
 """
 
 
+import enum
 import os
 import os
 from pathlib import Path
 from pathlib import Path
 import subprocess
 import subprocess
 import sys
 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 version of Python that we *want*.  We warn for older versions.
 MIN_PYTHON_VER_SOFT = (3, 8)
 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'
 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."""
     """Find the chromite dir in a repo, gclient, or submodule checkout."""
     path = path.resolve()
     path = path.resolve()
     # Depending on the checkout type (whether repo chromeos or gclient chrome)
     # Depending on the checkout type (whether repo chromeos or gclient chrome)
@@ -48,10 +56,8 @@ def _FindChromite(path: Path) -> Optional[Path]:
 
 
     while path != Path("/"):
     while path != Path("/"):
         for root, chromite_git_dir in roots:
         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
         path = path.parent
     return None
     return None
 
 
@@ -100,10 +106,16 @@ def _BootstrapVpython27():
 def main():
 def main():
     _CheckPythonVersion()
     _CheckPythonVersion()
 
 
-    chromite_dir = _FindChromite(Path.cwd())
+    result = _FindChromite(Path.cwd())
     target = os.path.basename(sys.argv[0])
     target = os.path.basename(sys.argv[0])
-    if chromite_dir is None:
+    if result is None:
         return _MissingErrorOut(target)
         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
     path = chromite_dir / "bin" / target