[PATCH] D103014: [lit] Make LLVM_LIT_PATH_FUNCTION to use pathlib

Kristina Bessonova via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 24 05:46:09 PDT 2021


krisb created this revision.
krisb added reviewers: thakis, hans.
Herald added a subscriber: mgorny.
krisb requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.

For example, for 'clang/test/PCH/enum.c' test running from 'J:\MyDir\llvm-project'
lit generates the following command for the first RUN line:

  "j:\mydir\build\bin\clang.exe" "-cc1" "-internal-isystem" "j:\mydir\build\lib\clang\1.12.0\include" "-nostdsysteminc" "-include" "j:\mydir\llvm-project\clang\test\PCH/enum.h" "-fsyntax-only" "j:\mydir\llvm-project\clang\test\PCH\enum.c"

which produces the following warning causing the test to fail:

  <built-in>:1:10: warning: non-portable path to file '"J:\MyDir\llvm-project\clang\test\PCH/enum.h"'; specified path differs in case from file name on disk [-Wnonportable-include-path]
  #include "j:\mydir\llvm-project\clang\test\PCH/enum.h"
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           "J:\MyDir\llvm-project\clang\test\PCH/enum.h"
  1 warning generated.

The problem originates from discovery.py which made paths to lit site
config files lowercase while adding them into the map. That causes all the paths
based on __file__ and requested within the config files to be in lowercase as well.

As os.path library doesn't seem to provide any relaible way to restore
case for paths on Windows, this patch proposes to use pathlib.resolve().

pathlib is a part of Python 3.4 [0] while llvm lit requires Python 3.6 [1].

Note: I noticed the same problem reported in D78169 <https://reviews.llvm.org/D78169>, but the suggestion
to use Python 3.8. doesn't seem working (at least for my setup).

[0] https://docs.python.org/3/library/pathlib.html
[1] https://llvm.org/docs/GettingStarted.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103014

Files:
  llvm/cmake/modules/AddLLVM.cmake


Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1549,9 +1549,10 @@
 # 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103014.347358.patch
Type: text/x-patch
Size: 672 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210524/29cfb0c6/attachment.bin>


More information about the llvm-commits mailing list