diff options
author | Ben Gamari <ben@smart-cactus.org> | 2021-11-19 22:59:35 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2021-12-01 20:19:08 -0500 |
commit | d0f9bcfa15ac2fc81325065cb8732c581e16c946 (patch) | |
tree | e051b07c3626b106f5f6a59127e7c7a97d1b1d31 | |
parent | 14e9cab675f5b0abf2c303a0aa455237768103d1 (diff) | |
download | haskell-d0f9bcfa15ac2fc81325065cb8732c581e16c946.tar.gz |
hadrian: Don't rely on realpath in bindist Makefilewip/T19963
As noted in #19963, `realpath` is not specified by POSIX and therefore
cannot be assumed to be available. Here we provide a POSIX shell
implementation of `realpath`, due to Julian Ospald and others.
Closes #19963.
-rw-r--r-- | hadrian/bindist/Makefile | 2 | ||||
-rw-r--r-- | hadrian/src/Rules/BinaryDist.hs | 7 | ||||
-rwxr-xr-x | mk/relpath.sh | 53 |
3 files changed, 58 insertions, 4 deletions
diff --git a/hadrian/bindist/Makefile b/hadrian/bindist/Makefile index 4276fe7a86..3ae599452f 100644 --- a/hadrian/bindist/Makefile +++ b/hadrian/bindist/Makefile @@ -202,7 +202,7 @@ update_package_db: install_bin install_lib @echo "$(PKG_CONFS)" @echo "Updating the package DB" $(foreach p, $(PKG_CONFS),\ - $(call patchpackageconf,$(shell echo $(notdir $p) | sed 's/-\([0-9]*[0-9]\.\)*conf//g'),$(shell echo "$p" | sed 's:xxx: :g'),$(docdir),$(shell realpath --relative-to="$(ActualLibsDir)" "$(docdir)"))) + $(call patchpackageconf,$(shell echo $(notdir $p) | sed 's/-\([0-9]*[0-9]\.\)*conf//g'),$(shell echo "$p" | sed 's:xxx: :g'),$(docdir),$(shell mk/relpath.sh "$(ActualLibsDir)" "$(docdir)"))) '$(WrapperBinsDir)/$(CrossCompilePrefix)ghc-pkg' recache install_mingw: diff --git a/hadrian/src/Rules/BinaryDist.hs b/hadrian/src/Rules/BinaryDist.hs index c86d42d8f0..914039d9e8 100644 --- a/hadrian/src/Rules/BinaryDist.hs +++ b/hadrian/src/Rules/BinaryDist.hs @@ -337,9 +337,10 @@ compressorExtension Bzip2 = "bz2" -- @./configure [...] && make install@ workflow. bindistInstallFiles :: [FilePath] bindistInstallFiles = - [ "config.sub", "config.guess", "install-sh", "mk" -/- "config.mk.in" - , "mk" -/- "install.mk.in", "mk" -/- "project.mk", "README" - , "INSTALL" ] + [ "config.sub", "config.guess", "install-sh" + , "mk" -/- "config.mk.in", "mk" -/- "install.mk.in", "mk" -/- "project.mk" + , "mk" -/- "relpath.sh" + , "README", "INSTALL" ] -- | This auxiliary function gives us a top-level 'Filepath' that we can 'need' -- for all libraries and programs that are needed for a complete build. diff --git a/mk/relpath.sh b/mk/relpath.sh new file mode 100755 index 0000000000..c2f82f430b --- /dev/null +++ b/mk/relpath.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# POSIX shell implementation of `realpath --relative-to=$1 $2. +# This is an adaptation of the implementation from +# <https://github.com/Offirmo/offirmo-shell-lib>. + +# returns relative path to $2=$target from $1=$source +## NOTE : path are compared in text only. They don’t have to exist +## and they WONT be normalized/escaped +## Result in "$return_value"# both $1 and $2 are absolute paths beginning with / + +src="$1" +target="$2" + +common_part="$src" +result="" + +while test "${target#$common_part}" = "${target}" ; do + #echo "common_part is now : \"$common_part\"" + #echo "result is now : \"$result\"" + #echo "target#common_part : \"${target#$common_part}\"" + # no match, means that candidate common part is not correct + # go up one level (reduce common part) + common_part="$(dirname "$common_part")" + # and record that we went back + if test -z "$result" ; then + result=".." + else + result="../$result" + fi +done + +#echo "common_part is : \"$common_part\"" + +if test "$common_part" = "/" ; then + # special case for root (no common path) + result="$result/" +fi + +# since we now have identified the common part, +# compute the non-common part +forward_part="${target#$common_part}" +#echo "forward_part = \"$forward_part\"" + +if test -n "$result" && test -n "$forward_part" ; then + #echo "(simple concat)" + result="$result$forward_part" +elif test -n "$forward_part" ; then + #echo "(concat with slash removal)" + result="$(printf "%s" "$forward_part" | cut -c 1-)" +fi + +printf "%s" "$result" |