Skip to content

Commit c1cf459

Browse files
committed
[lit] Avoid os.path.realpath in lit.py due to MAX_PATH limitations on Windows
lit.py uses os.path.realpath on file paths. Somewhere between Python 3.7 and 3.9, os.path.realpath was updated to resolve substitute drives on Windows (subst S: C:\Long\Path\To\My\Code). This is a problem because it prevents using substitute drives to work around MAX_PATH path length limitations on Windows. We run into this while building & testing, the Swift compiler on Windows, which uses a substitute drive in CI to shorten the workspace directory. cmake builds without resolving the substitute drive and can apply its logic to avoid output files exceeding MAX_PATH. However, when running tests, lit.py's use of os.path.realpath will resolve the substitute drive (with newer Python versions), resulting in some paths being longer than MAX_PATH, which cause all kinds of failures (for example rd in tests fails, or link.exe fails, etc). How tested: Ran check-all, and lit tests, saw no failures ``` > ninja -C build check-all Testing Time: 262.63s Skipped : 24 Unsupported : 2074 Passed : 51812 Expectedly Failed: 167 > python utils\lit\lit.py --path ..\build\bin utils\lit\tests Testing Time: 12.17s Unsupported: 6 Passed : 47 ``` Patch by Tristan Labelle! Differential Revision: https://reviews.llvm.org/D152709 Reviewed By: rnk, compnerd
1 parent 69d42ee commit c1cf459

File tree

7 files changed

+14
-15
lines changed

7 files changed

+14
-15
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def change_dir(self, newdir):
7474
if os.path.isabs(newdir):
7575
self.cwd = newdir
7676
else:
77-
self.cwd = os.path.realpath(os.path.join(self.cwd, newdir))
77+
self.cwd = os.path.abspath(os.path.join(self.cwd, newdir))
7878

7979

8080
class TimeoutHelper(object):
@@ -427,7 +427,7 @@ def executeBuiltinMkdir(cmd, cmd_shenv):
427427
dir = to_unicode(dir) if kIsWindows else to_bytes(dir)
428428
cwd = to_unicode(cwd) if kIsWindows else to_bytes(cwd)
429429
if not os.path.isabs(dir):
430-
dir = os.path.realpath(os.path.join(cwd, dir))
430+
dir = os.path.abspath(os.path.join(cwd, dir))
431431
if parent:
432432
lit.util.mkdir_p(dir)
433433
else:
@@ -473,7 +473,7 @@ def on_rm_error(func, path, exc_info):
473473
path = to_unicode(path) if kIsWindows else to_bytes(path)
474474
cwd = to_unicode(cwd) if kIsWindows else to_bytes(cwd)
475475
if not os.path.isabs(path):
476-
path = os.path.realpath(os.path.join(cwd, path))
476+
path = os.path.abspath(os.path.join(cwd, path))
477477
if force and not os.path.exists(path):
478478
continue
479479
try:

llvm/utils/lit/lit/builtin_commands/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def main(argv):
281281
try:
282282
for file in args:
283283
if file != "-" and not os.path.isabs(file):
284-
file = os.path.realpath(os.path.join(os.getcwd(), file))
284+
file = os.path.abspath(os.path.join(os.getcwd(), file))
285285

286286
if flags.recursive_diff:
287287
if file == "-":

llvm/utils/lit/lit/discovery.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def search1(path):
5656
# configuration to load instead.
5757
config_map = litConfig.params.get("config_map")
5858
if config_map:
59-
cfgpath = os.path.realpath(cfgpath)
60-
target = config_map.get(os.path.normcase(cfgpath))
59+
target = config_map.get(os.path.normcase(os.path.abspath(cfgpath)))
6160
if target:
6261
cfgpath = target
6362

@@ -67,16 +66,16 @@ def search1(path):
6766

6867
cfg = TestingConfig.fromdefaults(litConfig)
6968
cfg.load_from_path(cfgpath, litConfig)
70-
source_root = os.path.realpath(cfg.test_source_root or path)
71-
exec_root = os.path.realpath(cfg.test_exec_root or path)
69+
source_root = os.path.abspath(cfg.test_source_root or path)
70+
exec_root = os.path.abspath(cfg.test_exec_root or path)
7271
return Test.TestSuite(cfg.name, source_root, exec_root, cfg), ()
7372

7473
def search(path):
7574
# Check for an already instantiated test suite.
76-
real_path = os.path.realpath(path)
77-
res = cache.get(real_path)
75+
full_path = os.path.normcase(os.path.abspath(path))
76+
res = cache.get(full_path)
7877
if res is None:
79-
cache[real_path] = res = search1(path)
78+
cache[full_path] = res = search1(path)
8079
return res
8180

8281
# Canonicalize the path.

llvm/utils/lit/tests/Inputs/config-map-discovery/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55
main_config = sys.argv[1]
6-
main_config = os.path.realpath(main_config)
6+
main_config = os.path.abspath(main_config)
77
main_config = os.path.normcase(main_config)
88

99
config_map = {main_config: sys.argv[2]}

llvm/utils/lit/tests/Inputs/config-map-discovery/lit.alt.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ config.suffixes = ['.txt']
55
config.test_format = lit.formats.ShTest()
66

77
import os
8-
config.test_exec_root = os.path.realpath(os.path.dirname(__file__))
8+
config.test_exec_root = os.path.abspath(os.path.dirname(__file__))
99
config.test_source_root = os.path.join(config.test_exec_root, "tests")

llvm/utils/lit/tests/Inputs/use-llvm-tool-required/lit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ config.test_source_root = None
77
config.test_exec_root = None
88
import os.path
99

10-
config.llvm_tools_dir = os.path.realpath(os.path.dirname(__file__))
10+
config.llvm_tools_dir = os.path.abspath(os.path.dirname(__file__))
1111
import lit.llvm
1212

1313
lit.llvm.initialize(lit_config, config)

llvm/utils/lit/tests/Inputs/use-llvm-tool/lit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ config.test_source_root = None
77
config.test_exec_root = None
88
import os.path
99

10-
this_dir = os.path.realpath(os.path.dirname(__file__))
10+
this_dir = os.path.abspath(os.path.dirname(__file__))
1111
config.llvm_tools_dir = os.path.join(this_dir, "build")
1212
import lit.llvm
1313

0 commit comments

Comments
 (0)