[llvm] 8e62797 - [lit] Attempt for fix tests failing because of 'warning: non-portable path to file'

Kristina Bessonova via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 12 03:51:24 PDT 2021


Author: Kristina Bessonova
Date: 2021-06-12T12:49:03+02:00
New Revision: 8e62797963875e0cf93fcabda9e18bc0eff5da11

URL: https://github.com/llvm/llvm-project/commit/8e62797963875e0cf93fcabda9e18bc0eff5da11
DIFF: https://github.com/llvm/llvm-project/commit/8e62797963875e0cf93fcabda9e18bc0eff5da11.diff

LOG: [lit] Attempt for fix tests failing because of 'warning: non-portable path to file'

This is an attempt to fix clang test failures due to 'nonportable-include-path'
warnings on Windows when a path to llvm-project's base directory contains some
uppercase letters (excluding a drive letter).

The issue originates from 2 problems:
* discovery.py loads site config in lower case causing all the paths
based on __file__ and requested within the config file to be in lowercase as well,
* neither os.path.abspath() nor os.path.realpath() (both used to obtain paths of
config files, sources, object directories, etc) do not return paths in the correct
case for Windows (at least consistently for all python versions).

As os.path library doesn't seem to provide any relaible way to restore
the case for paths on Windows, this patch proposes to use pathlib.resolve().
pathlib is a part of Python 3.4 while llvm lit requires Python 3.6.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D103014

Added: 
    

Modified: 
    llvm/cmake/modules/AddLLVM.cmake
    llvm/utils/lit/lit/discovery.py

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 9c2b85374307a..689cac474c1ab 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1566,9 +1566,10 @@ endfunction()
 # use it and can't be in a lit module. Use with make_paths_relative().
 string(CONCAT LLVM_LIT_PATH_FUNCTION
   "# Allow generated file to be relocatable.\n"
+  "from pathlib import Path\n"
   "def path(p):\n"
   "    if not p: return ''\n"
-  "    return os.path.join(os.path.dirname(os.path.abspath(__file__)), p)\n"
+  "    return str((Path(__file__).parent / p).resolve())\n"
   )
 
 # This function provides an automatic way to 'configure'-like generate a file

diff  --git a/llvm/utils/lit/lit/discovery.py b/llvm/utils/lit/lit/discovery.py
index 22d6d8520283e..bb77aa310c713 100644
--- a/llvm/utils/lit/lit/discovery.py
+++ b/llvm/utils/lit/lit/discovery.py
@@ -53,8 +53,7 @@ def search1(path):
         config_map = litConfig.params.get('config_map')
         if config_map:
             cfgpath = os.path.realpath(cfgpath)
-            cfgpath = os.path.normcase(cfgpath)
-            target = config_map.get(cfgpath)
+            target = config_map.get(os.path.normcase(cfgpath))
             if target:
                 cfgpath = target
 


        


More information about the llvm-commits mailing list