|
9 | 9 | # Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if |
10 | 10 | # it's not available. |
11 | 11 | try: |
12 | | - import shlex |
13 | | - sh_quote = shlex.quote |
| 12 | + import shlex |
| 13 | + |
| 14 | + sh_quote = shlex.quote |
14 | 15 | except: |
15 | | - import pipes |
16 | | - sh_quote = pipes.quote |
| 16 | + import pipes |
| 17 | + |
| 18 | + sh_quote = pipes.quote |
| 19 | + |
17 | 20 |
|
18 | 21 | def get_required_attr(config, attr_name): |
19 | | - attr_value = getattr(config, attr_name, None) |
20 | | - if attr_value == None: |
21 | | - lit_config.fatal( |
22 | | - "No attribute %r in test configuration! You may need to run " |
23 | | - "tests from your build directory or add this attribute " |
24 | | - "to lit.site.cfg.py " % attr_name) |
25 | | - return attr_value |
| 22 | + attr_value = getattr(config, attr_name, None) |
| 23 | + if attr_value == None: |
| 24 | + lit_config.fatal( |
| 25 | + "No attribute %r in test configuration! You may need to run " |
| 26 | + "tests from your build directory or add this attribute " |
| 27 | + "to lit.site.cfg.py " % attr_name |
| 28 | + ) |
| 29 | + return attr_value |
| 30 | + |
26 | 31 |
|
27 | 32 | def push_dynamic_library_lookup_path(config, new_path): |
28 | | - if platform.system() == 'Windows': |
29 | | - dynamic_library_lookup_var = 'PATH' |
30 | | - elif platform.system() == 'Darwin': |
31 | | - dynamic_library_lookup_var = 'DYLD_LIBRARY_PATH' |
32 | | - else: |
33 | | - dynamic_library_lookup_var = 'LD_LIBRARY_PATH' |
34 | | - |
35 | | - new_ld_library_path = os.path.pathsep.join( |
36 | | - (new_path, config.environment.get(dynamic_library_lookup_var, ''))) |
37 | | - config.environment[dynamic_library_lookup_var] = new_ld_library_path |
38 | | - |
39 | | - if platform.system() == 'FreeBSD': |
40 | | - dynamic_library_lookup_var = 'LD_32_LIBRARY_PATH' |
41 | | - new_ld_32_library_path = os.path.pathsep.join( |
42 | | - (new_path, config.environment.get(dynamic_library_lookup_var, ''))) |
43 | | - config.environment[dynamic_library_lookup_var] = new_ld_32_library_path |
44 | | - |
45 | | - if platform.system() == 'SunOS': |
46 | | - dynamic_library_lookup_var = 'LD_LIBRARY_PATH_32' |
47 | | - new_ld_library_path_32 = os.path.pathsep.join( |
48 | | - (new_path, config.environment.get(dynamic_library_lookup_var, ''))) |
49 | | - config.environment[dynamic_library_lookup_var] = new_ld_library_path_32 |
50 | | - |
51 | | - dynamic_library_lookup_var = 'LD_LIBRARY_PATH_64' |
52 | | - new_ld_library_path_64 = os.path.pathsep.join( |
53 | | - (new_path, config.environment.get(dynamic_library_lookup_var, ''))) |
54 | | - config.environment[dynamic_library_lookup_var] = new_ld_library_path_64 |
| 33 | + if platform.system() == "Windows": |
| 34 | + dynamic_library_lookup_var = "PATH" |
| 35 | + elif platform.system() == "Darwin": |
| 36 | + dynamic_library_lookup_var = "DYLD_LIBRARY_PATH" |
| 37 | + else: |
| 38 | + dynamic_library_lookup_var = "LD_LIBRARY_PATH" |
| 39 | + |
| 40 | + new_ld_library_path = os.path.pathsep.join( |
| 41 | + (new_path, config.environment.get(dynamic_library_lookup_var, "")) |
| 42 | + ) |
| 43 | + config.environment[dynamic_library_lookup_var] = new_ld_library_path |
| 44 | + |
| 45 | + if platform.system() == "FreeBSD": |
| 46 | + dynamic_library_lookup_var = "LD_32_LIBRARY_PATH" |
| 47 | + new_ld_32_library_path = os.path.pathsep.join( |
| 48 | + (new_path, config.environment.get(dynamic_library_lookup_var, "")) |
| 49 | + ) |
| 50 | + config.environment[dynamic_library_lookup_var] = new_ld_32_library_path |
| 51 | + |
| 52 | + if platform.system() == "SunOS": |
| 53 | + dynamic_library_lookup_var = "LD_LIBRARY_PATH_32" |
| 54 | + new_ld_library_path_32 = os.path.pathsep.join( |
| 55 | + (new_path, config.environment.get(dynamic_library_lookup_var, "")) |
| 56 | + ) |
| 57 | + config.environment[dynamic_library_lookup_var] = new_ld_library_path_32 |
| 58 | + |
| 59 | + dynamic_library_lookup_var = "LD_LIBRARY_PATH_64" |
| 60 | + new_ld_library_path_64 = os.path.pathsep.join( |
| 61 | + (new_path, config.environment.get(dynamic_library_lookup_var, "")) |
| 62 | + ) |
| 63 | + config.environment[dynamic_library_lookup_var] = new_ld_library_path_64 |
| 64 | + |
55 | 65 |
|
56 | 66 | # Setup config name. |
57 | | -config.name = 'TypeSanitizer' + config.name_suffix |
| 67 | +config.name = "TypeSanitizer" + config.name_suffix |
58 | 68 |
|
59 | 69 | # Platform-specific default TYSAN_OPTIONS for lit tests. |
60 | 70 | default_tysan_opts = list(config.default_sanitizer_opts) |
61 | 71 |
|
62 | 72 | # On Darwin, leak checking is not enabled by default. Enable on macOS |
63 | 73 | # tests to prevent regressions |
64 | | -if config.host_os == 'Darwin' and config.apple_platform == 'osx': |
65 | | - default_tysan_opts += ['detect_leaks=1'] |
| 74 | +if config.host_os == "Darwin" and config.apple_platform == "osx": |
| 75 | + default_tysan_opts += ["detect_leaks=1"] |
66 | 76 |
|
67 | | -default_tysan_opts_str = ':'.join(default_tysan_opts) |
| 77 | +default_tysan_opts_str = ":".join(default_tysan_opts) |
68 | 78 | if default_tysan_opts_str: |
69 | | - config.environment['TYSAN_OPTIONS'] = default_tysan_opts_str |
70 | | - default_tysan_opts_str += ':' |
71 | | -config.substitutions.append(('%env_tysan_opts=', |
72 | | - 'env TYSAN_OPTIONS=' + default_tysan_opts_str)) |
| 79 | + config.environment["TYSAN_OPTIONS"] = default_tysan_opts_str |
| 80 | + default_tysan_opts_str += ":" |
| 81 | +config.substitutions.append( |
| 82 | + ("%env_tysan_opts=", "env TYSAN_OPTIONS=" + default_tysan_opts_str) |
| 83 | +) |
73 | 84 |
|
74 | 85 | # Setup source root. |
75 | 86 | config.test_source_root = os.path.dirname(__file__) |
76 | 87 |
|
77 | | -if config.host_os not in ['FreeBSD', 'NetBSD']: |
78 | | - libdl_flag = "-ldl" |
| 88 | +if config.host_os not in ["FreeBSD", "NetBSD"]: |
| 89 | + libdl_flag = "-ldl" |
79 | 90 | else: |
80 | | - libdl_flag = "" |
| 91 | + libdl_flag = "" |
81 | 92 |
|
82 | 93 | # GCC-ASan doesn't link in all the necessary libraries automatically, so |
83 | 94 | # we have to do it ourselves. |
84 | | -if config.compiler_id == 'GNU': |
85 | | - extra_link_flags = ["-pthread", "-lstdc++", libdl_flag] |
| 95 | +if config.compiler_id == "GNU": |
| 96 | + extra_link_flags = ["-pthread", "-lstdc++", libdl_flag] |
86 | 97 | else: |
87 | | - extra_link_flags = [] |
| 98 | + extra_link_flags = [] |
88 | 99 |
|
89 | 100 | # Setup default compiler flags used with -fsanitize=address option. |
90 | 101 | # FIXME: Review the set of required flags and check if it can be reduced. |
91 | 102 | target_cflags = [get_required_attr(config, "target_cflags")] + extra_link_flags |
92 | 103 | target_cxxflags = config.cxx_mode_flags + target_cflags |
93 | | -clang_tysan_static_cflags = (["-fsanitize=type", |
94 | | - "-mno-omit-leaf-frame-pointer", |
95 | | - "-fno-omit-frame-pointer", |
96 | | - "-fno-optimize-sibling-calls"] + |
97 | | - config.debug_info_flags + target_cflags) |
98 | | -if config.target_arch == 's390x': |
99 | | - clang_tysan_static_cflags.append("-mbackchain") |
| 104 | +clang_tysan_static_cflags = ( |
| 105 | + [ |
| 106 | + "-fsanitize=type", |
| 107 | + "-mno-omit-leaf-frame-pointer", |
| 108 | + "-fno-omit-frame-pointer", |
| 109 | + "-fno-optimize-sibling-calls", |
| 110 | + ] |
| 111 | + + config.debug_info_flags |
| 112 | + + target_cflags |
| 113 | +) |
| 114 | +if config.target_arch == "s390x": |
| 115 | + clang_tysan_static_cflags.append("-mbackchain") |
100 | 116 | clang_tysan_static_cxxflags = config.cxx_mode_flags + clang_tysan_static_cflags |
101 | 117 |
|
102 | | -clang_tysan_cflags = clang_tysan_static_cflags |
| 118 | +clang_tysan_cflags = clang_tysan_static_cflags |
103 | 119 | clang_tysan_cxxflags = clang_tysan_static_cxxflags |
104 | 120 |
|
| 121 | + |
105 | 122 | def build_invocation(compile_flags): |
106 | | - return " " + " ".join([config.clang] + compile_flags) + " " |
| 123 | + return " " + " ".join([config.clang] + compile_flags) + " " |
| 124 | + |
107 | 125 |
|
108 | | -config.substitutions.append( ("%clang ", build_invocation(target_cflags)) ) |
109 | | -config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) ) |
110 | | -config.substitutions.append( ("%clang_tysan ", build_invocation(clang_tysan_cflags)) ) |
111 | | -config.substitutions.append( ("%clangxx_tysan ", build_invocation(clang_tysan_cxxflags)) ) |
| 126 | +config.substitutions.append(("%clang ", build_invocation(target_cflags))) |
| 127 | +config.substitutions.append(("%clangxx ", build_invocation(target_cxxflags))) |
| 128 | +config.substitutions.append(("%clang_tysan ", build_invocation(clang_tysan_cflags))) |
| 129 | +config.substitutions.append(("%clangxx_tysan ", build_invocation(clang_tysan_cxxflags))) |
112 | 130 |
|
113 | 131 |
|
114 | 132 | # FIXME: De-hardcode this path. |
115 | 133 | tysan_source_dir = os.path.join( |
116 | | - get_required_attr(config, "compiler_rt_src_root"), "lib", "tysan") |
| 134 | + get_required_attr(config, "compiler_rt_src_root"), "lib", "tysan" |
| 135 | +) |
117 | 136 | python_exec = sh_quote(get_required_attr(config, "python_executable")) |
118 | 137 |
|
119 | 138 | # Set LD_LIBRARY_PATH to pick dynamic runtime up properly. |
120 | 139 | push_dynamic_library_lookup_path(config, config.compiler_rt_libdir) |
121 | 140 |
|
122 | 141 | # Default test suffixes. |
123 | | -config.suffixes = ['.c', '.cpp'] |
| 142 | +config.suffixes = [".c", ".cpp"] |
124 | 143 |
|
125 | | -if config.host_os == 'Darwin': |
126 | | - config.suffixes.append('.mm') |
| 144 | +if config.host_os == "Darwin": |
| 145 | + config.suffixes.append(".mm") |
127 | 146 |
|
128 | | -if config.host_os == 'Windows': |
129 | | - config.substitutions.append(('%fPIC', '')) |
130 | | - config.substitutions.append(('%fPIE', '')) |
131 | | - config.substitutions.append(('%pie', '')) |
| 147 | +if config.host_os == "Windows": |
| 148 | + config.substitutions.append(("%fPIC", "")) |
| 149 | + config.substitutions.append(("%fPIE", "")) |
| 150 | + config.substitutions.append(("%pie", "")) |
132 | 151 | else: |
133 | | - config.substitutions.append(('%fPIC', '-fPIC')) |
134 | | - config.substitutions.append(('%fPIE', '-fPIE')) |
135 | | - config.substitutions.append(('%pie', '-pie')) |
| 152 | + config.substitutions.append(("%fPIC", "-fPIC")) |
| 153 | + config.substitutions.append(("%fPIE", "-fPIE")) |
| 154 | + config.substitutions.append(("%pie", "-pie")) |
136 | 155 |
|
137 | 156 | # Only run the tests on supported OSs. |
138 | | -if config.host_os not in ['Linux', 'Darwin',]: |
139 | | - config.unsupported = True |
| 157 | +if config.host_os not in [ |
| 158 | + "Linux", |
| 159 | + "Darwin", |
| 160 | +]: |
| 161 | + config.unsupported = Tr |
0 commit comments