Fri, 06 Apr 2018 04:13:09 -0700
8035751: Clean up Visual Studio detection logic
Reviewed-by: ihse, erikj, tbell
1.1 --- a/common/autoconf/generated-configure.sh Thu Apr 05 08:14:51 2018 -0700 1.2 +++ b/common/autoconf/generated-configure.sh Fri Apr 06 04:13:09 2018 -0700 1.3 @@ -772,9 +772,9 @@ 1.4 SDKPATH 1.5 XCODEBUILD 1.6 SET_DEVELOPER_DIR 1.7 -VS_PATH 1.8 VS_LIB 1.9 VS_INCLUDE 1.10 +VS_PATH 1.11 CYGWIN_LINK 1.12 EXE_SUFFIX 1.13 OBJ_SUFFIX 1.14 @@ -4219,7 +4219,7 @@ 1.15 #CUSTOM_AUTOCONF_INCLUDE 1.16 1.17 # Do not change or remove the following line, it is needed for consistency checks: 1.18 -DATE_WHEN_GENERATED=1522941269 1.19 +DATE_WHEN_GENERATED=1523013158 1.20 1.21 ############################################################################### 1.22 # 1.23 @@ -25637,47 +25637,62 @@ 1.24 # Lets extract the variables that are set by vcvarsall.bat/vsvars32.bat/vsvars64.bat 1.25 { $as_echo "$as_me:${as_lineno-$LINENO}: Trying to extract Visual Studio environment variables" >&5 1.26 $as_echo "$as_me: Trying to extract Visual Studio environment variables" >&6;} 1.27 - cd $OUTPUT_ROOT 1.28 - # FIXME: The code betweeen ---- was inlined from a separate script and is not properly adapted 1.29 - # to autoconf standards. 1.30 - 1.31 - #---- 1.32 - 1.33 - # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment) 1.34 - # but calculate the difference in Cygwin environment before/after running it and then 1.35 - # apply the diff. 1.36 - 1.37 - if test "x$OPENJDK_BUILD_OS_ENV" = xwindows.cygwin; then 1.38 - _vs10varsall=`cygpath -a -m -s "$VS_ENV_CMD"` 1.39 - _dosvs10varsall=`cygpath -a -w -s $_vs10varsall` 1.40 - _dosbash=`cygpath -a -w -s \`which bash\`.*` 1.41 - else 1.42 - _dosvs10varsall=`cmd //c echo $VS_ENV_CMD` 1.43 - _dosbash=`cmd //c echo \`which bash\`` 1.44 - fi 1.45 - 1.46 - # generate the set of exported vars before/after the vs10 setup 1.47 - $ECHO "@echo off" > localdevenvtmp.bat 1.48 - $ECHO "$_dosbash -c \"export -p\" > localdevenvtmp.export0" >> localdevenvtmp.bat 1.49 - $ECHO "call $_dosvs10varsall $VS_ENV_ARGS" >> localdevenvtmp.bat 1.50 - $ECHO "$_dosbash -c \"export -p\" > localdevenvtmp.export1" >> localdevenvtmp.bat 1.51 + 1.52 + # We need to create a couple of temporary files. 1.53 + VS_ENV_TMP_DIR="$OUTPUT_ROOT/vs-env" 1.54 + $MKDIR -p $VS_ENV_TMP_DIR 1.55 + 1.56 + # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment). 1.57 + # Instead create a shell script which will set the relevant variables when run. 1.58 + WINPATH_VS_ENV_CMD="$VS_ENV_CMD" 1.59 + 1.60 + unix_path="$WINPATH_VS_ENV_CMD" 1.61 + if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then 1.62 + windows_path=`$CYGPATH -m "$unix_path"` 1.63 + WINPATH_VS_ENV_CMD="$windows_path" 1.64 + elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then 1.65 + windows_path=`cmd //c echo $unix_path` 1.66 + WINPATH_VS_ENV_CMD="$windows_path" 1.67 + fi 1.68 + 1.69 + WINPATH_BASH="$BASH" 1.70 + 1.71 + unix_path="$WINPATH_BASH" 1.72 + if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then 1.73 + windows_path=`$CYGPATH -m "$unix_path"` 1.74 + WINPATH_BASH="$windows_path" 1.75 + elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then 1.76 + windows_path=`cmd //c echo $unix_path` 1.77 + WINPATH_BASH="$windows_path" 1.78 + fi 1.79 + 1.80 + 1.81 + # Generate a DOS batch file which runs $VS_ENV_CMD, and then creates a shell 1.82 + # script (executable by bash) that will setup the important variables. 1.83 + EXTRACT_VC_ENV_BAT_FILE="$VS_ENV_TMP_DIR/extract-vs-env.bat" 1.84 + $ECHO "@echo off" > $EXTRACT_VC_ENV_BAT_FILE 1.85 + # This will end up something like: 1.86 + # call C:/progra~2/micros~2.0/vc/bin/amd64/vcvars64.bat 1.87 + $ECHO "call $WINPATH_VS_ENV_CMD $VS_ENV_ARGS" >> $EXTRACT_VC_ENV_BAT_FILE 1.88 + # These will end up something like: 1.89 + # C:/CygWin/bin/bash -c 'echo VS_PATH=\"$PATH\" > localdevenv.sh 1.90 + # The trailing space for everyone except PATH is no typo, but is needed due 1.91 + # to trailing \ in the Windows paths. These will be stripped later. 1.92 + $ECHO "$WINPATH_BASH -c 'echo VS_PATH="'\"$PATH\" > set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 1.93 + $ECHO "$WINPATH_BASH -c 'echo VS_INCLUDE="'\"$INCLUDE \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 1.94 + $ECHO "$WINPATH_BASH -c 'echo VS_LIB="'\"$LIB \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 1.95 + $ECHO "$WINPATH_BASH -c 'echo VCINSTALLDIR="'\"$VCINSTALLDIR \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 1.96 + $ECHO "$WINPATH_BASH -c 'echo WindowsSdkDir="'\"$WindowsSdkDir \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 1.97 + $ECHO "$WINPATH_BASH -c 'echo WINDOWSSDKDIR="'\"$WINDOWSSDKDIR \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 1.98 1.99 # Now execute the newly created bat file. 1.100 - # The | cat is to stop SetEnv.Cmd to mess with system colors on msys 1.101 - cmd /c localdevenvtmp.bat | cat 1.102 - 1.103 - # apply the diff (less some non-vs10 vars named by "!") 1.104 - $SORT localdevenvtmp.export0 | $GREP -v "!" > localdevenvtmp.export0.sort 1.105 - $SORT localdevenvtmp.export1 | $GREP -v "!" > localdevenvtmp.export1.sort 1.106 - $COMM -1 -3 localdevenvtmp.export0.sort localdevenvtmp.export1.sort > localdevenv.sh 1.107 - 1.108 - # cleanup 1.109 - $RM localdevenvtmp* 1.110 - #---- 1.111 + # The | cat is to stop SetEnv.Cmd to mess with system colors on msys. 1.112 + # Change directory so we don't need to mess with Windows paths in redirects. 1.113 + cd $VS_ENV_TMP_DIR 1.114 + cmd /c extract-vs-env.bat | $CAT 1.115 cd $CURDIR 1.116 - if test ! -s $OUTPUT_ROOT/localdevenv.sh; then 1.117 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 1.118 -$as_echo "no" >&6; } 1.119 + 1.120 + if test ! -s $VS_ENV_TMP_DIR/set-vs-env.sh; then 1.121 { $as_echo "$as_me:${as_lineno-$LINENO}: Could not succesfully extract the envionment variables needed for the VS setup." >&5 1.122 $as_echo "$as_me: Could not succesfully extract the envionment variables needed for the VS setup." >&6;} 1.123 { $as_echo "$as_me:${as_lineno-$LINENO}: Try setting --with-tools-dir to the VC/bin directory within the VS installation" >&5 1.124 @@ -25691,31 +25706,34 @@ 1.125 # the configure script to find and run the compiler in the proper way. 1.126 { $as_echo "$as_me:${as_lineno-$LINENO}: Setting extracted environment variables" >&5 1.127 $as_echo "$as_me: Setting extracted environment variables" >&6;} 1.128 - . $OUTPUT_ROOT/localdevenv.sh 1.129 + . $VS_ENV_TMP_DIR/set-vs-env.sh 1.130 + # Now we have VS_PATH, VS_INCLUDE, VS_LIB. For further checking, we 1.131 + # also define VCINSTALLDIR, WindowsSdkDir and WINDOWSSDKDIR. 1.132 else 1.133 # We did not find a vsvars bat file, let's hope we are run from a VS command prompt. 1.134 { $as_echo "$as_me:${as_lineno-$LINENO}: Cannot locate a valid Visual Studio installation, checking current environment" >&5 1.135 $as_echo "$as_me: Cannot locate a valid Visual Studio installation, checking current environment" >&6;} 1.136 fi 1.137 1.138 - # At this point, we should have corrent variables in the environment, or we can't continue. 1.139 + # At this point, we should have correct variables in the environment, or we can't continue. 1.140 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Visual Studio variables" >&5 1.141 $as_echo_n "checking for Visual Studio variables... " >&6; } 1.142 1.143 if test "x$VCINSTALLDIR" != x || test "x$WindowsSDKDir" != x || test "x$WINDOWSSDKDIR" != x; then 1.144 - if test "x$INCLUDE" = x || test "x$LIB" = x; then 1.145 + if test "x$VS_INCLUDE" = x || test "x$VS_LIB" = x; then 1.146 { $as_echo "$as_me:${as_lineno-$LINENO}: result: present but broken" >&5 1.147 $as_echo "present but broken" >&6; } 1.148 as_fn_error $? "Your VC command prompt seems broken, INCLUDE and/or LIB is missing." "$LINENO" 5 1.149 else 1.150 { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 1.151 $as_echo "ok" >&6; } 1.152 - # Remove any trailing \ from INCLUDE and LIB to avoid trouble in spec.gmk. 1.153 - VS_INCLUDE=`$ECHO "$INCLUDE" | $SED 's/\\\\$//'` 1.154 - VS_LIB=`$ECHO "$LIB" | $SED 's/\\\\$//'` 1.155 - # Remove any paths containing # (typically F#) as that messes up make 1.156 - PATH=`$ECHO "$PATH" | $SED 's/[^:#]*#[^:]*://g'` 1.157 - VS_PATH="$PATH" 1.158 + # Remove any trailing "\" and " " from the variables. 1.159 + VS_INCLUDE=`$ECHO "$VS_INCLUDE" | $SED 's/\\\\* *$//'` 1.160 + VS_LIB=`$ECHO "$VS_LIB" | $SED 's/\\\\* *$//'` 1.161 + VCINSTALLDIR=`$ECHO "$VCINSTALLDIR" | $SED 's/\\\\* *$//'` 1.162 + WindowsSDKDir=`$ECHO "$WindowsSDKDir" | $SED 's/\\\\* *$//'` 1.163 + WINDOWSSDKDIR=`$ECHO "$WINDOWSSDKDIR" | $SED 's/\\\\* *$//'` 1.164 + 1.165 1.166 1.167 1.168 @@ -25740,6 +25758,12 @@ 1.169 as_fn_error $? "Cannot continue" "$LINENO" 5 1.170 fi 1.171 1.172 + # Reset path to VS_PATH. It will include everything that was on PATH at the time we 1.173 + # ran TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV. 1.174 + PATH="$VS_PATH" 1.175 + # The microsoft toolchain also requires INCLUDE and LIB to be set. 1.176 + export INCLUDE="$VS_INCLUDE" 1.177 + export LIB="$VS_LIB" 1.178 fi 1.179 1.180 # autoconf magic only relies on PATH, so update it if tools dir is specified
2.1 --- a/common/autoconf/toolchain.m4 Thu Apr 05 08:14:51 2018 -0700 2.2 +++ b/common/autoconf/toolchain.m4 Fri Apr 06 04:13:09 2018 -0700 2.3 @@ -223,6 +223,12 @@ 2.4 # it for DLL resolution in runtime. 2.5 if test "x$OPENJDK_BUILD_OS" = "xwindows" && test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then 2.6 TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV 2.7 + # Reset path to VS_PATH. It will include everything that was on PATH at the time we 2.8 + # ran TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV. 2.9 + PATH="$VS_PATH" 2.10 + # The microsoft toolchain also requires INCLUDE and LIB to be set. 2.11 + export INCLUDE="$VS_INCLUDE" 2.12 + export LIB="$VS_LIB" 2.13 fi 2.14 2.15 # autoconf magic only relies on PATH, so update it if tools dir is specified
3.1 --- a/common/autoconf/toolchain_windows.m4 Thu Apr 05 08:14:51 2018 -0700 3.2 +++ b/common/autoconf/toolchain_windows.m4 Fri Apr 06 04:13:09 2018 -0700 3.3 @@ -141,46 +141,44 @@ 3.4 3.5 # Lets extract the variables that are set by vcvarsall.bat/vsvars32.bat/vsvars64.bat 3.6 AC_MSG_NOTICE([Trying to extract Visual Studio environment variables]) 3.7 - cd $OUTPUT_ROOT 3.8 - # FIXME: The code betweeen ---- was inlined from a separate script and is not properly adapted 3.9 - # to autoconf standards. 3.10 3.11 - #---- 3.12 + # We need to create a couple of temporary files. 3.13 + VS_ENV_TMP_DIR="$OUTPUT_ROOT/vs-env" 3.14 + $MKDIR -p $VS_ENV_TMP_DIR 3.15 3.16 - # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment) 3.17 - # but calculate the difference in Cygwin environment before/after running it and then 3.18 - # apply the diff. 3.19 + # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment). 3.20 + # Instead create a shell script which will set the relevant variables when run. 3.21 + WINPATH_VS_ENV_CMD="$VS_ENV_CMD" 3.22 + BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_VS_ENV_CMD]) 3.23 + WINPATH_BASH="$BASH" 3.24 + BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_BASH]) 3.25 3.26 - if test "x$OPENJDK_BUILD_OS_ENV" = xwindows.cygwin; then 3.27 - _vs10varsall=`cygpath -a -m -s "$VS_ENV_CMD"` 3.28 - _dosvs10varsall=`cygpath -a -w -s $_vs10varsall` 3.29 - _dosbash=`cygpath -a -w -s \`which bash\`.*` 3.30 - else 3.31 - _dosvs10varsall=`cmd //c echo $VS_ENV_CMD` 3.32 - _dosbash=`cmd //c echo \`which bash\`` 3.33 - fi 3.34 - 3.35 - # generate the set of exported vars before/after the vs10 setup 3.36 - $ECHO "@echo off" > localdevenvtmp.bat 3.37 - $ECHO "$_dosbash -c \"export -p\" > localdevenvtmp.export0" >> localdevenvtmp.bat 3.38 - $ECHO "call $_dosvs10varsall $VS_ENV_ARGS" >> localdevenvtmp.bat 3.39 - $ECHO "$_dosbash -c \"export -p\" > localdevenvtmp.export1" >> localdevenvtmp.bat 3.40 + # Generate a DOS batch file which runs $VS_ENV_CMD, and then creates a shell 3.41 + # script (executable by bash) that will setup the important variables. 3.42 + EXTRACT_VC_ENV_BAT_FILE="$VS_ENV_TMP_DIR/extract-vs-env.bat" 3.43 + $ECHO "@echo off" > $EXTRACT_VC_ENV_BAT_FILE 3.44 + # This will end up something like: 3.45 + # call C:/progra~2/micros~2.0/vc/bin/amd64/vcvars64.bat 3.46 + $ECHO "call $WINPATH_VS_ENV_CMD $VS_ENV_ARGS" >> $EXTRACT_VC_ENV_BAT_FILE 3.47 + # These will end up something like: 3.48 + # C:/CygWin/bin/bash -c 'echo VS_PATH=\"$PATH\" > localdevenv.sh 3.49 + # The trailing space for everyone except PATH is no typo, but is needed due 3.50 + # to trailing \ in the Windows paths. These will be stripped later. 3.51 + $ECHO "$WINPATH_BASH -c 'echo VS_PATH="'\"$PATH\" > set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 3.52 + $ECHO "$WINPATH_BASH -c 'echo VS_INCLUDE="'\"$INCLUDE \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 3.53 + $ECHO "$WINPATH_BASH -c 'echo VS_LIB="'\"$LIB \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 3.54 + $ECHO "$WINPATH_BASH -c 'echo VCINSTALLDIR="'\"$VCINSTALLDIR \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 3.55 + $ECHO "$WINPATH_BASH -c 'echo WindowsSdkDir="'\"$WindowsSdkDir \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 3.56 + $ECHO "$WINPATH_BASH -c 'echo WINDOWSSDKDIR="'\"$WINDOWSSDKDIR \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE 3.57 3.58 # Now execute the newly created bat file. 3.59 - # The | cat is to stop SetEnv.Cmd to mess with system colors on msys 3.60 - cmd /c localdevenvtmp.bat | cat 3.61 + # The | cat is to stop SetEnv.Cmd to mess with system colors on msys. 3.62 + # Change directory so we don't need to mess with Windows paths in redirects. 3.63 + cd $VS_ENV_TMP_DIR 3.64 + cmd /c extract-vs-env.bat | $CAT 3.65 + cd $CURDIR 3.66 3.67 - # apply the diff (less some non-vs10 vars named by "!") 3.68 - $SORT localdevenvtmp.export0 | $GREP -v "!" > localdevenvtmp.export0.sort 3.69 - $SORT localdevenvtmp.export1 | $GREP -v "!" > localdevenvtmp.export1.sort 3.70 - $COMM -1 -3 localdevenvtmp.export0.sort localdevenvtmp.export1.sort > localdevenv.sh 3.71 - 3.72 - # cleanup 3.73 - $RM localdevenvtmp* 3.74 - #---- 3.75 - cd $CURDIR 3.76 - if test ! -s $OUTPUT_ROOT/localdevenv.sh; then 3.77 - AC_MSG_RESULT([no]) 3.78 + if test ! -s $VS_ENV_TMP_DIR/set-vs-env.sh; then 3.79 AC_MSG_NOTICE([Could not succesfully extract the envionment variables needed for the VS setup.]) 3.80 AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation]) 3.81 AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.]) 3.82 @@ -190,30 +188,33 @@ 3.83 # Now set all paths and other env variables. This will allow the rest of 3.84 # the configure script to find and run the compiler in the proper way. 3.85 AC_MSG_NOTICE([Setting extracted environment variables]) 3.86 - . $OUTPUT_ROOT/localdevenv.sh 3.87 + . $VS_ENV_TMP_DIR/set-vs-env.sh 3.88 + # Now we have VS_PATH, VS_INCLUDE, VS_LIB. For further checking, we 3.89 + # also define VCINSTALLDIR, WindowsSdkDir and WINDOWSSDKDIR. 3.90 else 3.91 # We did not find a vsvars bat file, let's hope we are run from a VS command prompt. 3.92 AC_MSG_NOTICE([Cannot locate a valid Visual Studio installation, checking current environment]) 3.93 fi 3.94 3.95 - # At this point, we should have corrent variables in the environment, or we can't continue. 3.96 + # At this point, we should have correct variables in the environment, or we can't continue. 3.97 AC_MSG_CHECKING([for Visual Studio variables]) 3.98 3.99 if test "x$VCINSTALLDIR" != x || test "x$WindowsSDKDir" != x || test "x$WINDOWSSDKDIR" != x; then 3.100 - if test "x$INCLUDE" = x || test "x$LIB" = x; then 3.101 + if test "x$VS_INCLUDE" = x || test "x$VS_LIB" = x; then 3.102 AC_MSG_RESULT([present but broken]) 3.103 AC_MSG_ERROR([Your VC command prompt seems broken, INCLUDE and/or LIB is missing.]) 3.104 else 3.105 AC_MSG_RESULT([ok]) 3.106 - # Remove any trailing \ from INCLUDE and LIB to avoid trouble in spec.gmk. 3.107 - VS_INCLUDE=`$ECHO "$INCLUDE" | $SED 's/\\\\$//'` 3.108 - VS_LIB=`$ECHO "$LIB" | $SED 's/\\\\$//'` 3.109 - # Remove any paths containing # (typically F#) as that messes up make 3.110 - PATH=`$ECHO "$PATH" | $SED 's/[[^:#]]*#[^:]*://g'` 3.111 - VS_PATH="$PATH" 3.112 + # Remove any trailing "\" and " " from the variables. 3.113 + VS_INCLUDE=`$ECHO "$VS_INCLUDE" | $SED 's/\\\\* *$//'` 3.114 + VS_LIB=`$ECHO "$VS_LIB" | $SED 's/\\\\* *$//'` 3.115 + VCINSTALLDIR=`$ECHO "$VCINSTALLDIR" | $SED 's/\\\\* *$//'` 3.116 + WindowsSDKDir=`$ECHO "$WindowsSDKDir" | $SED 's/\\\\* *$//'` 3.117 + WINDOWSSDKDIR=`$ECHO "$WINDOWSSDKDIR" | $SED 's/\\\\* *$//'` 3.118 + 3.119 + AC_SUBST(VS_PATH) 3.120 AC_SUBST(VS_INCLUDE) 3.121 AC_SUBST(VS_LIB) 3.122 - AC_SUBST(VS_PATH) 3.123 fi 3.124 else 3.125 AC_MSG_RESULT([not found])