summaryrefslogtreecommitdiff
path: root/solenv/gbuild/CompilerTest.mk
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-11-14 23:35:19 +0100
committerStephan Bergmann <sbergman@redhat.com>2016-11-15 11:09:29 +0100
commit645583dfd374c8b02f3c0eeba6233a0bb5884d68 (patch)
tree522ce0e474fb6263a69b3402f786245c73a1357e /solenv/gbuild/CompilerTest.mk
parent10efab2b9a3cf7fc49655c90ba29db4512680c38 (diff)
New compilerplugins/clang unit tests
...to check that loplugin produces warnings/errors as expected: * Clang has a -verify switch that makes it easy to write test input .cxx files that list in comments all the warnings/errors that are expected, and let Clang check those expectations instead of generating object code. See include/clang/Frontend/VerifyDiagnosticConsumer.h in the Clang source tree for documentation. * Introduce a CompilerTest gbuild class that uses the existing LinkTarget class as much as possible. Checking the input files is implicitly phony, as the compilation step doesn't generate any object files, and the link step does nothing because there is no gb_LinkTarget_set_targettype for CompilerTest. The setup at least works for Clang on Linux (will need adaptions for Clang on Windows; compilers other than Clang are not relevant for now given this is used to check compilerplugins). * Definition of gb_CFLAGS_WERROR in solenv/gbuild/platform/com_GCC_defs.mk needs to be lazy ('=' vs. ':=') so that CompilerTest can override it: The Clang -verify mode wants the input files to specify whether the loplugin diagnostics are warnings or errros, so they consistently need to be errors independent of --enable-werror configuration. * A first (example) test is in compilerplugins/clang/test/salbool.cxx. The corresponding gbuild CompilerTest instance is in solenv/CompilerTest_compilerplugins_clang.mk for now. The reason for that odd split across compilerplugins/ and solenv/ is that there is no compilerplugins/Modules_compilerplugins.mk file, so this setup is the easiest hack for now (to be cleaned up). (Another area that could be improved is that all test files need to be listed explicitly in the CompilerTest_*.mk file, instead of, say, using all .c/.cxx/.m/.mm files in a specified directory.) * The test is run somewhat late during a top-level 'make', after loplugin has already been used in compilation. But it can be run manually (e.g., 'make solenv') when making changes to loplugin during development. Change-Id: I01e12fb84887d264ac03ef2484807458c2075af4
Diffstat (limited to 'solenv/gbuild/CompilerTest.mk')
-rw-r--r--solenv/gbuild/CompilerTest.mk46
1 files changed, 46 insertions, 0 deletions
diff --git a/solenv/gbuild/CompilerTest.mk b/solenv/gbuild/CompilerTest.mk
new file mode 100644
index 000000000000..674ec9389d08
--- /dev/null
+++ b/solenv/gbuild/CompilerTest.mk
@@ -0,0 +1,46 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+define gb_CompilerTest_CompilerTest
+$(call gb_CompilerTest__CompilerTest_impl,$(1),$(call gb_CompilerTest_get_linktarget,$(1)))
+
+endef
+
+# call gb_CompilerTest__CompilerTest_impl,compilertest,linktarget
+define gb_CompilerTest__CompilerTest_impl
+$(call gb_LinkTarget_LinkTarget,$(2),CompilerTest_$(1),NONE)
+$(call gb_LinkTarget_get_target,$(2)): COMPILER_TEST := $(true)
+$(call gb_LinkTarget_get_target,$(2)): ENABLE_WERROR := $(true)
+$(call gb_CompilerTest_get_target,$(1)): $(call gb_LinkTarget_get_target,$(2))
+$(call gb_CompilerTest_get_clean_target,$(1)): $(call gb_LinkTarget_get_clean_target,$(2))
+$$(eval $$(call gb_Module_register_target,$(call gb_CompilerTest_get_target,$(1)),$(call gb_CompilerTest_get_clean_target,$(1))))
+$(call gb_Helper_make_userfriendly_targets,$(1),CompilerTest)
+
+endef
+
+define gb_CompilerTest__forward_to_Linktarget
+gb_CompilerTest_$(1) = $$(call gb_LinkTarget_$(1),$$(call gb_CompilerTest_get_linktarget,$$(1)),$$(2),$$(3),CompilerTest_$$(1))
+
+endef
+
+$(eval $(foreach method, \
+ add_cobject \
+ add_cobjects \
+ add_cxxobject \
+ add_cxxobjects \
+ add_exception_objects \
+ add_objcobject \
+ add_objcobjects \
+ add_objcxxobject \
+ add_objcxxobjects \
+, \
+ $(call gb_CompilerTest__forward_to_Linktarget,$(method)) \
+))
+
+# vim: set noet sw=4 ts=4: