File 4722-Update-w32_path-for-WSL.patch of Package erlang

From 10fe8d43092a3c661648ca8e93c8088a6988d6f4 Mon Sep 17 00:00:00 2001
From: Dan Gudmundsson <dgud@erlang.org>
Date: Thu, 11 Jun 2020 12:02:28 +0200
Subject: [PATCH 1/2] Update w32_path for WSL

'wslpath' have changed in the latest release.

When converting to windows paths 'wslpath' now always output absolute
paths, and file/dir must exist otherwise it fails.

Patch 'w32_path.sh' to handle this, also use that in 'erlc' instead
of using wslpath directly.

I'm keeping the other uses of 'wslpath' for now since it should be
slightly faster, the build times are already to long.
---
 erts/etc/win32/wsl_tools/erlc        |  6 +--
 erts/etc/win32/wsl_tools/w32_path.sh | 73 +++++++++++++++++++++++-----
 2 files changed, 64 insertions(+), 15 deletions(-)

diff --git a/erts/etc/win32/wsl_tools/erlc b/erts/etc/win32/wsl_tools/erlc
index 956ac19abd..bca537f751 100755
--- a/erts/etc/win32/wsl_tools/erlc
+++ b/erts/etc/win32/wsl_tools/erlc
@@ -29,14 +29,14 @@ for x in "$@"; do
 	-I/*|-o/*)
 	    y=`echo $x | sed 's,^-[Io]\(/.*\),\1,g'`;
 	    z=`echo $x | sed 's,^-\([Io]\)\(/.*\),\1,g'`;
-	    MPATH=`wslpath -m $y`;
+	    MPATH=`w32_path.sh -m $y`;
 	    CMD="$CMD -$z$MPATH";;
 	-pa/*)
 	    y=`echo $x | sed 's,^-pa\(/.*\),\1,g'`;
-	    MPATH=`wslpath -m $y`;
+	    MPATH=`w32_path.sh -m $y`;
 	    CMD="$CMD -pa $MPATH";;
 	/*)
-	    MPATH=`wslpath -m $x`;
+	    MPATH=`w32_path.sh -m $x`;
 	    CMD="$CMD \"$MPATH\"";;
 # Needed for  +'{preproc_flags,whatever}'
 	+{preproc_flags,*})
diff --git a/erts/etc/win32/wsl_tools/w32_path.sh b/erts/etc/win32/wsl_tools/w32_path.sh
index 55fbd76174..52bcddfe5b 100755
--- a/erts/etc/win32/wsl_tools/w32_path.sh
+++ b/erts/etc/win32/wsl_tools/w32_path.sh
@@ -41,6 +41,15 @@ if [ -z "$1" ]; then
     exit 1;
 fi
 
+case "$1" in
+    /*)
+        rel_input=false
+        ;;
+    *)
+        rel_input=true
+        ;;
+esac
+
 if [ $UNIX = true ]; then
     # cl.exe loses //// in the beginning which make dependencies fail
     # and sometimes lowercases the path
@@ -55,16 +64,56 @@ if [ $UNIX = true ]; then
             ;;
     esac
 else
-    case "$SEPARATOR" in
-	slash)
-	    echo `wslpath -m $ABSOLUTE "$1"`;
-	    ;;
-	backslash)
-	    echo `wslpath -w $ABSOLUTE "$1"`;
-	    ;;
-	double)
-	    DOUBLE=`wslpath -w $ABSOLUTE "$1" | sed 's,\\\\,\\\\\\\\,g'`;
-	    echo $DOUBLE
-	    ;;
-    esac
+    #  wslpath have changed to always return absolute paths and
+    #  ensure the file/dir exists before translation
+
+    if [ $rel_input = true -a "$ABSOLUTE" = "" ]; then
+        case "$SEPARATOR" in
+	    slash)
+                echo $1
+                ;;
+            backslash)
+                echo "$1" | sed 's,/,\\,g'
+                ;;
+            double)
+                echo "$1" | sed 's,/,\\\\,g'
+                ;;
+        esac
+        exit 0
+    fi
+
+    # absolute input and/or absolute output
+
+    if [ -d "$1" ]; then
+        dir=$1;
+        case "$SEPARATOR" in
+	    slash)
+	        echo `wslpath -m $ABSOLUTE "$dir"`;
+	        ;;
+	    backslash)
+	        echo `wslpath -w $ABSOLUTE "$dir"`;
+	        ;;
+	    double)
+	        DOUBLE=`wslpath -w $ABSOLUTE "$dir" | sed 's,\\\\,\\\\\\\\,g'`;
+	        echo $DOUBLE
+	        ;;
+        esac
+        exit 0
+    else
+        dir=`dirname $1`
+        file=`basename $1`
+
+        case "$SEPARATOR" in
+	    slash)
+	        echo `wslpath -m $ABSOLUTE "$dir"`/$file;
+	        ;;
+	    backslash)
+	        echo `wslpath -w $ABSOLUTE "$dir"`\\$file;
+	        ;;
+	    double)
+	        DOUBLE=`wslpath -w $ABSOLUTE "$dir" | sed 's,\\\\,\\\\\\\\,g'`;
+	        echo $DOUBLE\\\\$file
+	        ;;
+        esac
+    fi
 fi
-- 
2.26.2

openSUSE Build Service is sponsored by