From 6ce1cc9953da44133f5646e3c11e7ba38f9ca90f Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Tue, 28 Jun 2022 14:34:04 +0200 Subject: [PATCH] support customizing install directory with $DPATH This introduces the $DPATH environment variable to override the user's home directory just for D tools. This is also intended to be used by DUB (https://github.com/dlang/dub/pull/2281) when there is not the more explicit `$DUB_HOME` variable set on the system. This allows users who install their D compiler through the install.sh script to both have the compiler installations as well as the dub packages be stored elsewhere in the system than in their home folder. In case we have other tools that download their dependencies into the user's home directory, we should also make them support the same $DPATH environment variable. --- changelog/dpath.dd | 5 +++++ script/install.sh | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 changelog/dpath.dd diff --git a/changelog/dpath.dd b/changelog/dpath.dd new file mode 100644 index 00000000..d5446358 --- /dev/null +++ b/changelog/dpath.dd @@ -0,0 +1,5 @@ +The `install.sh` script now respects the `$DPATH` environment variable + +The `$DPATH` environment variable can be set on any system to make the install location of the install.sh script as well as other D related tools like DUB to store their cache files, dependencies, installed compilers, etc. + +This way you can change where all the D tools are installed and keep a clean home folder. diff --git a/script/install.sh b/script/install.sh index 81970369..b534b325 100755 --- a/script/install.sh +++ b/script/install.sh @@ -176,13 +176,21 @@ GET_PATH_AUTO_INSTALL=0 GET_PATH_COMPILER=dc # Set a default install path depending on the POSIX/Windows environment. if posix_terminal; then - ROOT=~/dlang + if [ -z "$DPATH" ]; then + ROOT=~/dlang + else + ROOT="$DPATH/dlang" + fi else - # Default to a ROOT that is outside the POSIX-like environment. - if [ -z "$USERPROFILE" ]; then - fatal '%USERPROFILE% should not be empty on Windows.'; + if [ -z "$DPATH" ]; then + # Default to a ROOT that is outside the POSIX-like environment. + if [ -z "$USERPROFILE" ]; then + fatal '%USERPROFILE% should not be empty on Windows.'; + fi + ROOT=$(posix_path "$USERPROFILE")/dlang + else + ROOT=$(posix_path "$DPATH")/dlang fi - ROOT=$(posix_path "$USERPROFILE")/dlang fi TMP_ROOT= DUB_VERSION=