[PATCH] D78228: lit: Don't make with_environment() change case of existing PATH entries.

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 12:04:07 PDT 2020


thakis created this revision.
thakis added a reviewer: hans.
Herald added a subscriber: delcypher.

This is an alternative fix for https://reviews.llvm.org/D57343.
Instead of normcase()ing in which() in addition to in
with_environment(), consistently don't do it in both places.

Since normcase() is lossy (the original, likely "true" on-disk case
is lost), only computing a normcase() in-memory while comparing
seems overall less surprising.

No intended behavior change, except that binaries returned by which()
will now have on-disk case again, like before D57343 <https://reviews.llvm.org/D57343>.


https://reviews.llvm.org/D78228

Files:
  llvm/utils/lit/lit/llvm/config.py
  llvm/utils/lit/lit/util.py


Index: llvm/utils/lit/lit/util.py
===================================================================
--- llvm/utils/lit/lit/util.py
+++ llvm/utils/lit/lit/util.py
@@ -223,7 +223,7 @@
 
     # Check for absolute match first.
     if os.path.isabs(command) and os.path.isfile(command):
-        return os.path.normcase(os.path.normpath(command))
+        return os.path.normpath(command)
 
     # Would be nice if Python had a lib function for this.
     if not paths:
@@ -241,7 +241,7 @@
         for ext in pathext:
             p = os.path.join(path, command + ext)
             if os.path.exists(p) and not os.path.isdir(p):
-                return os.path.normcase(os.path.normpath(p))
+                return os.path.normpath(p)
 
     return None
 
Index: llvm/utils/lit/lit/llvm/config.py
===================================================================
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -124,10 +124,9 @@
             def norm(x):
                 return os.path.normcase(os.path.normpath(x))
 
-            current_paths = self.config.environment.get(variable, None)
-            if current_paths:
-                current_paths = current_paths.split(os.path.pathsep)
-                paths = [norm(p) for p in current_paths]
+            paths = self.config.environment.get(variable, None)
+            if paths:
+                paths = paths.split(os.path.pathsep)
             else:
                 paths = []
 
@@ -137,9 +136,8 @@
             for p in reversed(paths_to_add):
                 # Move it to the front if it already exists, otherwise insert
                 # it at the beginning.
-                p = norm(p)
                 try:
-                    paths.remove(p)
+                    paths.pop(map(norm, paths).index(norm(p)))
                 except ValueError:
                     pass
                 paths = [p] + paths


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78228.257792.patch
Type: text/x-patch
Size: 1910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200415/6ef9575b/attachment.bin>


More information about the llvm-commits mailing list