commit 3f675f0bd12df0d9130bf358ba937d26adea4c8b
parent 5bfbe558bebcd619b40c39f71a204d6a119d6488
Author: finwo <finwo@pm.me>
Date: Wed, 18 Oct 2023 21:39:23 +0200
Revert to full paths, using windows-specific symlinking now
Diffstat:
3 files changed, 73 insertions(+), 6 deletions(-)
diff --git a/dist/dep b/dist/dep
@@ -225,6 +225,39 @@ function cmd_add {
cmds[${#cmds[*]}]="a"
cmds[${#cmds[*]}]="add"
+# Origin: https://stackoverflow.com/a/25394801
+
+windows() { [[ -n "$WINDIR" ]]; }
+
+# Cross-platform symlink function. With one parameter, it will check
+# whether the parameter is a symlink. With two parameters, it will create
+# a symlink to a file or directory, with syntax: link $linkname $target
+lnk() {
+ if [[ -z "$2" ]]; then
+ # Link-checking mode.
+ if windows; then
+ fsutil reparsepoint query "$1" > /dev/null
+ else
+ [[ -h "$1" ]]
+ fi
+ else
+ # Link-creation mode.
+ if windows; then
+ # Windows needs to be told if it's a directory or not. Infer that.
+ # Also: note that we convert `/` to `\`. In this case it's necessary.
+ if [[ -d "$2" ]]; then
+ echo 'cmd <<< "mklink /D \"$1\" \"${2//\//\\}\"" > /dev/null'
+ cmd <<< "mklink /D \"$1\" \"${2//\//\\}\"" > /dev/null
+ else
+ echo 'cmd <<< "mklink \"$1\" \"${2//\//\\}\"" > /dev/null'
+ cmd <<< "mklink \"$1\" \"${2//\//\\}\"" > /dev/null
+ fi
+ else
+ echo ln -fs "$2" "$1"
+ ln -fs "$2" "$1"
+ fi
+ fi
+}
read -r -d '' help_topics[install] <<- EOF
Usage: dep [global options] install
@@ -266,7 +299,7 @@ cmds[${#cmds[*]}]="i"
cmds[${#cmds[*]}]="install"
CMD_INSTALL_PKG_NAME=
-CMD_INSTALL_PKG_DEST="lib"
+CMD_INSTALL_PKG_DEST="$(pwd)/lib"
declare -A CMD_INSTALL_DEPS
function cmd_install_parse_ini_main {
case "$1" in
@@ -276,7 +309,7 @@ function cmd_install_parse_ini_main {
CMD_INSTALL_PKG_NAME="$3"
;;
deps)
- CMD_INSTALL_PKG_DEST="$3"
+ CMD_INSTALL_PKG_DEST="$(pwd)/$3"
;;
esac
;;
@@ -395,7 +428,7 @@ function cmd_install_dep {
cat "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}" | sed "s|__DIRNAME|${CMD_INSTALL_PKG_DEST}/${name}|g" >> "${CMD_INSTALL_PKG_DEST}/.dep/${filetarget}"
;;
*)
- ln -fs "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}" "${CMD_INSTALL_PKG_DEST}/.dep/${filetarget}"
+ lnk "${CMD_INSTALL_PKG_DEST}/.dep/${filetarget}" "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}"
;;
esac
done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "export.")
diff --git a/src/command/install/index.sh b/src/command/install/index.sh
@@ -1,4 +1,5 @@
# #include "util/ini.sh"
+# #include "util/link.sh"
read -r -d '' help_topics[install] <<- EOF
# #include "help.txt"
@@ -34,7 +35,7 @@ cmds[${#cmds[*]}]="i"
cmds[${#cmds[*]}]="install"
CMD_INSTALL_PKG_NAME=
-CMD_INSTALL_PKG_DEST="lib"
+CMD_INSTALL_PKG_DEST="$(pwd)/lib"
declare -A CMD_INSTALL_DEPS
function cmd_install_parse_ini_main {
case "$1" in
@@ -44,7 +45,7 @@ function cmd_install_parse_ini_main {
CMD_INSTALL_PKG_NAME="$3"
;;
deps)
- CMD_INSTALL_PKG_DEST="$3"
+ CMD_INSTALL_PKG_DEST="$(pwd)/$3"
;;
esac
;;
@@ -163,7 +164,7 @@ function cmd_install_dep {
cat "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}" | sed "s|__DIRNAME|${CMD_INSTALL_PKG_DEST}/${name}|g" >> "${CMD_INSTALL_PKG_DEST}/.__NAME/${filetarget}"
;;
*)
- ln -fs "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}" "${CMD_INSTALL_PKG_DEST}/.__NAME/${filetarget}"
+ lnk "${CMD_INSTALL_PKG_DEST}/.__NAME/${filetarget}" "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}"
;;
esac
done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "export.")
diff --git a/src/util/link.sh b/src/util/link.sh
@@ -0,0 +1,33 @@
+# Origin: https://stackoverflow.com/a/25394801
+
+windows() { [[ -n "$WINDIR" ]]; }
+
+# Cross-platform symlink function. With one parameter, it will check
+# whether the parameter is a symlink. With two parameters, it will create
+# a symlink to a file or directory, with syntax: link $linkname $target
+lnk() {
+ if [[ -z "$2" ]]; then
+ # Link-checking mode.
+ if windows; then
+ fsutil reparsepoint query "$1" > /dev/null
+ else
+ [[ -h "$1" ]]
+ fi
+ else
+ # Link-creation mode.
+ if windows; then
+ # Windows needs to be told if it's a directory or not. Infer that.
+ # Also: note that we convert `/` to `\`. In this case it's necessary.
+ if [[ -d "$2" ]]; then
+ echo 'cmd <<< "mklink /D \"$1\" \"${2//\//\\}\"" > /dev/null'
+ cmd <<< "mklink /D \"$1\" \"${2//\//\\}\"" > /dev/null
+ else
+ echo 'cmd <<< "mklink \"$1\" \"${2//\//\\}\"" > /dev/null'
+ cmd <<< "mklink \"$1\" \"${2//\//\\}\"" > /dev/null
+ fi
+ else
+ echo ln -fs "$2" "$1"
+ ln -fs "$2" "$1"
+ fi
+ fi
+}