Skip to content

Commit 971a9f7

Browse files
committed
[lit] Check for accidental external command calls
This patch extends lit's test suite to check that lit's internal shell doesn't accidentally execute internal commands as external commands. It does so by putting fake failing versions of those commands in `PATH` while the entire lit test suite is running. Without the fixes in D65697 but with its tests, this approach catches accidental external `env` calls. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D66293 llvm-svn: 369309
1 parent 3f3a257 commit 971a9f7

File tree

8 files changed

+48
-0
lines changed

8 files changed

+48
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
3+
import fake_external
4+
5+
fake_external.execute(__file__)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
3+
import fake_external
4+
5+
fake_external.execute(__file__)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
3+
import fake_external
4+
5+
fake_external.execute(__file__)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
3+
import fake_external
4+
5+
fake_external.execute(__file__)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
import sys
3+
4+
def execute(fileName):
5+
sys.stderr.write("error: external '{}' command called unexpectedly\n"
6+
.format(os.path.basename(fileName)));
7+
sys.exit(1)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
3+
import fake_external
4+
5+
fake_external.execute(__file__)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
3+
import fake_external
4+
5+
fake_external.execute(__file__)

llvm/utils/lit/tests/lit.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,14 @@ else:
7575
if not llvm_config:
7676
if sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
7777
config.available_features.add('system-windows')
78+
79+
# For each of lit's internal shell commands ('env', 'cd', 'diff', etc.), put
80+
# a fake command that always fails at the start of PATH. This helps us check
81+
# that we always use lit's internal version rather than some external version
82+
# that might not be present or behave correctly on all platforms. Don't do
83+
# this for 'echo' because an external version is used when it appears in a
84+
# pipeline. Don't do this for ':' because it doesn't appear to be a valid file
85+
# name under Windows.
86+
test_bin = os.path.join(os.path.dirname(__file__), 'Inputs', 'fake-externals')
87+
config.environment['PATH'] = os.path.pathsep.join((test_bin,
88+
config.environment['PATH']))

0 commit comments

Comments
 (0)