Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -649,6 +649,7 @@ add_subdirectory(utils/not) add_subdirectory(utils/llvm-lit) add_subdirectory(utils/yaml-bench) + add_subdirectory(utils/lit) else() if ( LLVM_INCLUDE_TESTS ) message(FATAL_ERROR "Including tests when not building utils will not work. Index: utils/lit/CMakeLists.txt =================================================================== --- utils/lit/CMakeLists.txt +++ utils/lit/CMakeLists.txt @@ -0,0 +1,20 @@ +# LIT's self tests write out temporary files relative to themselves, +# which dirties the source dir. To avoid this, we copy them to the build +# directory, and run them from there. +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/tests + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/tests/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/tests/lit.site.cfg + ) + +add_custom_command(TARGET check-lit + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_SOURCE_DIR}/tests + ${CMAKE_CURRENT_BINARY_DIR}/tests) + +add_lit_testsuite(check-lit "Running lit's self tests" + ${CMAKE_CURRENT_BINARY_DIR}/tests + DEPENDS FileCheck not) +set_target_properties(check-lit PROPERTIES FOLDER "Tests") Index: utils/lit/tests/lit.cfg =================================================================== --- utils/lit/tests/lit.cfg +++ utils/lit/tests/lit.cfg @@ -21,8 +21,20 @@ # test_source_root: The root path where tests are located. config.test_source_root = os.path.dirname(__file__) -config.test_exec_root = config.test_source_root +llvm_src_root = getattr(config, 'llvm_src_root', None) +if llvm_src_root is not None: + lit_path = os.path.join(llvm_src_root, 'utils/lit/lit.py') +else: + lit_path = os.path.join(config.test_source_root, '../lit.py') + +# test_exec_root: The root path where tests should be run. +llvm_obj_root = getattr(config, 'llvm_obj_root', None) +if llvm_obj_root is not None: + config.test_exec_root = os.path.join(llvm_obj_root, 'utils/lit/tests') +else: + config.test_exec_root = config.test_source_root + config.target_triple = '(unused)' src_root = os.path.join(config.test_source_root, '..') @@ -30,8 +42,8 @@ config.substitutions.append(('%{src_root}', src_root)) config.substitutions.append(('%{inputs}', os.path.join( src_root, 'tests', 'Inputs'))) -config.substitutions.append(('%{lit}', "%%{python} %s" % ( - os.path.join(src_root, 'lit.py'),))) +config.substitutions.append(('%{lit}', "%%{python} %s" % + (lit_path,))) config.substitutions.append(('%{python}', sys.executable)) # Enable coverage.py reporting, assuming the coverage module has been installed Index: utils/lit/tests/lit.site.cfg.in =================================================================== --- utils/lit/tests/lit.site.cfg.in +++ utils/lit/tests/lit.site.cfg.in @@ -0,0 +1,7 @@ +## Autogenerated by LLVM/Clang configuration. +# Do not edit! +config.llvm_src_root = "@LLVM_SOURCE_DIR@" +config.llvm_obj_root = "@LLVM_BINARY_DIR@" + +# Let the main config do the real work. +lit_config.load_config(config, "@LLVM_BINARY_DIR@/utils/lit/tests/lit.cfg") Index: utils/lit/tests/progress-bar.py =================================================================== --- utils/lit/tests/progress-bar.py +++ utils/lit/tests/progress-bar.py @@ -11,3 +11,5 @@ # CHECK: FAIL: shtest-shell :: test-3.txt (3 of 4) # CHECK: Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. # CHECK: FAIL: shtest-shell :: test-4.txt (4 of 4) + +# foo bar baz