8216278: Fix devkit and basic Jib support on WSL
authorerikj
Thu, 10 Jan 2019 09:11:56 -0800
changeset 53240 f6ab4cc4c70e
parent 53239 c024fcb88ede
child 53241 7327a62f3c04
child 57105 3409e81fb3cb
8216278: Fix devkit and basic Jib support on WSL Reviewed-by: tbell
make/autoconf/basics.m4
make/autoconf/toolchain_windows.m4
make/conf/jib-profiles.js
--- a/make/autoconf/basics.m4	Thu Jan 10 11:16:17 2019 -0600
+++ b/make/autoconf/basics.m4	Thu Jan 10 09:11:56 2019 -0800
@@ -999,7 +999,7 @@
           elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
             MAKE_EXPECTED_ENV='msys'
           elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
-            MAKE_EXPECTED_ENV='x86_64-pc-linux-gnu'
+            MAKE_EXPECTED_ENV='x86_64-.*-linux-gnu'
           else
             AC_MSG_ERROR([Unknown Windows environment])
           fi
--- a/make/autoconf/toolchain_windows.m4	Thu Jan 10 11:16:17 2019 -0600
+++ b/make/autoconf/toolchain_windows.m4	Thu Jan 10 09:11:56 2019 -0800
@@ -272,7 +272,26 @@
     eval USE_UCRT="\${VS_USE_UCRT_${VS_VERSION}}"
     eval VS_SUPPORTED="\${VS_SUPPORTED_${VS_VERSION}}"
     eval PLATFORM_TOOLSET="\${VS_VS_PLATFORM_NAME_${VS_VERSION}}"
-    VS_PATH="$TOOLCHAIN_PATH:$PATH"
+
+    # The TOOLCHAIN_PATH from a devkit is in Unix format. In WSL we need a
+    # windows version of the complete VS_PATH as VS_PATH_WINDOWS
+    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
+      # Convert the toolchain path
+      OLDIFS="$IFS"
+      IFS=":"
+      VS_PATH_WINDOWS=""
+      for i in $TOOLCHAIN_PATH; do
+        path=$i
+        BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([path])
+        VS_PATH_WINDOWS="$VS_PATH_WINDOWS;$path"
+      done
+      IFS="$OLDIFS"
+      # Append the current path from Windows env
+      WINDOWS_PATH="`$CMD /c echo %PATH%`"
+      VS_PATH_WINDOWS="$VS_PATH_WINDOWS;$WINDOWS_PATH"
+    else
+      VS_PATH="$TOOLCHAIN_PATH:$PATH"
+    fi
 
     # Convert DEVKIT_VS_INCLUDE into windows style VS_INCLUDE so that it
     # can still be exported as INCLUDE for compiler invocations without
@@ -450,6 +469,34 @@
       . $VS_ENV_TMP_DIR/set-vs-env.sh
       # Now we have VS_PATH, VS_INCLUDE, VS_LIB. For further checking, we
       # also define VCINSTALLDIR, WindowsSdkDir and WINDOWSSDKDIR.
+
+      # In WSL, the extracted VS_PATH is Windows style. This needs to be
+      # rewritten as Unix style and the Windows style version is saved
+      # in VS_PATH_WINDOWS.
+      if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
+        OLDIFS="$IFS"
+        IFS=";"
+        # Convert VS_PATH to unix style
+        VS_PATH_WINDOWS="$VS_PATH"
+        VS_PATH=""
+        for i in $VS_PATH_WINDOWS; do
+          path=$i
+          # Only process non-empty elements
+          if test "x$path" != x; then
+            IFS="$OLDIFS"
+            # Check that directory exists before calling fixup_path
+            testpath=$path
+            BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([testpath])
+            if test -d "$testpath"; then
+              BASIC_FIXUP_PATH([path])
+              BASIC_APPEND_TO_PATH(VS_PATH, $path)
+            fi
+            IFS=";"
+          fi
+        done
+        IFS="$OLDIFS"
+      fi
+
     else
       # We did not find a vsvars bat file, let's hope we are run from a VS command prompt.
       AC_MSG_NOTICE([Cannot locate a valid Visual Studio installation, checking current environment])
@@ -483,29 +530,9 @@
       AC_SUBST(VS_INCLUDE)
       AC_SUBST(VS_LIB)
 
+      # Convert VS_INCLUDE into SYSROOT_CFLAGS
       OLDIFS="$IFS"
       IFS=";"
-      if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
-        # Convert VS_PATH to unix style
-        VS_PATH_WINDOWS="$VS_PATH"
-        VS_PATH=""
-        for i in $VS_PATH_WINDOWS; do
-          path=$i
-          # Only process non-empty elements
-          if test "x$path" != x; then
-            IFS="$OLDIFS"
-            # Check that directory exists before calling fixup_path
-            testpath=$path
-            BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([testpath])
-            if test -d "$testpath"; then
-              BASIC_FIXUP_PATH([path])
-              BASIC_APPEND_TO_PATH(VS_PATH, $path)
-            fi
-            IFS=";"
-          fi
-        done
-      fi
-      # Convert VS_INCLUDE into SYSROOT_CFLAGS
       for i in $VS_INCLUDE; do
         ipath=$i
         # Only process non-empty elements
--- a/make/conf/jib-profiles.js	Thu Jan 10 11:16:17 2019 -0600
+++ b/make/conf/jib-profiles.js	Thu Jan 10 09:11:56 2019 -0800
@@ -386,7 +386,9 @@
             target_cpu: "x64",
             dependencies: ["devkit", "graphviz", "pandoc", "graalunit_lib"],
             configure_args: concat(common.configure_args_64bit,
-                "--enable-full-docs", "--with-zlib=system"),
+                "--enable-full-docs", "--with-zlib=system",
+                (isWsl(input) ? [ "--host=x86_64-unknown-linux-gnu",
+                    "--build=x86_64-unknown-linux-gnu" ] : [])),
             default_make_targets: ["docs-bundles"],
         },
 
@@ -833,6 +835,13 @@
 
     var boot_jdk_platform = (input.build_os == "macosx" ? "osx" : input.build_os)
         + "-" + input.build_cpu;
+    var boot_jdk_ext = (input.build_os == "windows" ? ".zip" : ".tar.gz")
+    // If running in WSL and building for Windows, it will look like Linux,
+    // but we need a Windows boot JDK.
+    if (isWsl(input) && input.target_os == "windows") {
+        boot_jdk_platform = "windows-" + input.build_cpu;
+        boot_jdk_ext = ".zip";
+    }
 
     var makeBinDir = (input.build_os == "windows"
         ? input.get("gnumake", "install_path") + "/cygwin/bin"
@@ -846,8 +855,7 @@
             version: common.boot_jdk_version,
             build_number: "28",
             file: "bundles/" + boot_jdk_platform + "/jdk-" + common.boot_jdk_version + "_"
-                + boot_jdk_platform + "_bin"
-		+ (input.build_os == "windows" ? ".zip" : ".tar.gz"),
+                + boot_jdk_platform + "_bin" + boot_jdk_ext,
             configure_args: "--with-boot-jdk=" + common.boot_jdk_home,
             environment_path: common.boot_jdk_home + "/bin"
         },
@@ -941,7 +949,7 @@
             organization: common.organization,
             ext: "tar.gz",
             revision: "2.3.1+1.0",
-            module: "pandoc-" + input.target_platform,
+            module: "pandoc-" + input.build_platform,
             configure_args: "PANDOC=" + input.get("pandoc", "install_path") + "/pandoc/pandoc",
             environment_path: input.get("pandoc", "install_path") + "/pandoc"
         },
@@ -1181,3 +1189,13 @@
     }
     return version_numbers;
 }
+
+/**
+ * Returns true if running in Windows Subsystem for Linux. Jib does not yet
+ * detect wsl as osenv, so fall back on linux with version containing Microsoft.
+ */
+var isWsl = function (input) {
+    return ( input.build_osenv == "wsl"
+             || (input.build_os == "linux"
+                 && java.lang.System.getProperty("os.version").contains("Microsoft")));
+}