[PATCH] D51709: [lit] Correctly expand globs relative to their intended directory.
Graydon Hoare via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 5 16:52:12 PDT 2018
graydon updated this revision to Diff 164127.
graydon added a comment.
Add test, fix typo.
Repository:
rL LLVM
https://reviews.llvm.org/D51709
Files:
utils/lit/lit/ShCommands.py
utils/lit/tests/shtest-glob-relative.py
Index: utils/lit/tests/shtest-glob-relative.py
===================================================================
--- /dev/null
+++ utils/lit/tests/shtest-glob-relative.py
@@ -0,0 +1,8 @@
+# Here we're checking that glob-expanding a relative glob within a "cd ..." does not
+# wind up prepending the working directory absolute path to the glob expansion.
+#
+# RUN: mkdir -p %t.dir/test/deep/path
+# RUN: touch %t.dir/test/deep/path/file.txt
+# RUN: cd %t.dir/test/deep/path && ls file.* > %t.out
+# RUN: FileCheck --input-file %t.out %s
+# CHECK-NOT: deep/path
Index: utils/lit/lit/ShCommands.py
===================================================================
--- utils/lit/lit/ShCommands.py
+++ utils/lit/lit/ShCommands.py
@@ -52,10 +52,18 @@
import glob
import os
if os.path.isabs(self.pattern):
- abspath = self.pattern
+ results = glob.glob(self.pattern)
else:
- abspath = os.path.join(cwd, self.pattern)
- results = glob.glob(abspath)
+ # For a non-absolute pattern, we want to match "relative to
+ # cwd"; unfortunately glob.glob() will only match relative to
+ # the process working directory, or else an absolute path. So
+ # rather than change working directory to and from cwd in order
+ # to glob, we extend the relative pattern to an absolute
+ # pattern, then glob, then map the results back to relative
+ # paths using relpath.
+ abs_pat = os.path.join(cwd, self.pattern)
+ abs_glob = glob.glob(abs_pat)
+ results = [os.path.relpath(f, cwd) for f in abs_glob]
return [self.pattern] if len(results) == 0 else results
class Pipeline:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51709.164127.patch
Type: text/x-patch
Size: 1749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180905/37fac566/attachment.bin>
More information about the llvm-commits
mailing list