--- old/make/autoconf/basics_windows.m4 2018-12-13 10:21:49.811231600 -0800 +++ new/make/autoconf/basics_windows.m4 2018-12-13 10:21:49.279999700 -0800 @@ -32,6 +32,13 @@ elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then unix_path=`$ECHO "$windows_path" | $SED -e 's,^\\(.\\):,/\\1,g' -e 's,\\\\,/,g'` $1="$unix_path" + elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then + # wslpath does not check the input, only call if an actual windows path was + # given. + if $ECHO "$windows_path" | $GREP -q ["^[a-zA-Z]:[\\\\/]"]; then + unix_path=`$WSLPATH -u "$windows_path"` + $1="$unix_path" + fi fi ]) @@ -44,6 +51,9 @@ elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then windows_path=`cmd //c echo $unix_path` $1="$windows_path" + elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then + windows_path=`$WSLPATH -m "$unix_path"` + $1="$windows_path" fi ]) @@ -100,6 +110,31 @@ fi ]) +# Helper function which possibly converts a path using DOS-style short mode. +# If so, the updated path is stored in $new_path. +# $1: The path to check +AC_DEFUN([BASIC_MAKE_WINDOWS_SPACE_SAFE_WSL], +[ + input_path="$1" + # Check if we need to convert this using DOS-style short mode. If the path + # contains just simple characters, use it. Otherwise (spaces, weird characters), + # take no chances and rewrite it. + # Note: m4 eats our [], so we need to use @<:@ and @:>@ instead. + has_forbidden_chars=`$ECHO "$input_path" | $GREP [[^-_/:a-zA-Z0-9\\.]]` + if test "x$has_forbidden_chars" != x; then + # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \) + TOPDIR_windows="$TOPDIR" + BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([TOPDIR_windows]) + # First convert to Windows path to make input valid for cmd + BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([input_path]) + new_path=`$CMD /c $TOPDIR_windows/make/scripts/windowsShortName.cmd "$input_path" \ + | $SED -e 's|\r||g' \ + | $TR \\\\\\\\ / | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + # Rewrite back to unix style + BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([new_path]) + fi +]) + # FIXME: The BASIC_FIXUP_*_CYGWIN/MSYS is most likely too convoluted # and could probably be heavily simplified. However, all changes in this # area tend to need lot of testing in different scenarios, and in lack of @@ -157,6 +192,23 @@ all_fixpath_prefixes=("${all_fixpath_prefixes@<:@@@:>@}" "${new_path:0:10}") ]) +AC_DEFUN([BASIC_FIXUP_PATH_WSL], +[ + # Input might be given as Windows format, start by converting to + # unix format. + new_path="[$]$1" + BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([new_path]) + + # Call helper function which possibly converts this using DOS-style short mode. + # If so, the updated path is stored in $new_path. + BASIC_MAKE_WINDOWS_SPACE_SAFE_WSL([$new_path]) + + if test "x$path" != "x$new_path"; then + $1="$new_path" + AC_MSG_NOTICE([Rewriting $1 to "$new_path"]) + fi +]) + AC_DEFUN([BASIC_FIXUP_EXECUTABLE_CYGWIN], [ # First separate the path from the arguments. This will split at the first @@ -305,6 +357,79 @@ fi ]) +AC_DEFUN([BASIC_FIXUP_EXECUTABLE_WSL], +[ + # First separate the path from the arguments. This will split at the first + # space. + complete="[$]$1" + path="${complete%% *}" + tmp="$complete EOL" + arguments="${tmp#* }" + + # Input might be given as Windows format, start by converting to + # unix format. + new_path="$path" + BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([new_path]) + + # Now try to locate executable using which + new_path_bak="$new_path" + new_path=`$WHICH "$new_path" 2> /dev/null` + # bat and cmd files are not considered executable in WSL + if test "x$new_path" = x \ + && test "x`$ECHO \"$path\" | $GREP -i -e \"\\.bat$\" -e \"\\.cmd$\"`" != x \ + && test "x`$LS \"$path\" 2>/dev/null`" != x; then + new_path="$new_path_back" + fi + if test "x$new_path" = x; then + # Oops. Which didn't find the executable. + # The splitting of arguments from the executable at a space might have been incorrect, + # since paths with space are more likely in Windows. Give it another try with the whole + # argument. + path="$complete" + arguments="EOL" + new_path="$path" + BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([new_path]) + new_path_bak="$new_path" + new_path=`$WHICH "$new_path" 2> /dev/null` + # bat and cmd files are not considered executable in WSL + if test "x$new_path" = x \ + && test "x`$ECHO \"$path\" | $GREP -i -e \"\\.bat$\" -e \"\\.cmd$\"`" != x \ + && test "x`$LS \"$path\" 2>/dev/null`" != x; then + new_path="$new_path_bak" + fi + if test "x$new_path" = x; then + # It's still not found. Now this is an unrecoverable error. + AC_MSG_NOTICE([The path of $1, which resolves as "$complete", is not found.]) + has_space=`$ECHO "$complete" | $GREP " "` + if test "x$has_space" != x; then + AC_MSG_NOTICE([You might be mixing spaces in the path and extra arguments, which is not allowed.]) + fi + AC_MSG_ERROR([Cannot locate the the path of $1]) + fi + fi + + # In WSL, suffixes must be present for Windows executables + if test ! -f "$new_path"; then + # Try adding .exe or .cmd + if test -f "${new_path}.exe"; then + input_to_shortpath="${new_path}.exe" + elif test -f "${new_path}.cmd"; then + input_to_shortpath="${new_path}.cmd" + else + AC_MSG_NOTICE([The path of $1, which resolves as "$new_path", is invalid.]) + AC_MSG_NOTICE([Neither "$new_path" nor "$new_path.exe/cmd" can be found]) + AC_MSG_ERROR([Cannot locate the the path of $1]) + fi + else + input_to_shortpath="$new_path" + fi + + # Call helper function which possibly converts this using DOS-style short mode. + # If so, the updated path is stored in $new_path. + new_path="$input_to_shortpath" + BASIC_MAKE_WINDOWS_SPACE_SAFE_WSL([$input_to_shortpath]) +]) + # Setup basic configuration paths, and platform-specific stuff related to PATHs. AC_DEFUN([BASIC_CHECK_PATHS_WINDOWS], [ @@ -339,6 +464,7 @@ if test "x$test_cygdrive_prefix" = x; then AC_MSG_ERROR([Your cygdrive prefix is not /cygdrive. This is currently not supported. Change with mount -c.]) fi + EXECUTABLE_SUFFIX="" elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then AC_MSG_CHECKING([msys release]) MSYS_VERSION=`$UNAME -r` @@ -353,8 +479,11 @@ BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(MSYS_ROOT_PATH) AC_MSG_RESULT([$MSYS_ROOT_PATH]) WINDOWS_ENV_ROOT_PATH="$MSYS_ROOT_PATH" + EXECUTABLE_SUFFIX="" + elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then + EXECUTABLE_SUFFIX=".exe" else - AC_MSG_ERROR([Unknown Windows environment. Neither cygwin nor msys was detected.]) + AC_MSG_ERROR([Unknown Windows environment. Neither cygwin, msys, nor wsl was detected.]) fi # Test if windows or unix (cygwin/msys) find is first in path. @@ -395,6 +524,8 @@ | tr ' ' '\n' | $GREP '^/./' | $SORT | $UNIQ` fixpath_argument_list=`echo $all_unique_prefixes | tr ' ' '@'` FIXPATH="$FIXPATH_BIN -m$fixpath_argument_list" + elif test "x$OPENJDK_BUILD_OS_ENV" = xwindows.wsl; then + FIXPATH="$FIXPATH_BIN -w" fi FIXPATH_SRC_W="$FIXPATH_SRC" FIXPATH_BIN_W="$FIXPATH_BIN"