summaryrefslogtreecommitdiff
path: root/solenv
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
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')
-rw-r--r--solenv/CompilerTest_compilerplugins_clang.mk16
-rw-r--r--solenv/Module_solenv.mk6
-rw-r--r--solenv/gbuild/CompilerTest.mk46
-rw-r--r--solenv/gbuild/LinkTarget.mk9
-rw-r--r--solenv/gbuild/TargetLocations.mk13
-rw-r--r--solenv/gbuild/gbuild.mk1
-rw-r--r--solenv/gbuild/platform/com_GCC_class.mk5
-rw-r--r--solenv/gbuild/platform/com_GCC_defs.mk2
8 files changed, 91 insertions, 7 deletions
diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk
new file mode 100644
index 000000000000..29fb11a14b21
--- /dev/null
+++ b/solenv/CompilerTest_compilerplugins_clang.mk
@@ -0,0 +1,16 @@
+# -*- 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/.
+#
+
+$(eval $(call gb_CompilerTest_CompilerTest,compilerplugins_clang))
+
+$(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
+ compilerplugins/clang/test/salbool \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/solenv/Module_solenv.mk b/solenv/Module_solenv.mk
index 229ee5854425..127007eae676 100644
--- a/solenv/Module_solenv.mk
+++ b/solenv/Module_solenv.mk
@@ -33,4 +33,10 @@ endif
endif
endif
+ifneq ($(COMPILER_PLUGINS),)
+$(eval $(call gb_Module_add_check_targets,solenv, \
+ CompilerTest_compilerplugins_clang \
+))
+endif
+
# vim: set shiftwidth=4 tabstop=4 noexpandtab:
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:
diff --git a/solenv/gbuild/LinkTarget.mk b/solenv/gbuild/LinkTarget.mk
index 4e2c2bff5b7c..f54ace62c1d8 100644
--- a/solenv/gbuild/LinkTarget.mk
+++ b/solenv/gbuild/LinkTarget.mk
@@ -135,7 +135,7 @@ $(call gb_CObject_get_target,%) : $(call gb_CObject_get_source,$(SRCDIR),%) $(gb
$(call gb_CObject__tool_command,$*,$<)
else
$(call gb_CObject_get_target,%) : $(call gb_CObject_get_source,$(SRCDIR),%)
- $(call gb_Output_announce,$*.c,$(true),C ,3)
+ $(call gb_Output_announce,$*.c,$(true),$(if $(COMPILER_TEST),C? ,C ),3)
$(call gb_CObject__command_pattern,$@,$(T_CFLAGS) $(T_CFLAGS_APPEND),$<,$(call gb_CObject_get_dep_target,$*),$(COMPILER_PLUGINS))
endif
@@ -186,7 +186,7 @@ $(call gb_CxxObject_get_target,%) : $(call gb_CxxObject_get_source,$(SRCDIR),%)
$(call gb_CxxObject__tool_command,$*,$<)
else
$(call gb_CxxObject_get_target,%) : $(call gb_CxxObject_get_source,$(SRCDIR),%)
- $(call gb_Output_announce,$*.cxx,$(true),CXX,3)
+ $(call gb_Output_announce,$*.cxx,$(true),$(if $(COMPILER_TEST),C??,CXX),3)
$(eval $(gb_CxxObject__set_pchflags))
$(call gb_CObject__command_pattern,$@,$(T_CXXFLAGS) $(T_CXXFLAGS_APPEND),$<,$(call gb_CxxObject_get_dep_target,$*),$(COMPILER_PLUGINS))
endif
@@ -320,7 +320,7 @@ $(call gb_ObjCxxObject_get_target,%) : $(call gb_ObjCxxObject_get_source,$(SRCDI
$(call gb_ObjCxxObject__tool_command,$*,$<)
else
$(call gb_ObjCxxObject_get_target,%) : $(call gb_ObjCxxObject_get_source,$(SRCDIR),%)
- $(call gb_Output_announce,$*.mm,$(true),OCX,3)
+ $(call gb_Output_announce,$*.mm,$(true),$(if $(COMPILER_TEST),O?X,OCX),3)
$(call gb_CObject__command_pattern,$@,$(T_OBJCXXFLAGS) $(T_OBJCXXFLAGS_APPEND),$<,$(call gb_ObjCxxObject_get_dep_target,$*),$(COMPILER_PLUGINS))
endif
@@ -347,7 +347,7 @@ $(call gb_ObjCObject_get_target,%) : $(call gb_ObjCObject_get_source,$(SRCDIR),%
$(call gb_ObjCObject__tool_command,$*,$<)
else
$(call gb_ObjCObject_get_target,%) : $(call gb_ObjCObject_get_source,$(SRCDIR),%)
- $(call gb_Output_announce,$*.m,$(true),OCC,3)
+ $(call gb_Output_announce,$*.m,$(true),$(if $(COMPILER_TEST),O?C,OCC),3)
$(call gb_CObject__command_pattern,$@,$(T_OBJCFLAGS) $(T_OBJCFLAGS_APPEND),$<,$(call gb_ObjCObject_get_dep_target,$*),$(COMPILER_PLUGINS))
endif
@@ -614,6 +614,7 @@ $(call gb_LinkTarget_get_target,$(1)) : WARNINGS_NOT_ERRORS :=
$(call gb_LinkTarget_get_target,$(1)) : PLUGIN_WARNINGS_AS_ERRORS :=
$(call gb_LinkTarget_get_target,$(1)) : EXTERNAL_CODE :=
$(call gb_LinkTarget_get_target,$(1)) : SOVERSIONSCRIPT :=
+$(call gb_LinkTarget_get_target,$(1)) : COMPILER_TEST :=
ifeq ($(gb_FULLDEPS),$(true))
ifeq (depcache:,$(filter depcache,$(.FEATURES)):$(gb_PARTIAL_BUILD))
diff --git a/solenv/gbuild/TargetLocations.mk b/solenv/gbuild/TargetLocations.mk
index 3cf0cdf6e606..78ed59c07835 100644
--- a/solenv/gbuild/TargetLocations.mk
+++ b/solenv/gbuild/TargetLocations.mk
@@ -44,6 +44,7 @@ gb_CliAssemblyTarget_get_target = $(WORKDIR)/CliAssemblyTarget/$(1).done
gb_CliAssemblyTarget_get_assembly_target = $(WORKDIR)/CliAssemblyTarget/$(1)$(gb_CliAssemblyTarget_POLICYEXT)
gb_CliConfigTarget_get_target = $(WORKDIR)/CliConfigTarget/$(1).config
gb_CliNativeLibrary_get_preparation_target = $(WORKDIR)/CliNativeLibraryTarget/$(1).prepare
+gb_CompilerTest_get_target = $(WORKDIR)/CompilerTest/$(1)
gb_ComponentTarget_get_target = $(WORKDIR)/ComponentTarget/$(1).component
gb_ComponentTarget_get_target_for_build = $(WORKDIR_FOR_BUILD)/ComponentTarget/$(1).component
gb_Configuration_get_preparation_target = $(WORKDIR)/Configuration/$(1).prepared
@@ -233,6 +234,7 @@ $(eval $(call gb_Helper_make_clean_targets,\
CliLibrary \
CliNativeLibrary \
CliUnoApi \
+ CompilerTest \
ComponentTarget \
CustomPackage \
DescriptionTranslateTarget \
@@ -411,6 +413,17 @@ define gb_CppunitTest_get_linktarget
$(call gb_CppunitTest__get_workdir_linktargetname,$(1))<>$(call gb_CppunitTest__get_linktarget_target,$(1))
endef
+define gb_CompilerTest__get_workdir_linktargetname
+CompilerTest/$(1)
+endef
+define gb_CompilerTest__get_linktarget_target
+$(WORKDIR)/LinkTarget/$(call gb_CompilerTest__get_workdir_linktargetname,$(1))
+endef
+# this returns a tuple of both the linktargetname, and the target file
+define gb_CompilerTest_get_linktarget
+$(call gb_CompilerTest__get_workdir_linktargetname,$(1))<>$(call gb_CompilerTest__get_linktarget_target,$(1))
+endef
+
# static members declared here because they are used globally
gb_StaticLibrary_WORKDIR = $(WORKDIR)/LinkTarget/StaticLibrary
diff --git a/solenv/gbuild/gbuild.mk b/solenv/gbuild/gbuild.mk
index f98ce8185899..f05310706742 100644
--- a/solenv/gbuild/gbuild.mk
+++ b/solenv/gbuild/gbuild.mk
@@ -313,6 +313,7 @@ include $(foreach class, \
AutoInstall \
PackageSet \
GeneratedPackage \
+ CompilerTest \
,$(GBUILDDIR)/$(class).mk)
$(eval $(call gb_Helper_process_executable_registrations))
diff --git a/solenv/gbuild/platform/com_GCC_class.mk b/solenv/gbuild/platform/com_GCC_class.mk
index 4d0378bec617..3967e200981f 100644
--- a/solenv/gbuild/platform/com_GCC_class.mk
+++ b/solenv/gbuild/platform/com_GCC_class.mk
@@ -54,15 +54,16 @@ $(call gb_Helper_abbreviate_dirs,\
$(if $(VISIBILITY),,$(gb_VISIBILITY_FLAGS)) \
$(if $(WARNINGS_NOT_ERRORS),$(if $(ENABLE_WERROR),$(if $(PLUGIN_WARNINGS_AS_ERRORS),$(gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS))),$(gb_CFLAGS_WERROR)) \
$(if $(5),$(gb_COMPILER_PLUGINS)) \
+ $(if $(COMPILER_TEST),-fsyntax-only -Xclang -verify) \
$(2) \
$(if $(EXTERNAL_CODE),$(gb_CXXFLAGS_Wundef),$(gb_DEFS_INTERNAL)) \
-c $(3) \
-o $(1) \
- $(call gb_cxx_dep_generation_options,$(1),$(4)) \
+ $(if $(COMPILER_TEST),,$(call gb_cxx_dep_generation_options,$(1),$(4))) \
-I$(dir $(3)) \
$(INCLUDE) \
$(PCHFLAGS) \
- $(call gb_cxx_dep_copy,$(4)) \
+ $(if $(COMPILER_TEST),,$(call gb_cxx_dep_copy,$(4))) \
)
endef
diff --git a/solenv/gbuild/platform/com_GCC_defs.mk b/solenv/gbuild/platform/com_GCC_defs.mk
index 2d6dc73d4a6f..6b697fc9461c 100644
--- a/solenv/gbuild/platform/com_GCC_defs.mk
+++ b/solenv/gbuild/platform/com_GCC_defs.mk
@@ -126,7 +126,7 @@ gb_CXXFLAGS_COMMON += -fpch-preprocess -Winvalid-pch
endif
endif
-gb_CFLAGS_WERROR := $(if $(ENABLE_WERROR),-Werror)
+gb_CFLAGS_WERROR = $(if $(ENABLE_WERROR),-Werror)
# This is the default in non-C++11 mode
ifeq ($(COM_IS_CLANG),TRUE)