Skip to content

Commit 886158f

Browse files
fix: ccache fix
1 parent 31706e8 commit 886158f

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

scripts/build_helper/build-buildroot.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,21 @@ fi
117117
# arm-none-linux-gnueabihf-gcc 的真实位置反推,换机器/换工具链版本都不用改 defconfig。
118118
# buildroot 的 Kconfig 符号不取 `make BR2_X=Y` 命令行覆盖(conf 只读 .config),
119119
# 故算出 TC_ROOT 后在 Step 1c 用 sed 写进 .config + olddefconfig 规范化。
120-
_tc_gcc="$(command -v arm-none-linux-gnueabihf-gcc || true)"
120+
# 遍历 PATH 找真实 gcc,跳过 ccache 包装:CI(及本地若配了 ccache)在 PATH 前段塞
121+
# ccache-bin/arm-none-linux-gnueabihf-gcc -> /usr/bin/ccache 符号链接,command -v 会先命中它,
122+
# readlink -f 解析到 .../ccache → 误把工具链根算成 /usr,buildroot 去找 /usr/bin/...gcc
123+
# 报 "Cannot execute cross-compiler"。取第一个 readlink 后 basename 不是 ccache 的候选。
124+
_tc_gcc=""
125+
_oifs="$IFS"; IFS=':'; read -ra _pd <<< "${PATH}"; IFS="$_oifs"
126+
for _d in "${_pd[@]}"; do
127+
[[ -z "$_d" ]] && continue
128+
_c="${_d}/arm-none-linux-gnueabihf-gcc"
129+
[[ -x "$_c" ]] || continue
130+
_r="$(readlink -f "$_c" 2>/dev/null || printf '%s' "$_c")"
131+
[[ "$(basename "$_r")" == "ccache" ]] && continue # ccache 包装,跳过
132+
_tc_gcc="$_c"; break
133+
done
134+
unset _oifs _pd _d _c _r
121135
if [[ -n "${_tc_gcc}" ]]; then
122136
TC_ROOT="$(cd "$(dirname "$(readlink -f "${_tc_gcc}")")/.." && pwd)"
123137
else

0 commit comments

Comments
 (0)