Skip to content

Commit 2fceb9a

Browse files
authored
Merge pull request #84863 from ramonasuncion/test-moduleinterface-replace-find
[Test][ModuleInterface] Replace find with find_files utility
2 parents 70341f4 + f99260c commit 2fceb9a

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

test/ModuleInterface/ModuleCache/module-cache-deployment-target-irrelevant.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
//
2525
// Phase 4: make sure we only compiled LeafModule and OtherModule one time:
2626
//
27-
// RUN: NUM_LEAF_MODULES=$(find %t/modulecache -type f -name 'LeafModule-*.swiftmodule' | wc -l)
28-
// RUN: NUM_OTHER_MODULES=$(find %t/modulecache -type f -name 'OtherModule-*.swiftmodule' | wc -l)
29-
// RUN: if [ ! $NUM_LEAF_MODULES -eq 1 ]; then echo "Should only be 1 LeafModule, found $NUM_LEAF_MODULES"; exit 1; fi
30-
// RUN: if [ ! $NUM_OTHER_MODULES -eq 1 ]; then echo "Should only be 1 OtherModule, found $NUM_OTHER_MODULES"; exit 1; fi
27+
// RUN: %find_files %t/modulecache 'LeafModule-*.swiftmodule' | %llvm_obj_root/bin/count 1
28+
// RUN: %find_files %t/modulecache 'OtherModule-*.swiftmodule' | %llvm_obj_root/bin/count 1
3129
import LeafModule
3230
import OtherModule

test/ModuleInterface/ModuleCache/module-cache-options.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -I %t -module-cache-path %t/swiftcache -emit-module-interface-path %t/OtherModule.swiftinterface -module-name OtherModule %t/other.swift -emit-module -o /dev/null
77
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -I %t -module-cache-path %t/swiftcache -Xcc -fmodules-cache-path=%t/clangcache -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %t/main.swift
88

9-
// RUN: NUM_SWIFT_MODULES=$(find %t/swiftcache -type f -name '*.swiftmodule' | wc -l)
10-
// RUN: NUM_CLANG_MODULES=$(find %t/clangcache -type f -name '*.pcm' | wc -l)
119
/// Two swift modules, Leaf and Other
12-
// RUN: if [ ! $NUM_SWIFT_MODULES -eq 2 ]; then echo "Should only be 2 Swift Modules, found $NUM_SWIFT_MODULES"; exit 1; fi
10+
// RUN: %find_files %t/swiftcache '*.swiftmodule' | %llvm_obj_root/bin/count 2
1311
/// Two clang modules, shim and A
14-
// RUN: if [ ! $NUM_CLANG_MODULES -eq 2 ]; then echo "Should only be 2 Clang Modules, found $NUM_CLANG_MODULES"; exit 1; fi
12+
// RUN: %find_files %t/clangcache '*.pcm' | %llvm_obj_root/bin/count 2
13+
1514

1615
//--- leaf.swift
1716
public func LeafFunc() {}

test/lit.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2984,6 +2984,8 @@ config.substitutions.append(('%round-trip-syntax-test',
29842984
'%s %s' % (shell_quote(sys.executable),
29852985
config.round_trip_syntax_test)))
29862986
config.substitutions.append(('%rth', '%s %s' % (shell_quote(sys.executable), config.rth)))
2987+
config.substitutions.append(('%find_files', '%s %s' % (shell_quote(sys.executable),
2988+
make_path(config.swift_utils, 'find_files'))))
29872989
config.substitutions.append(('%scale-test',
29882990
'{} {} --swiftc-binary={} --tmpdir=%t --exclude-timers'.format(
29892991
shell_quote(sys.executable), config.scale_test,

utils/find_files

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
# Recursively find files matching a glob pattern. Replaces Unix (find) in lit tests
3+
# for cross-platform compatibility
4+
5+
import sys
6+
from pathlib import Path
7+
8+
def usage():
9+
print("Usage: find_files <directory> <pattern>", file=sys.stderr)
10+
sys.exit(2)
11+
12+
def main():
13+
if len(sys.argv) != 3:
14+
usage()
15+
root, pattern = sys.argv[1], sys.argv[2]
16+
p = Path(root)
17+
if not p.exists():
18+
print(f"Directory not found: {root}", file=sys.stderr)
19+
sys.exit(2)
20+
for x in p.rglob(pattern):
21+
if x.is_file():
22+
print(x)
23+
sys.exit(0)
24+
25+
if __name__ == "__main__":
26+
main()

utils/python_format.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
_SWIFT_PATH / "utils/symbolicate-linux-fatal",
5757
_SWIFT_PATH / "utils/update-checkout",
5858
_SWIFT_PATH / "utils/viewcfg",
59+
_SWIFT_PATH / "utils/find_files"
5960
]
6061

6162

0 commit comments

Comments
 (0)