Skip to content

Commit e0f79dc

Browse files
authored
Merge pull request swiftlang#23829 from drodriguez/path-sanitizing-filecheck-yaml-compatibility
[utils][test] PathSanitizingFileCheck more compatible with Windows.
2 parents e6449a1 + 267e0fc commit e0f79dc

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

test/ClangImporter/pch-bridging-header-deps.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
// RUN: %target-swift-frontend -emit-pch -o %t.pch %/S/Inputs/chained-unit-test-bridging-header-to-pch.h
77
// RUN: %target-swift-frontend -module-name test -c -emit-dependencies-path %t.d -emit-reference-dependencies-path %t.swiftdeps -primary-file %s -import-objc-header %t.pch
88
// RUN: %FileCheck --check-prefix CHECK-DEPS %s < %t.d
9-
// RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS %s < %t.swiftdeps
10-
// RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS2 %s < %t.swiftdeps
9+
// RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS --enable-yaml-compatibility %s < %t.swiftdeps
10+
// RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS2 --enable-yaml-compatibility %s < %t.swiftdeps
1111

1212
// RUN: %target-swift-frontend -module-name test -c -emit-dependencies-path %t.persistent.d -emit-reference-dependencies-path %t.persistent.swiftdeps -primary-file %s -import-objc-header %/S/Inputs/chained-unit-test-bridging-header-to-pch.h -pch-output-dir %t/pch
1313
// RUN: %FileCheck --check-prefix CHECK-DEPS %s < %t.persistent.d
14-
// RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS %s < %t.persistent.swiftdeps
15-
// RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS2 %s < %t.persistent.swiftdeps
14+
// RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS --enable-yaml-compatibility %s < %t.persistent.swiftdeps
15+
// RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS2 --enable-yaml-compatibility %s < %t.persistent.swiftdeps
1616

1717
print(app_function(1))
1818

test/lit.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,12 +1450,13 @@ config.substitutions.append(('%llvm-profdata', config.llvm_profdata))
14501450
config.substitutions.append(('%llvm-cov', config.llvm_cov))
14511451

14521452
config.substitutions.append(('%FileCheck',
1453-
'%r %r --sanitize BUILD_DIR=%r --sanitize SOURCE_DIR=%r --use-filecheck %r' % (
1453+
'%r %r --sanitize BUILD_DIR=%r --sanitize SOURCE_DIR=%r --use-filecheck %r %s' % (
14541454
sys.executable,
14551455
config.PathSanitizingFileCheck,
14561456
swift_obj_root,
14571457
config.swift_src_root,
1458-
config.filecheck)))
1458+
config.filecheck,
1459+
'--enable-windows-compatibility' if kIsWindows else '')))
14591460
config.substitutions.append(('%raw-FileCheck', pipes.quote(config.filecheck)))
14601461

14611462
# If static stdlib is present, enable static stdlib tests

utils/PathSanitizingFileCheck

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,36 @@ constants.""")
4343
dest="file_check_path",
4444
default="FileCheck")
4545

46+
parser.add_argument(
47+
"--enable-windows-compatibility",
48+
help="Enable Windows path compatibility, which checks against both "
49+
"forward slashes and backward slashes.",
50+
action="store_true")
51+
52+
parser.add_argument(
53+
"--enable-yaml-compatibility",
54+
help="Enable YAML path compatibility. Since YAML double escapes "
55+
"backward slashes, we need to check for them escaped. Only "
56+
"available if Windows compatibility is enabled.",
57+
action="store_true")
58+
4659
args, unknown_args = parser.parse_known_args()
4760

61+
if args.enable_windows_compatibility:
62+
if args.enable_yaml_compatibility:
63+
slashes_re = r'(/|\\\\|\\\\\\\\)'
64+
else:
65+
slashes_re = r'(/|\\\\)'
66+
else:
67+
slashes_re = r'/'
68+
4869
stdin = sys.stdin.read()
4970
for s in args.sanitize_strings:
5071
replacement, pattern = s.split('=', 1)
51-
stdin = re.sub(re.sub(r'/', r'[/\\\\]', pattern), replacement, stdin)
72+
# We are replacing the Unix path separators in the paths passed as
73+
# arguments with a broader pattern to also allow forward slashes and
74+
# double escaped slashes in the result that we are checking. Sigh.
75+
stdin = re.sub(re.sub(r'/', slashes_re, pattern), replacement, stdin)
5276

5377
p = subprocess.Popen(
5478
[args.file_check_path] + unknown_args, stdin=subprocess.PIPE)

0 commit comments

Comments
 (0)