From: Alp Toker Date: Wed, 8 Jan 2014 11:38:47 +0000 (+0000) Subject: Add tests for clang plugins X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a47e455037b741573f7c9c074c19c2594fb4cd3;p=clang Add tests for clang plugins Somehow the entire plugin infrastructure went wholly untested until now. The only plugins available for use in testing are the examples, so plugin tests will only be run if CLANG_BUILD_EXAMPLES is enabled in the build. (The examples should really be enabled by default, not just to aid testing but also to prevent bitrot in some key user-facing code. I'll propose that shortly.) Requires supporting changes in LLVM r198746. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198747 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f635169757..a54c1fa3b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -319,6 +319,10 @@ macro(add_clang_library name) add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) endif() + if (MODULE) + set_property(TARGET ${name} PROPERTY SUFFIX ${LLVM_PLUGIN_EXT}) + endif () + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "libclang") install(TARGETS ${name} LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} diff --git a/test/Frontend/plugins.c b/test/Frontend/plugins.c new file mode 100644 index 0000000000..8117f72fa7 --- /dev/null +++ b/test/Frontend/plugins.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -load %llvmshlibdir/PrintFunctionNames%pluginext -plugin print-fns %s 2>&1 | FileCheck %s +// REQUIRES: plugins, examples + +// CHECK: top-level-decl: "x" +void x(); diff --git a/test/lit.cfg b/test/lit.cfg index eea7f89b9f..ee011c6d2e 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -195,6 +195,22 @@ config.clang = inferClang(config.environment['PATH']).replace('\\', '/') if not lit_config.quiet: lit_config.note('using clang: %r' % config.clang) +# Plugins (loadable modules) +# TODO: This should be supplied by Makefile or autoconf. +if sys.platform in ['win32', 'cygwin']: + has_plugins = (config.enable_shared == 1) +else: + has_plugins = True + +if has_plugins and config.llvm_plugin_ext: + config.available_features.add('plugins') + +config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) ) +config.substitutions.append( ('%pluginext', config.llvm_plugin_ext) ) + +if config.clang_examples: + config.available_features.add('examples') + # Note that when substituting %clang_cc1 also fill in the include directory of # the builtin headers. Those are part of even a freestanding environment, but # Clang relies on the driver to locate them. diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in index a5234da01e..09d4d213f1 100644 --- a/test/lit.site.cfg.in +++ b/test/lit.site.cfg.in @@ -6,6 +6,8 @@ config.llvm_src_root = "@LLVM_SOURCE_DIR@" config.llvm_obj_root = "@LLVM_BINARY_DIR@" config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" config.llvm_libs_dir = "@LLVM_LIBS_DIR@" +config.llvm_shlib_dir = "@SHLIBDIR@" +config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@" config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" config.clang_obj_root = "@CLANG_BINARY_DIR@" config.clang_tools_dir = "@CLANG_TOOLS_DIR@" @@ -14,6 +16,7 @@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@" config.clang_arcmt = @ENABLE_CLANG_ARCMT@ config.clang_staticanalyzer = @ENABLE_CLANG_STATIC_ANALYZER@ config.clang_rewriter = @ENABLE_CLANG_REWRITER@ +config.clang_examples = @CLANG_BUILD_EXAMPLES@ config.host_arch = "@HOST_ARCH@" # Support substitution of the tools and libs dirs with user parameters. This is @@ -21,6 +24,7 @@ config.host_arch = "@HOST_ARCH@" try: config.clang_tools_dir = config.clang_tools_dir % lit_config.params config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params + config.llvm_shlib_dir = config.llvm_shlib_dir % lit_config.params config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params except KeyError: e = sys.exc_info()[1]