Make cl.py work under WSL draft
authorTed Mielczarek <ted@mielczarek.org>
Thu, 14 Sep 2017 06:49:36 -0400
changeset 668592 c43dc471da4b9b8a61d46edf7e5a683d3aa4f484
parent 668591 96949eaa5fbda1d6a4fb53ac922d760f6dcb729f
child 668593 30b47c045a11d0a8ff55734aaaa9bb98d181cf75
push id81087
push userbmo:ted@mielczarek.org
push dateThu, 21 Sep 2017 20:59:05 +0000
milestone57.0a1
Make cl.py work under WSL MozReview-Commit-ID: AL5s8BXojIF
python/mozbuild/mozbuild/action/cl.py
--- a/python/mozbuild/mozbuild/action/cl.py
+++ b/python/mozbuild/mozbuild/action/cl.py
@@ -5,50 +5,49 @@
 from __future__ import absolute_import
 
 import ctypes
 import os
 import sys
 
 from mozprocess.processhandler import ProcessHandlerMixin
 from mozbuild.makeutil import Makefile
+from mozbuild.util import memoize
+import mozpack.path as mozpath
 
 CL_INCLUDES_PREFIX = os.environ.get("CL_INCLUDES_PREFIX", "Note: including file:")
 
-GetShortPathName = ctypes.windll.kernel32.GetShortPathNameW
-GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW
+if sys.platform == 'win32':
+    GetShortPathName = ctypes.windll.kernel32.GetShortPathNameW
+    GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW
 
 
 # cl.exe likes to print inconsistent paths in the showIncludes output
 # (some lowercased, some not, with different directions of slashes),
 # and we need the original file case for make/pymake to be happy.
 # As this is slow and needs to be called a lot of times, use a cache
 # to speed things up.
-_normcase_cache = {}
-
+@memoize
 def normcase(path):
-    # Get*PathName want paths with backslashes
-    path = path.replace('/', os.sep)
-    dir = os.path.dirname(path)
-    # name is fortunately always going to have the right case,
-    # so we can use a cache for the directory part only.
-    name = os.path.basename(path)
-    if dir in _normcase_cache:
-        result = _normcase_cache[dir]
-    else:
-        path = ctypes.create_unicode_buffer(dir)
+    if sys.platform == 'win32':
+        # Get*PathName want paths with backslashes
+        path = path.replace('/', os.sep)
+        path = ctypes.create_unicode_buffer(path)
         length = GetShortPathName(path, None, 0)
         shortpath = ctypes.create_unicode_buffer(length)
         GetShortPathName(path, shortpath, length)
         length = GetLongPathName(shortpath, None, 0)
         if length > len(path):
             path = ctypes.create_unicode_buffer(length)
         GetLongPathName(shortpath, path, length)
-        result = _normcase_cache[dir] = path.value
-    return os.path.join(result, name)
+        return path.value
+    else:
+        # This isn't doing any case-translation. That being said, modern MSVC (2017) seems
+        # to return the canonical case nowadays.
+        return mozpath.nativepath(path)
 
 
 def InvokeClWithDependencyGeneration(cmdline):
     target = ""
     # Figure out what the target is
     for arg in cmdline:
         if arg.startswith("-Fo"):
             target = arg[3:]