From e9aabcf5d5ddc1e65d7d804854ee20b8c24f72fd Mon Sep 17 00:00:00 2001
From: Matthew Pickering <matthewtpickering@gmail.com>
Date: Thu, 20 Jun 2024 17:41:48 +0100
Subject: [PATCH] bindist: Use complete relative paths when cding to
 directories

If a user has configured CDPATH on their system then `cd lib` may change
into an unexpected directory during the installation process.

If you write `cd ./lib` then it will not consult `CDPATH` to determine
what you mean.

I have added a check on ghcup-ci to verify that the bindist installation
works in this situation.

Fixes #24951

(cherry picked from commit 383c01a8928779920b4edea2f9d886ff303b8bd3)
---
 hadrian/bindist/Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hadrian/bindist/Makefile b/hadrian/bindist/Makefile
index 7a9579211c5..701e95ca4d5 100644
--- a/hadrian/bindist/Makefile
+++ b/hadrian/bindist/Makefile
@@ -165,7 +165,7 @@ install_lib: lib/settings
 	$(INSTALL_DIR) "$(DESTDIR)$(ActualLibsDir)"
 	
 	@dest="$(DESTDIR)$(ActualLibsDir)"; \
-	cd lib; \
+	cd ./lib; \
 	for i in `$(FIND) . -type f`; do \
 		$(INSTALL_DIR) "$$dest/`dirname $$i`" ; \
 		case $$i in \
@@ -195,7 +195,7 @@ install_docs:
 	$(INSTALL_DIR) "$(DESTDIR)$(docdir)"
 
 	if [ -d doc ]; then \
-		cd doc; $(FIND) . -type f -exec sh -c \
+		cd ./doc; $(FIND) . -type f -exec sh -c \
 			'$(INSTALL_DIR) "$(DESTDIR)$(docdir)/`dirname $$1`" && $(INSTALL_DATA) "$$1" "$(DESTDIR)$(docdir)/`dirname $$1`"' \
 			sh '{}' ';'; \
 	fi
@@ -210,7 +210,7 @@ install_docs:
 install_data:
 	@echo "Copying data to $(DESTDIR)share"
 	$(INSTALL_DIR) "$(DESTDIR)$(datadir)"
-	cd share; $(FIND) . -type f -exec sh -c \
+	cd ./share; $(FIND) . -type f -exec sh -c \
 		'$(INSTALL_DIR) "$(DESTDIR)$(datadir)/`dirname $$1`" && \
 		$(INSTALL_DATA) "$$1" "$(DESTDIR)$(datadir)/`dirname $$1`"' \
 		sh '{}' ';';
@@ -231,7 +231,7 @@ export SHELL
 install_wrappers: install_bin_libdir install_hsc2hs_wrapper
 	@echo "Installing wrapper scripts"
 	$(INSTALL_DIR) "$(DESTDIR)$(WrapperBinsDir)"
-	for p in `cd wrappers; $(FIND) . ! -type d`; do \
+	for p in `cd ./wrappers; $(FIND) . ! -type d`; do \
 	    mk/install_script.sh "$$p" "$(DESTDIR)/$(WrapperBinsDir)/$$p" "$(WrapperBinsDir)" "$(ActualBinsDir)" "$(ActualBinsDir)/$$p" "$(ActualLibsDir)" "$(docdir)" "$(includedir)"; \
 	done
 
-- 
GitLab