tools/build: Create toolchain symlinks for non-absolute compiler/linker

If any of the toolchain variables are not absolute then we need to
create a symlink in WORLDTMP/legacy/bin in order to make them available
during a BUILD_WITH_STRICT_TMPPATH build.

Reviewed by:	brooks, jhb
Differential Revision:	https://reviews.freebsd.org/D41188
This commit is contained in:
Jessica Clarke 2023-07-27 05:10:47 +01:00
parent 81805ec300
commit 65f28f63a7
2 changed files with 28 additions and 4 deletions

View File

@ -602,9 +602,8 @@ STRICTTMPPATH= ${XPATH}:${BPATH}:${UNIVERSE_TOOLCHAIN_PATH}
# still allow using the old behaviour (inheriting $PATH) if
# BUILD_WITH_STRICT_TMPPATH is set to 0 but this will eventually be removed.
# Currently strict $PATH can cause build failures and does not work yet with
# USING_SYSTEM_LINKER/USING_SYSTEM_COMPILER. Once these issues have been
# resolved it will be turned on by default.
# Currently strict $PATH can cause build failures. Once the remaining issues
# have been resolved it will be turned on by default.
BUILD_WITH_STRICT_TMPPATH?=0
.if defined(CROSSBUILD_HOST)
# When building on non-FreeBSD we can't rely on the tools in /usr/bin being compatible

View File

@ -312,6 +312,8 @@ _host_tools_to_symlink= basename bzip2 bunzip2 chmod chown cmp comm cp date dd \
_make_abs!= which "${MAKE}"
_host_abs_tools_to_symlink= ${_make_abs}:make ${_make_abs}:bmake
_LINK_HOST_TOOL= ln -sfn
.if ${.MAKE.OS} == "FreeBSD"
# When building on FreeBSD we always copy the host tools instead of linking
# into WORLDTMP to avoid issues with incompatible libraries (see r364030).
@ -322,7 +324,7 @@ _COPY_HOST_TOOL= cp -pf
# tools to another directory with cp -p results in freezes on macOS Big Sur for
# some unknown reason. It can also break building inside docker containers if
# there are ACLs on shared volumes.
_COPY_HOST_TOOL= ln -sfn
_COPY_HOST_TOOL= ${_LINK_HOST_TOOL}
.if ${.MAKE.OS} == "Darwin"
# /usr/bin/cpp may invoke xcrun:
@ -335,6 +337,20 @@ _host_abs_tools_to_symlink+= /bin/bash:sh
_host_tools_to_symlink:= ${_host_tools_to_symlink:Nsh}
.endif
# We also need to symlink any non-absolute toolchain commands. Clang finds its
# resource directory relative to itself, so CC/CXX/CPP must be symlinked, and
# we do the same for LD for consistency. There should be no concerns about
# installing over the current system since we don't use the toolchain during
# install.
.for var in CC CXX CPP LD
.for X in $${_empty_var_} X
.if !empty(${X}${var}) && !${${X}${var}:M/*} && \
!${_toolchain_tools_to_symlink:U:M${${X}${var}}}
_toolchain_tools_to_symlink+= ${${X}${var}}
.endif
.endfor
.endfor
host-symlinks:
@echo "Linking host tools into ${DESTDIR}/bin"
.for _tool in ${_host_tools_to_symlink}
@ -359,6 +375,15 @@ host-symlinks:
rm -f ${DESTDIR}/usr/libexec/flua
${_COPY_HOST_TOOL} /usr/libexec/flua ${DESTDIR}/usr/libexec/flua
.endif
.for _tool in ${_toolchain_tools_to_symlink}
@export PATH=$${PATH}:/usr/local/bin; \
source_path=`which ${_tool} || echo /dev/null/no/such`; \
if [ ! -e "$${source_path}" ] ; then \
echo "Cannot find host tool '${_tool}' in PATH ($$PATH)." >&2; false; \
fi; \
rm -f "${DESTDIR}/bin/${_tool}"; \
${_LINK_HOST_TOOL} "$${source_path}" "${DESTDIR}/bin/${_tool}"
.endfor
# Create all the directories that are needed during the legacy, bootstrap-tools
# and cross-tools stages. We do this here using mkdir since mtree may not exist