|
11 | 11 |
|
12 | 12 | import argparse |
13 | 13 | import io |
| 14 | +import os |
| 15 | +import platform |
14 | 16 | import re |
15 | 17 | import subprocess |
16 | 18 | import sys |
17 | 19 |
|
| 20 | +# LLVM Lit performs realpath with the config path, so all paths are relative |
| 21 | +# to the real path. Paths that come from CMake (like cmake_binary_dir and |
| 22 | +# swift_src_root), might not do real path. Use realpath to normalize. Because |
| 23 | +# this normalizes Windows paths to use backslashes, we have to replace them |
| 24 | +# back to forward slashes. |
| 25 | +def normalize_if_path(s): |
| 26 | + if not os.path.exists(s): |
| 27 | + return s |
| 28 | + if platform.system() == "Windows": |
| 29 | + return os.path.abspath(s).replace('\\', '/') |
| 30 | + else: |
| 31 | + return os.path.realpath(s) |
18 | 32 |
|
19 | 33 | def main(): |
20 | 34 | parser = argparse.ArgumentParser( |
@@ -78,13 +92,13 @@ constants.""") |
78 | 92 |
|
79 | 93 | stdin = io.open(sys.stdin.fileno(), 'r', encoding='utf-8', errors='ignore').read() |
80 | 94 |
|
81 | | - for s in args.sanitize_strings: |
| 95 | + for s in sorted(args.sanitize_strings, key=len, reverse=True): |
82 | 96 | replacement, pattern = s.split('=', 1) |
83 | 97 | # Since we want to use pattern as a regex in some platforms, we need |
84 | 98 | # to escape it first, and then replace the escaped slash |
85 | 99 | # literal (r'\\/') for our platform-dependent slash regex. |
86 | 100 | stdin = re.sub(re.sub(r'\\/' if sys.version_info[0] < 3 else r'/', |
87 | | - slashes_re, re.escape(pattern)), |
| 101 | + slashes_re, re.escape(normalize_if_path(pattern))), |
88 | 102 | replacement, stdin) |
89 | 103 |
|
90 | 104 | # Because we force the backtracer on in the tests, we can get runtime |
|
0 commit comments