Skip to content

Commit 553861c

Browse files
committed
fix: keep E2E registry paths out of GCC prefix controls
1 parent 9229b97 commit 553861c

4 files changed

Lines changed: 81 additions & 4 deletions

File tree

‎.agents/docs/2026-10-08-llvm-2313-part2-execution-and-dependencies.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,32 @@ c29e53df 的 fresh-install workflow 在启动前失败,GitHub annotation
213213
先验证构建脚本与来源一致,再重新执行原生准入,结果成功。
214214
旧头及排队中的重复全量构建取消;该复用不覆盖安装消费门,也
215215
不重新发布任何已钉住的归档。
216+
217+
## 11. 2026-10-08 Windows 前端查找根因更正
218+
219+
同一头 9229b979 的 Windows 单测与打包成功后,bare Windows
220+
[113062257150](https://github.com/mcpp-community/mcpp/actions/runs/37699239809/job/113062257150)
221+
再次失败,独立驱动目录保留了真实载荷与 shim 的不同证据。真实
222+
g++ 16.1.0 的摘要与归档一致;cc1plus 直接编译 C++ 源成功并生成
223+
汇编。PowerShell 长路径和完整 8.3 路径调用均失败,两个驱动搜索
224+
列表都把辅助程序前缀指向全局 xim-x-gcc,载荷自身的安装前缀正确。
225+
这组对照排除了短路径单独致错及辅助程序缺失的解释。
226+
227+
最终根因为本 PR 的测试版本抽象层导出了 GCC_ROOT。182 在创建
228+
隔离 MCPP_HOME 前加载该层,GCC_ROOT 因而指向全局通用 GCC 目录。
229+
[GCC 的前缀处理](https://github.com/gcc-mirror/gcc/blob/master/gcc/prefix.cc)
230+
将 GCC_ROOT 作为驱动控制变量,替换辅助程序及库的搜索根;隔离的
231+
MinGW 载荷因此查不到自身的 cc1plus。原环境快照仅包含
232+
GCC_EXEC_PREFIX,遗漏了这个变量。此前把失败归因为 Windows 底镜像
233+
滚动或 Defender 的结论撤回;15.2.0 搜索列表来自被覆盖的 shim
234+
报告,亦不能用于推断真实 16.1.0 驱动。本次归因由独立真实载荷
235+
报告与 GCC 源码支持,基础设施假设不再作为合入豁免。
236+
237+
测试路径变量改为 MCPP_E2E_GCC_ROOT,保持用户原有 GCC_ROOT 不变。
238+
诊断同时捕获 GCC_ROOT、BINUTILS_ROOT 及测试路径变量。真实 Linux
239+
GCC 16.1.0 对照验证:正常环境编译成功;显式不存在的 GCC_ROOT
240+
使驱动返回裸 cc1plus 并编译失败;加载修正后的测试层保留两种
241+
行为。四项聚焦测试、Bash 语法及差异检查通过。此修复也消除原生
242+
ARM64 消费门切换至 musl GCC 时同一测试变量造成的前端查找污染,
243+
但 Windows 与 ARM64 的最终通过状态仍须新头执行确认。引擎算法、
244+
编译器归档及镜像摘要不变,无须重新发布资源。

‎tests/e2e/182_windows_no_msvc_fallback.sh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ cleanup() {
9090
done < <(find "$MCPP_HOME/registry/subos" -name g++.exe -type f 2>/dev/null)
9191
printf 'GCC_EXEC_PREFIX=%s\nCOMPILER_PATH=%s\nLIBRARY_PATH=%s\n' \
9292
"${GCC_EXEC_PREFIX:-}" "${COMPILER_PATH:-}" "${LIBRARY_PATH:-}" > "$report/driver-environment.txt"
93+
printf 'GCC_ROOT=%s\nBINUTILS_ROOT=%s\nMCPP_E2E_GCC_ROOT=%s\n' \
94+
"${GCC_ROOT:-}" "${BINUTILS_ROOT:-}" "${MCPP_E2E_GCC_ROOT:-}" >> "$report/driver-environment.txt"
9395
printf 'XLINGS_HOME=%s\nXLINGS_PROJECT_DIR=%s\nXLINGS_ACTIVE_SUBOS=%s\nPATH=%s\n' \
9496
"${XLINGS_HOME:-}" "${XLINGS_PROJECT_DIR:-}" "${XLINGS_ACTIVE_SUBOS:-}" "$PATH" \
9597
>> "$report/driver-environment.txt"
9698
command -v g++ > "$report/ambient-driver-path.txt" 2>&1 || true
9799
# Windows variable names are case-insensitive; Bash's lookup is not.
98-
env | grep -Ei '^(gcc_exec_prefix|compiler_path|library_path|collect_gcc|collect_lto_wrapper|xlings_[^=]*|msys[^=]*)=' \
100+
env | grep -Ei '^(gcc_[^=]*|binutils_root|mcpp_e2e_gcc_root|compiler_path|library_path|collect_gcc|collect_lto_wrapper|xlings_[^=]*|msys[^=]*)=' \
99101
> "$report/driver-environment-all-cases.txt" || true
100102
while IFS= read -r helper; do
101103
echo "Direct invocation: $helper"

‎tests/e2e/_toolchain_env.sh‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# payload the fallback stands, which is what lets a fixture pin a toolchain
2323
# the engine then installs on first use):
2424
# LLVM_VERSION / LLVM_ROOT store dir xim-x-llvm
25-
# GCC_VERSION / GCC_ROOT store dir xim-x-gcc
25+
# GCC_VERSION / MCPP_E2E_GCC_ROOT store dir xim-x-gcc
2626
# MUSL_GCC_VERSION / MUSL_GCC_ROOT store dir xim-x-musl-gcc
2727
# MINGW_CROSS_VERSION / MINGW_CROSS_ROOT store dir xim-x-mingw-cross-gcc
2828
#
@@ -61,13 +61,16 @@ LLVM_VERSION="$(_e2e_family_version xim-x-llvm MCPP_E2E_LLVM_VERSION 23.1.3)"
6161
LLVM_ROOT="$(_e2e_family_root xim-x-llvm "$LLVM_VERSION")"
6262

6363
GCC_VERSION="$(_e2e_family_version xim-x-gcc MCPP_E2E_GCC_VERSION 16.1.0)"
64-
GCC_ROOT="$(_e2e_family_root xim-x-gcc "$GCC_VERSION")"
64+
# GCC_ROOT is a compiler control variable: GCC uses it to rewrite executable
65+
# and library prefixes. A fixture's registry path must not alter the driver's
66+
# lookup, especially after a test switches to a cold MCPP_HOME.
67+
MCPP_E2E_GCC_ROOT="$(_e2e_family_root xim-x-gcc "$GCC_VERSION")"
6568

6669
MUSL_GCC_VERSION="$(_e2e_family_version xim-x-musl-gcc MCPP_E2E_MUSL_GCC_VERSION 15.1.0)"
6770
MUSL_GCC_ROOT="$(_e2e_family_root xim-x-musl-gcc "$MUSL_GCC_VERSION")"
6871

6972
MINGW_CROSS_VERSION="$(_e2e_family_version xim-x-mingw-cross-gcc MCPP_E2E_MINGW_CROSS_VERSION 16.1.0)"
7073
MINGW_CROSS_ROOT="$(_e2e_family_root xim-x-mingw-cross-gcc "$MINGW_CROSS_VERSION")"
7174

72-
export LLVM_VERSION LLVM_ROOT GCC_VERSION GCC_ROOT \
75+
export LLVM_VERSION LLVM_ROOT GCC_VERSION MCPP_E2E_GCC_ROOT \
7376
MUSL_GCC_VERSION MUSL_GCC_ROOT MINGW_CROSS_VERSION MINGW_CROSS_ROOT

‎tests/scripts/test_toolchain_env.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""The E2E helper selects payloads from the effective mcpp registry."""
22
import os
33
from pathlib import Path
4+
import shutil
45
import subprocess
56
import tempfile
67
import unittest
@@ -9,6 +10,48 @@
910

1011

1112
class ToolchainRegistry(unittest.TestCase):
13+
def test_real_gcc_compiles_after_helper_without_losing_user_prefix(self):
14+
compiler = os.environ.get('MCPP_E2E_GCC_DRIVER') or shutil.which('g++')
15+
if not compiler:
16+
self.skipTest('a real GCC C++ driver is unavailable')
17+
version = subprocess.run([compiler, '--version'], capture_output=True, text=True, check=True)
18+
if 'clang' in version.stdout.lower():
19+
self.skipTest('g++ is a Clang alias')
20+
with tempfile.TemporaryDirectory() as directory:
21+
root = Path(directory)
22+
source = root / 'probe.cpp'
23+
source.write_text('int answer() { return 42; }\n')
24+
env = dict(os.environ, MCPP_HOME=str(root / 'cold-home'))
25+
env.pop('GCC_ROOT', None)
26+
args = [compiler, '-c', str(source), '-o', str(root / 'probe.o')]
27+
clean = subprocess.run(args, env=env, capture_output=True, text=True)
28+
self.assertEqual(clean.returncode, 0, clean.stderr)
29+
# A nonexistent explicit compiler prefix reproduces the exact
30+
# missing-cc1plus failure from the isolated Windows fixture.
31+
bad_env = dict(env, GCC_ROOT=str(root / 'missing-gcc-root'))
32+
bad = subprocess.run(args, env=bad_env, capture_output=True, text=True)
33+
self.assertNotEqual(bad.returncode, 0)
34+
self.assertIn('cc1plus', bad.stderr)
35+
for context, expected in ((env, 0), (bad_env, bad.returncode)):
36+
after = subprocess.run(
37+
['bash', '-c', 'source "$1"; shift; "$@"', 'bash', str(HELPER), *args],
38+
env=context, capture_output=True, text=True)
39+
self.assertEqual(after.returncode, expected, after.stderr)
40+
41+
def test_fixture_paths_do_not_change_gcc_child_process_prefix(self):
42+
# GCC interprets GCC_ROOT itself; exporting a fixture registry root
43+
# makes a cold MinGW driver search another installation for cc1plus.
44+
for existing in (None, '/explicit/compiler/root'):
45+
with self.subTest(existing=existing), tempfile.TemporaryDirectory() as directory:
46+
env = dict(os.environ, MCPP_HOME=directory)
47+
env.pop('GCC_ROOT', None)
48+
if existing is not None:
49+
env['GCC_ROOT'] = existing
50+
result = subprocess.run(
51+
['bash', '-c', 'source "$1"; bash -c \'printf "%s" "${GCC_ROOT-unset}"\'',
52+
'bash', str(HELPER)], env=env, capture_output=True, text=True, check=True)
53+
self.assertEqual(result.stdout, existing if existing is not None else 'unset')
54+
1255
def test_explicit_home_outranks_home_and_userprofile(self):
1356
with tempfile.TemporaryDirectory() as directory:
1457
root = Path(directory)

0 commit comments

Comments
 (0)