Daniel Dunbar | 1db467f | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 3 | import os |
Daniel Dunbar | b850ddd | 2009-09-22 10:08:03 +0000 | [diff] [blame] | 4 | import platform |
Daniel Dunbar | 724827f | 2009-09-08 16:39:23 +0000 | [diff] [blame] | 5 | |
Daniel Dunbar | 1db467f | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 6 | # Configuration file for the 'lit' test runner. |
| 7 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 8 | # name: The name of this test suite. |
| 9 | config.name = 'Clang' |
Daniel Dunbar | 724827f | 2009-09-08 16:39:23 +0000 | [diff] [blame] | 10 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 11 | # testFormat: The test format to use to interpret tests. |
Daniel Dunbar | 1db467f | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 12 | # |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 13 | # For now we require '&&' between commands, until they get globally killed and |
| 14 | # the test runner updated. |
Daniel Dunbar | b850ddd | 2009-09-22 10:08:03 +0000 | [diff] [blame] | 15 | execute_external = platform.system() != 'Windows' |
| 16 | config.test_format = lit.formats.ShTest(execute_external, |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 17 | require_and_and = True) |
Daniel Dunbar | 6827f3f | 2009-09-06 01:31:12 +0000 | [diff] [blame] | 18 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 19 | # suffixes: A list of file extensions to treat as test files. |
| 20 | config.suffixes = ['.c', '.cpp', '.m', '.mm'] |
| 21 | |
| 22 | # test_source_root: The root path where tests are located. |
| 23 | config.test_source_root = os.path.dirname(__file__) |
| 24 | |
| 25 | # test_exec_root: The root path where tests should be run. |
| 26 | clang_obj_root = getattr(config, 'clang_obj_root', None) |
| 27 | if clang_obj_root is not None: |
| 28 | config.test_exec_root = os.path.join(clang_obj_root, 'test') |
| 29 | |
| 30 | # Set llvm_{src,obj}_root for use by others. |
| 31 | config.llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 32 | config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 33 | |
| 34 | # Tweak the PATH to include the tools dir and the scripts dir. |
| 35 | if clang_obj_root is not None: |
| 36 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 37 | if not llvm_tools_dir: |
| 38 | lit.fatal('No LLVM tools dir set!') |
Daniel Dunbar | ee45d6d | 2009-09-24 06:31:08 +0000 | [diff] [blame] | 39 | path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 40 | config.environment['PATH'] = path |
| 41 | |
Daniel Dunbar | 9e10cc7 | 2009-09-26 07:36:09 +0000 | [diff] [blame] | 42 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 43 | if not llvm_libs_dir: |
| 44 | lit.fatal('No LLVM libs dir set!') |
| 45 | path = os.path.pathsep.join((llvm_libs_dir, |
| 46 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 47 | config.environment['LD_LIBRARY_PATH'] = path |
| 48 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 49 | ### |
| 50 | |
| 51 | # Check that the object root is known. |
| 52 | if config.test_exec_root is None: |
| 53 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 54 | # probably trying to run on a test file directly, and either the site |
| 55 | # configuration hasn't been created by the build system, or we are in an |
| 56 | # out-of-tree build situation). |
| 57 | |
| 58 | # Try to detect the situation where we are using an out-of-tree build by |
| 59 | # looking for 'llvm-config'. |
| 60 | # |
| 61 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 62 | # automagically generate the lit.site.cfg if we are in some kind of fresh |
| 63 | # build situation. This means knowing how to invoke the build system |
| 64 | # though, and I decided it was too much magic. |
| 65 | |
| 66 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 67 | if not llvm_config: |
| 68 | lit.fatal('No site specific configuration available!') |
| 69 | |
| 70 | # Get the source and object roots. |
| 71 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 72 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 73 | clang_src_root = os.path.join(llvm_src_root, "tools", "clang") |
| 74 | clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang") |
| 75 | |
| 76 | # Validate that we got a tree which points to here, using the standard |
| 77 | # tools/clang layout. |
| 78 | this_src_root = os.path.dirname(config.test_source_root) |
| 79 | if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root): |
| 80 | lit.fatal('No site specific configuration available!') |
| 81 | |
| 82 | # Check that the site specific configuration exists. |
| 83 | site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg') |
| 84 | if not os.path.exists(site_cfg): |
| 85 | lit.fatal('No site specific configuration available!') |
| 86 | |
| 87 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
| 88 | lit.note('using out-of-tree build at %r' % clang_obj_root) |
| 89 | lit.load_config(config, site_cfg) |
| 90 | raise SystemExit |
| 91 | |
| 92 | ### |
| 93 | |
| 94 | # Discover the 'clang' and 'clangcc' to use. |
| 95 | |
| 96 | import os |
| 97 | |
| 98 | def inferClang(PATH): |
| 99 | # Determine which clang to use. |
| 100 | clang = os.getenv('CLANG') |
| 101 | |
| 102 | # If the user set clang in the environment, definitely use that and don't |
| 103 | # try to validate. |
| 104 | if clang: |
| 105 | return clang |
| 106 | |
| 107 | # Otherwise look in the path. |
| 108 | clang = lit.util.which('clang', PATH) |
| 109 | |
| 110 | if not clang: |
| 111 | lit.fatal("couldn't find 'clang' program, try setting " |
| 112 | "CLANG in your environment") |
| 113 | |
| 114 | return clang |
| 115 | |
| 116 | def inferClangCC(clang, PATH): |
| 117 | clangcc = os.getenv('CLANGCC') |
| 118 | |
| 119 | # If the user set clang in the environment, definitely use that and don't |
| 120 | # try to validate. |
| 121 | if clangcc: |
| 122 | return clangcc |
| 123 | |
| 124 | # Otherwise try adding -cc since we expect to be looking in a build |
| 125 | # directory. |
| 126 | if clang.endswith('.exe'): |
| 127 | clangccName = clang[:-4] + '-cc.exe' |
| 128 | else: |
| 129 | clangccName = clang + '-cc' |
| 130 | clangcc = lit.util.which(clangccName, PATH) |
| 131 | if not clangcc: |
| 132 | # Otherwise ask clang. |
| 133 | res = lit.util.capture([clang, '-print-prog-name=clang-cc']) |
| 134 | res = res.strip() |
| 135 | if res and os.path.exists(res): |
| 136 | clangcc = res |
| 137 | |
| 138 | if not clangcc: |
| 139 | lit.fatal("couldn't find 'clang-cc' program, try setting " |
| 140 | "CLANGCC in your environment") |
| 141 | |
| 142 | return clangcc |
| 143 | |
| 144 | config.clang = inferClang(config.environment['PATH']) |
| 145 | if not lit.quiet: |
| 146 | lit.note('using clang: %r' % config.clang) |
| 147 | config.substitutions.append( (' clang ', ' ' + config.clang + ' ') ) |
| 148 | |
| 149 | config.clang_cc = inferClangCC(config.clang, config.environment['PATH']) |
| 150 | if not lit.quiet: |
| 151 | lit.note('using clang-cc: %r' % config.clang_cc) |
| 152 | config.substitutions.append( (' clang-cc ', ' ' + config.clang_cc + ' ') ) |