Create a clean Windows environment without Git Bash indicators. This removes Git Bash environment variables (MSYSTEM, TERM, SHELL, etc.) that might cause ESP-IDF tooling to detect Git Bash and abort compilation. This function is extracted from ci/util/pio_package_daemon.py where it
()
| 47 | |
| 48 | |
| 49 | def get_clean_windows_env() -> dict[str, str]: |
| 50 | """Create a clean Windows environment without Git Bash indicators. |
| 51 | |
| 52 | This removes Git Bash environment variables (MSYSTEM, TERM, SHELL, etc.) |
| 53 | that might cause ESP-IDF tooling to detect Git Bash and abort compilation. |
| 54 | |
| 55 | This function is extracted from ci/util/pio_package_daemon.py where it |
| 56 | was originally implemented for package installations. Now we reuse it |
| 57 | for compilation as well. |
| 58 | |
| 59 | Returns: |
| 60 | Clean environment dict suitable for running pio via cmd.exe |
| 61 | """ |
| 62 | # Start with minimal system environment |
| 63 | clean_env: dict[str, str] = {} |
| 64 | |
| 65 | # Git Bash environment variables to EXCLUDE (these cause ESP-IDF to abort) |
| 66 | git_bash_vars = { |
| 67 | "MSYSTEM", # MSYS2/Git Bash indicator |
| 68 | "MSYSTEM_CARCH", |
| 69 | "MSYSTEM_CHOST", |
| 70 | "MSYSTEM_PREFIX", |
| 71 | "MINGW_CHOST", |
| 72 | "MINGW_PACKAGE_PREFIX", |
| 73 | "MINGW_PREFIX", |
| 74 | "TERM", # Often set to 'xterm' in Git Bash |
| 75 | "SHELL", # Points to bash.exe in Git Bash |
| 76 | "BASH", |
| 77 | "BASH_ENV", |
| 78 | "SHLVL", |
| 79 | "OLDPWD", |
| 80 | "LS_COLORS", |
| 81 | "ACLOCAL_PATH", |
| 82 | "MANPATH", |
| 83 | "INFOPATH", |
| 84 | "PKG_CONFIG_PATH", |
| 85 | "ORIGINAL_PATH", |
| 86 | "MSYS", |
| 87 | } |
| 88 | |
| 89 | # Copy safe environment variables from parent |
| 90 | for key, value in os.environ.items(): |
| 91 | # Skip Git Bash indicators |
| 92 | if key in git_bash_vars: |
| 93 | continue |
| 94 | |
| 95 | # Skip variables starting with MSYS or MINGW prefixes |
| 96 | if key.startswith(("MSYS", "MINGW", "BASH_")): |
| 97 | continue |
| 98 | |
| 99 | # Keep important system variables |
| 100 | clean_env[key] = value |
| 101 | |
| 102 | # Ensure critical variables are set for Windows |
| 103 | if platform.system() == "Windows": |
| 104 | # Force UTF-8 encoding |
| 105 | clean_env["PYTHONIOENCODING"] = "utf-8:replace" |
| 106 | clean_env["PYTHONUTF8"] = "1" |
no test coverage detected