Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | import os |
| 4 | import platform |
| 5 | |
| 6 | import lit.formats |
| 7 | |
Sergej Jaskiewicz | a89d54f | 2020-07-09 19:36:15 +0300 | [diff] [blame] | 8 | # Choose between lit's internal shell pipeline runner and a real shell. If |
| 9 | # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override. |
| 10 | use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL") |
| 11 | if use_lit_shell: |
| 12 | # 0 is external, "" is default, and everything else is internal. |
| 13 | execute_external = (use_lit_shell == "0") |
| 14 | else: |
| 15 | # Otherwise we default to internal on Windows and external elsewhere, as |
| 16 | # bash on Windows is usually very slow. |
| 17 | execute_external = (not sys.platform in ['win32']) |
| 18 | |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 19 | def get_required_attr(config, attr_name): |
| 20 | attr_value = getattr(config, attr_name, None) |
| 21 | if attr_value == None: |
| 22 | lit_config.fatal( |
| 23 | "No attribute %r in test configuration! You may need to run " |
| 24 | "tests from your build directory or add this attribute " |
Reid Kleckner | 8007ff1 | 2019-06-27 20:56:04 +0000 | [diff] [blame] | 25 | "to lit.site.cfg.py " % attr_name) |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 26 | return attr_value |
| 27 | |
| 28 | # Setup config name. |
| 29 | config.name = 'Builtins' + config.name_suffix |
| 30 | |
| 31 | # Platform-specific default Builtins_OPTIONS for lit tests. |
| 32 | default_builtins_opts = '' |
| 33 | |
| 34 | # Setup source root. |
| 35 | config.test_source_root = os.path.dirname(__file__) |
| 36 | |
| 37 | # Path to the static library |
Reid Kleckner | dffe5a3 | 2018-11-01 00:00:03 +0000 | [diff] [blame] | 38 | is_msvc = get_required_attr(config, "is_msvc") |
Reid Kleckner | 8c78ca2 | 2017-04-07 16:35:09 +0000 | [diff] [blame] | 39 | if is_msvc: |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 +0000 | [diff] [blame] | 40 | base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.builtins%s.lib " |
| 41 | % config.target_suffix) |
Reid Kleckner | 8c78ca2 | 2017-04-07 16:35:09 +0000 | [diff] [blame] | 42 | config.substitutions.append( ("%librt ", base_lib) ) |
Nico Weber | 34b6f49 | 2019-09-14 22:22:47 +0000 | [diff] [blame] | 43 | elif config.host_os == 'Darwin': |
| 44 | base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.osx.a ") |
| 45 | config.substitutions.append( ("%librt ", base_lib + ' -lSystem ') ) |
Reid Kleckner | 8c78ca2 | 2017-04-07 16:35:09 +0000 | [diff] [blame] | 46 | else: |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 +0000 | [diff] [blame] | 47 | base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.builtins%s.a" |
| 48 | % config.target_suffix) |
Sergej Jaskiewicz | a89d54f | 2020-07-09 19:36:15 +0300 | [diff] [blame] | 49 | if sys.platform in ['win32'] and execute_external: |
| 50 | # Don't pass dosish path separator to msys bash.exe. |
| 51 | base_lib = base_lib.replace('\\', '/') |
Reid Kleckner | 8c78ca2 | 2017-04-07 16:35:09 +0000 | [diff] [blame] | 52 | config.substitutions.append( ("%librt ", base_lib + ' -lc -lm ') ) |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 53 | |
| 54 | builtins_source_dir = os.path.join( |
| 55 | get_required_attr(config, "compiler_rt_src_root"), "lib", "builtins") |
Sergej Jaskiewicz | a89d54f | 2020-07-09 19:36:15 +0300 | [diff] [blame] | 56 | if sys.platform in ['win32'] and execute_external: |
| 57 | # Don't pass dosish path separator to msys bash.exe. |
| 58 | builtins_source_dir = builtins_source_dir.replace('\\', '/') |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 59 | builtins_lit_source_dir = get_required_attr(config, "builtins_lit_source_dir") |
| 60 | |
| 61 | extra_link_flags = ["-nodefaultlibs"] |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 62 | |
| 63 | target_cflags = [get_required_attr(config, "target_cflags")] |
| 64 | target_cflags += ['-fno-builtin', '-I', builtins_source_dir] |
| 65 | target_cflags += extra_link_flags |
| 66 | target_cxxflags = config.cxx_mode_flags + target_cflags |
| 67 | clang_builtins_static_cflags = ([""] + |
| 68 | config.debug_info_flags + target_cflags) |
| 69 | clang_builtins_static_cxxflags = config.cxx_mode_flags + \ |
| 70 | clang_builtins_static_cflags |
| 71 | |
| 72 | clang_builtins_cflags = clang_builtins_static_cflags |
| 73 | clang_builtins_cxxflags = clang_builtins_static_cxxflags |
| 74 | |
Reid Kleckner | dffe5a3 | 2018-11-01 00:00:03 +0000 | [diff] [blame] | 75 | # FIXME: Right now we don't compile the C99 complex builtins when using |
| 76 | # clang-cl. Fix that. |
Reid Kleckner | 8c78ca2 | 2017-04-07 16:35:09 +0000 | [diff] [blame] | 77 | if not is_msvc: |
| 78 | config.available_features.add('c99-complex') |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 79 | |
Reid Kleckner | dffe5a3 | 2018-11-01 00:00:03 +0000 | [diff] [blame] | 80 | builtins_is_msvc = get_required_attr(config, "builtins_is_msvc") |
| 81 | if not builtins_is_msvc: |
| 82 | config.available_features.add('int128') |
| 83 | |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 84 | clang_wrapper = "" |
| 85 | |
| 86 | def build_invocation(compile_flags): |
| 87 | return " " + " ".join([clang_wrapper, config.clang] + compile_flags) + " " |
| 88 | |
| 89 | |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 90 | config.substitutions.append( ("%clang ", build_invocation(target_cflags)) ) |
| 91 | config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) ) |
| 92 | config.substitutions.append( ("%clang_builtins ", \ |
| 93 | build_invocation(clang_builtins_cflags))) |
| 94 | config.substitutions.append( ("%clangxx_builtins ", \ |
| 95 | build_invocation(clang_builtins_cxxflags))) |
| 96 | |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 97 | # Default test suffixes. |
Nico Weber | 307beb1 | 2019-08-05 19:25:35 +0000 | [diff] [blame] | 98 | config.suffixes = ['.c', '.cpp'] |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 99 | |
| 100 | if not config.emulator: |
| 101 | config.available_features.add('native-run') |
Dan Liew | 5be7eb3 | 2019-10-17 18:12:49 +0000 | [diff] [blame] | 102 | |
| 103 | # Add features for available sources |
| 104 | builtins_source_features = config.builtins_lit_source_features.split(';') |
| 105 | # Sanity checks |
| 106 | if not builtins_source_features: |
| 107 | lit_config.fatal('builtins_source_features cannot be empty') |
| 108 | builtins_source_features_set = set() |
| 109 | builtins_source_feature_duplicates = [] |
| 110 | for builtin_source_feature in builtins_source_features: |
| 111 | if len(builtin_source_feature) == 0: |
| 112 | lit_config.fatal('builtins_source_feature cannot contain empty features') |
| 113 | if builtin_source_feature not in builtins_source_features_set: |
| 114 | builtins_source_features_set.add(builtin_source_feature) |
| 115 | else: |
| 116 | builtins_source_feature_duplicates.append(builtin_source_feature) |
| 117 | |
| 118 | if len(builtins_source_feature_duplicates) > 0: |
Dan Liew | 23a33d4 | 2019-10-30 16:21:46 -0700 | [diff] [blame] | 119 | lit_config.fatal( |
Dan Liew | 5be7eb3 | 2019-10-17 18:12:49 +0000 | [diff] [blame] | 120 | 'builtins_source_features contains duplicates: {}'.format( |
| 121 | builtins_source_feature_duplicates) |
| 122 | ) |
| 123 | config.available_features.update(builtins_source_features) |