Skip to content

Commit 4cd873a

Browse files
authored
Merge pull request #28298 from drodriguez/windows-python-sed_clean
[windows] Replace SourceKit cleaning regexes for Python script.
2 parents e830660 + 8470083 commit 4cd873a

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
# sourcekitd_path_sanitize.py - Cleans up paths from sourcekitd-test output
3+
#
4+
# This source file is part of the Swift.org open source project
5+
#
6+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
7+
# Licensed under Apache License v2.0 with Runtime Library Exception
8+
#
9+
# See https://swift.org/LICENSE.txt for license information
10+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
12+
import re
13+
import sys
14+
15+
SWIFTMODULE_BUNDLE_RE = re.compile(
16+
r'key.filepath: ".*[/\\](.*)\.swiftmodule[/\\].*\.swiftmodule"')
17+
SWIFTMODULE_RE = re.compile(r'key.filepath: ".*[/\\](.*)\.swiftmodule"')
18+
SWIFT_RE = re.compile(r'key.filepath: ".*[/\\](.*)\.swift"')
19+
PCM_RE = re.compile(r'key.filepath: ".*[/\\](.*)-[0-9A-Z]*\.pcm"')
20+
HEADER_RE = re.compile(r' file=\\".*[/\\](.*)\.h\\"')
21+
22+
try:
23+
for line in sys.stdin.readlines():
24+
line = re.sub(SWIFTMODULE_BUNDLE_RE,
25+
r'key.filepath: \1.swiftmodule', line)
26+
line = re.sub(SWIFTMODULE_RE, r'key.filepath: \1.swiftmodule', line)
27+
line = re.sub(SWIFT_RE, r'key.filepath: \1.swift', line)
28+
line = re.sub(PCM_RE, r'key.filepath: \1.pcm', line)
29+
line = re.sub(HEADER_RE, r' file=\1.h', line)
30+
sys.stdout.write(line)
31+
except KeyboardInterrupt:
32+
sys.stdout.flush()

test/SourceKit/lit.local.cfg

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
3+
14
if 'sourcekit' not in config.available_features:
25
config.unsupported = True
36

@@ -9,13 +12,10 @@ elif 'swift_evolve' in config.available_features:
912
config.unsupported = True
1013

1114
else:
12-
sed_clean = r"sed -e 's/key.filepath: \".*[/\\\\]\\(.*\\)\\.swiftmodule[/\\\\].*\\.swiftmodule\"/key.filepath: \\1.swiftmodule/g'"
13-
sed_clean += r" | sed -e 's/key.filepath: \".*[/\\\\]\\(.*\\)\\.swiftmodule\"/key.filepath: \\1.swiftmodule/g'"
14-
sed_clean += r" | sed -e 's/key.filepath: \".*[/\\\\]\\(.*\\)\\.swift\"/key.filepath: \\1.swift/g'"
15-
sed_clean += r" | sed -e 's/key.filepath: \".*[/\\\\]\\(.*\\)-[0-9A-Z]*\\.pcm\"/key.filepath: \\1.pcm/g'"
16-
sed_clean += r" | sed -e 's/ file=\\\\\".*[/\\\\]\\(.*\\)\\.h\\\\\"/ file=\\1.h/g'"
15+
sk_path_sanitize = os.path.join(os.path.dirname(__file__), 'Inputs', 'sourcekitd_path_sanitize.py')
1716

1817
config.substitutions.append( ('%sourcekitd-test', config.sourcekitd_test) )
1918
config.substitutions.append( ('%complete-test', config.complete_test) )
2019
config.substitutions.append( ('%swiftlib_dir', config.swiftlib_dir) )
21-
config.substitutions.append( ('%sed_clean', sed_clean) )
20+
config.substitutions.append( ('%sed_clean', '%s %s' % (sys.executable, sk_path_sanitize) )
21+
)

0 commit comments

Comments
 (0)