Skip to content

Commit 8470083

Browse files
committed
[windows] Replace SourceKit cleaning regexes for Python script.
The quoting of the sed commands was creating problems in my Windows installation. I am unsure if the implementation of sed.exe is different or the cmd.exe is different. In order to avoid problems in different machines, replace the piped sed commands into only one python script. This should be multiplatform and should execute the same in any of them. It also remove a lot of the extra quoting and escaping, and avoids 5 processes for only just one.
1 parent 25949c2 commit 8470083

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)