Add tests for clang plugins
authorAlp Toker <alp@nuanti.com>
Wed, 8 Jan 2014 11:38:47 +0000 (11:38 +0000)
committerAlp Toker <alp@nuanti.com>
Wed, 8 Jan 2014 11:38:47 +0000 (11:38 +0000)
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.

llvm-svn: 198747

clang/CMakeLists.txt
clang/test/Frontend/plugins.c [new file with mode: 0644]
clang/test/lit.cfg
clang/test/lit.site.cfg.in

index f635169..a54c1fa 100644 (file)
@@ -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/clang/test/Frontend/plugins.c b/clang/test/Frontend/plugins.c
new file mode 100644 (file)
index 0000000..8117f72
--- /dev/null
@@ -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();
index eea7f89..ee011c6 100644 (file)
@@ -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.
index a5234da..09d4d21 100644 (file)
@@ -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]