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' |
Daniel Dunbar | bc20ef3 | 2009-11-08 01:47:35 +0000 | [diff] [blame] | 16 | config.test_format = lit.formats.ShTest(execute_external) |
Daniel Dunbar | 6827f3f | 2009-09-06 01:31:12 +0000 | [diff] [blame] | 17 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 18 | # suffixes: A list of file extensions to treat as test files. |
| 19 | config.suffixes = ['.c', '.cpp', '.m', '.mm'] |
| 20 | |
| 21 | # test_source_root: The root path where tests are located. |
| 22 | config.test_source_root = os.path.dirname(__file__) |
| 23 | |
| 24 | # test_exec_root: The root path where tests should be run. |
| 25 | clang_obj_root = getattr(config, 'clang_obj_root', None) |
| 26 | if clang_obj_root is not None: |
| 27 | config.test_exec_root = os.path.join(clang_obj_root, 'test') |
| 28 | |
| 29 | # Set llvm_{src,obj}_root for use by others. |
| 30 | config.llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 31 | config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 32 | |
| 33 | # Tweak the PATH to include the tools dir and the scripts dir. |
| 34 | if clang_obj_root is not None: |
| 35 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 36 | if not llvm_tools_dir: |
| 37 | lit.fatal('No LLVM tools dir set!') |
Daniel Dunbar | ee45d6d | 2009-09-24 06:31:08 +0000 | [diff] [blame] | 38 | path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 39 | config.environment['PATH'] = path |
| 40 | |
Daniel Dunbar | 9e10cc7 | 2009-09-26 07:36:09 +0000 | [diff] [blame] | 41 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 42 | if not llvm_libs_dir: |
| 43 | lit.fatal('No LLVM libs dir set!') |
| 44 | path = os.path.pathsep.join((llvm_libs_dir, |
| 45 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 46 | config.environment['LD_LIBRARY_PATH'] = path |
| 47 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 48 | ### |
| 49 | |
| 50 | # Check that the object root is known. |
| 51 | if config.test_exec_root is None: |
| 52 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 53 | # probably trying to run on a test file directly, and either the site |
| 54 | # configuration hasn't been created by the build system, or we are in an |
| 55 | # out-of-tree build situation). |
| 56 | |
Daniel Dunbar | b258d8f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 57 | # Check for 'clang_site_config' user parameter, and use that if available. |
| 58 | site_cfg = lit.params.get('clang_site_config', None) |
| 59 | if site_cfg and os.path.exists(site_cfg): |
| 60 | lit.load_config(config, site_cfg) |
| 61 | raise SystemExit |
| 62 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 63 | # Try to detect the situation where we are using an out-of-tree build by |
| 64 | # looking for 'llvm-config'. |
| 65 | # |
| 66 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 67 | # automagically generate the lit.site.cfg if we are in some kind of fresh |
Daniel Dunbar | 2335421 | 2009-11-07 23:53:17 +0000 | [diff] [blame] | 68 | # build situation. This means knowing how to invoke the build system though, |
| 69 | # and I decided it was too much magic. We should solve this by just having |
| 70 | # the .cfg files generated during the configuration step. |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 71 | |
| 72 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 73 | if not llvm_config: |
| 74 | lit.fatal('No site specific configuration available!') |
| 75 | |
| 76 | # Get the source and object roots. |
| 77 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 78 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 79 | clang_src_root = os.path.join(llvm_src_root, "tools", "clang") |
| 80 | clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang") |
| 81 | |
| 82 | # Validate that we got a tree which points to here, using the standard |
| 83 | # tools/clang layout. |
| 84 | this_src_root = os.path.dirname(config.test_source_root) |
| 85 | if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root): |
| 86 | lit.fatal('No site specific configuration available!') |
| 87 | |
| 88 | # Check that the site specific configuration exists. |
| 89 | site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg') |
| 90 | if not os.path.exists(site_cfg): |
| 91 | lit.fatal('No site specific configuration available!') |
| 92 | |
| 93 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
| 94 | lit.note('using out-of-tree build at %r' % clang_obj_root) |
| 95 | lit.load_config(config, site_cfg) |
| 96 | raise SystemExit |
| 97 | |
| 98 | ### |
| 99 | |
| 100 | # Discover the 'clang' and 'clangcc' to use. |
| 101 | |
| 102 | import os |
| 103 | |
| 104 | def inferClang(PATH): |
| 105 | # Determine which clang to use. |
| 106 | clang = os.getenv('CLANG') |
| 107 | |
| 108 | # If the user set clang in the environment, definitely use that and don't |
| 109 | # try to validate. |
| 110 | if clang: |
| 111 | return clang |
| 112 | |
| 113 | # Otherwise look in the path. |
| 114 | clang = lit.util.which('clang', PATH) |
| 115 | |
| 116 | if not clang: |
| 117 | lit.fatal("couldn't find 'clang' program, try setting " |
| 118 | "CLANG in your environment") |
| 119 | |
| 120 | return clang |
| 121 | |
Daniel Dunbar | e1fa096 | 2010-03-20 21:13:08 +0000 | [diff] [blame] | 122 | # When running under valgrind, we mangle '-vg' onto the end of the triple so we |
| 123 | # can check it with XFAIL and XTARGET. |
| 124 | if lit.useValgrind: |
| 125 | config.target_triple += '-vg' |
| 126 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 127 | config.clang = inferClang(config.environment['PATH']) |
| 128 | if not lit.quiet: |
| 129 | lit.note('using clang: %r' % config.clang) |
Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 130 | config.substitutions.append( ('%clang_cc1', config.clang + ' -cc1') ) |
Daniel Dunbar | 6643096 | 2010-02-18 18:10:26 +0000 | [diff] [blame] | 131 | config.substitutions.append( ('%clangxx', ' ' + config.clang + ' -ccc-cxx')) |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 132 | config.substitutions.append( ('%clang', ' ' + config.clang + ' ') ) |
Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 133 | |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 134 | # FIXME: Find nicer way to prohibit this. |
| 135 | config.substitutions.append( |
| 136 | (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") ) |
| 137 | config.substitutions.append( |
Daniel Dunbar | 679d605 | 2010-02-17 20:31:01 +0000 | [diff] [blame] | 138 | (' clang++ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***""")) |
| 139 | config.substitutions.append( |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 140 | (' clang-cc ', |
| 141 | """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") ) |
| 142 | config.substitutions.append( |
| 143 | (' clang -cc1 ', |
| 144 | """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") ) |