bump product version to 4.2.0.1
[LibreOffice.git] / solenv / gbuild / CppunitTest.mk
blob7ebfc07c26f53f35f88870cdf84b753afd5ccf7c
1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 # CppunitTest class
23 # $(1): "Cppunit" or "Python"
24 # $(2): the name of the unit test that failed
25 define gb_UNIT_FAILED_MSG
26 printf '\nError: a unit test failed, please do one of:\n\nexport DEBUGCPPUNIT=TRUE # for exception catching\nexport CPPUNITTRACE="gdb --args" # for interactive debugging on linux\nexport CPPUNITTRACE="\"[full path to devenv.exe]\" /debugexe" # for interactive debugging in Visual Studio\nexport VALGRIND=memcheck # for memory checking\n\nand retry using: make %sTest_%s\n\n' $(1) $(2)
27 endef
29 ifeq ($(strip $(DEBUGCPPUNIT)),TRUE)
30 gb_CppunitTest_GDBTRACE := gdb -nx -ex "add-auto-load-safe-path $(INSTDIR)" --command=$(SRCDIR)/solenv/bin/gdbtrycatchtrace-stdout -return-child-result --args
31 else ifneq ($(strip $(CPPUNITTRACE)),)
32 gb_CppunitTest_GDBTRACE := $(CPPUNITTRACE)
33 gb_CppunitTest__interactive := $(true)
34 endif
36 ifneq ($(strip $(VALGRIND)),)
37 gb_CppunitTest_VALGRINDTOOL := valgrind --tool=$(VALGRIND) --num-callers=50 --error-exitcode=1 --trace-children=yes --leak-check=no
38 ifeq ($(strip $(VALGRIND)),memcheck)
39 G_SLICE := always-malloc
40 GLIBCXX_FORCE_NEW := 1
41 endif
42 endif
44 # defined by platform
45 # gb_CppunitTest_TARGETTYPE
46 # gb_CppunitTest_get_filename
47 # DBGSV_ERROR_OUT => in non-product builds, ensure that tools-based assertions do not pop up as message box, but are routed to the shell
48 gb_CppunitTest_CPPTESTDEPS := $(call gb_Executable_get_runtime_dependencies,cppunittester)
49 gb_CppunitTest_CPPTESTCOMMAND := $(call gb_Executable_get_target_for_build,cppunittester)
51 define gb_CppunitTest__make_args
52 $(HEADLESS) \
53 "-env:BRAND_BASE_DIR=$(call gb_Helper_make_url,$(INSTROOT))" \
54 "-env:BRAND_SHARE_SUBDIR=share" \
55 $(if $(URE),\
56 $(if $(strip $(CONFIGURATION_LAYERS)),\
57 "-env:CONFIGURATION_LAYERS=$(strip $(CONFIGURATION_LAYERS))") \
58 $(if $(strip $(UNO_TYPES)),\
59 "-env:UNO_TYPES=$(foreach item,$(UNO_TYPES),$(call gb_Helper_make_url,$(item)))") \
60 $(if $(strip $(UNO_SERVICES)),\
61 "-env:UNO_SERVICES=$(foreach item,$(UNO_SERVICES),$(call gb_Helper_make_url,$(item)))") \
62 -env:URE_INTERNAL_LIB_DIR=$(call gb_Helper_make_url,$(INSTROOT)/$(LIBO_URE_LIB_FOLDER)) \
63 -env:LO_LIB_DIR=$(call gb_Helper_make_url,$(INSTROOT)/$(LIBO_LIB_FOLDER)) \
64 -env:LO_JAVA_DIR=$(call gb_Helper_make_url,$(INSTROOT)/$(LIBO_SHARE_JAVA_FOLDER)) \
65 --protector $(call gb_Library_get_target,unoexceptionprotector) unoexceptionprotector \
66 --protector $(call gb_Library_get_target,unobootstrapprotector) unobootstrapprotector \
67 ) $(ARGS)
68 endef
70 .PHONY : $(call gb_CppunitTest_get_clean_target,%)
71 $(call gb_CppunitTest_get_clean_target,%) :
72 $(call gb_Helper_abbreviate_dirs,\
73 rm -f $(call gb_CppunitTest_get_target,$*) $(call gb_CppunitTest_get_target,$*).log)
75 .PHONY : $(call gb_CppunitTest_get_target,%)
76 $(call gb_CppunitTest_get_target,%) :| $(gb_CppunitTest_CPPTESTDEPS)
77 $(call gb_Output_announce,$*,$(true),CUT,2)
78 $(call gb_Helper_abbreviate_dirs,\
79 mkdir -p $(dir $@) && \
80 $(if $(gb_CppunitTest__interactive),, \
81 $(if $(value gb_CppunitTest_postprocess), \
82 rm -fr $@.core && mkdir $@.core && cd $@.core &&)) \
83 ($(gb_CppunitTest_CPPTESTPRECOMMAND) \
84 $(if $(G_SLICE),G_SLICE=$(G_SLICE)) \
85 $(if $(GLIBCXX_FORCE_NEW),GLIBCXX_FORCE_NEW=$(GLIBCXX_FORCE_NEW)) \
86 $(if $(DBGSV_ERROR_OUT),DBGSV_ERROR_OUT=$(DBGSV_ERROR_OUT)) \
87 DISABLE_SAL_DBGBOX=t \
88 $(if $(SAL_DIAGNOSE_ABORT),SAL_DIAGNOSE_ABORT=$(SAL_DIAGNOSE_ABORT)) \
89 $(ICECREAM_RUN) $(gb_CppunitTest_GDBTRACE) $(gb_CppunitTest_VALGRINDTOOL) $(gb_CppunitTest_CPPTESTCOMMAND) \
90 $(call gb_LinkTarget_get_target,$(call gb_CppunitTest_get_linktarget,$*)) \
91 $(call gb_CppunitTest__make_args) \
92 $(if $(gb_CppunitTest__interactive),, \
93 > $@.log 2>&1 \
94 || (RET=$$? \
95 $(if $(value gb_CppunitTest_postprocess), \
96 && $(call gb_CppunitTest_postprocess,$(gb_CppunitTest_CPPTESTCOMMAND),$@.core,$$RET) >> $@.log 2>&1) \
97 && cat $@.log && $(call gb_UNIT_FAILED_MSG,Cppunit,$*) \
98 && false))))
100 define gb_CppunitTest_CppunitTest
101 $(call gb_CppunitTest__CppunitTest_impl,$(1),$(call gb_CppunitTest_get_linktarget,$(1)))
103 endef
105 # call gb_CppunitTest__CppunitTest_impl,cppunittest,linktarget
106 define gb_CppunitTest__CppunitTest_impl
107 $(call gb_LinkTarget_LinkTarget,$(2),CppunitTest_$(1),NONE)
108 $(call gb_LinkTarget_set_targettype,$(2),CppunitTest)
109 $(call gb_LinkTarget_add_libs,$(2),$(gb_STDLIBS))
110 $(call gb_LinkTarget_add_defs,$(2),\
111 $(gb_CppunitTest_DEFS) \
113 $(call gb_LinkTarget_use_external,$(2),cppunit)
114 $(call gb_LinkTarget_set_include,$(2),\
115 $$(INCLUDE) \
116 $(filter -I%,$(CPPUNIT_CFLAGS)) \
118 $(call gb_LinkTarget_add_defs,$(2), \
119 $(filter-out -I%,$(CPPUNIT_CFLAGS)) \
120 -DCPPUNIT_PLUGIN_EXPORT='extern "C" SAL_DLLPUBLIC_EXPORT' \
122 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_LinkTarget_get_target,$(2))
123 $(call gb_CppunitTest_get_clean_target,$(1)) : $(call gb_LinkTarget_get_clean_target,$(2))
124 $(call gb_CppunitTest_CppunitTest_platform,$(1),$(2),$(gb_CppunitTest_DLLDIR)/$(call gb_CppunitTest_get_ilibfilename,$(1)))
125 $(call gb_CppunitTest_get_target,$(1)) : ARGS :=
126 $(call gb_CppunitTest_get_target,$(1)) : CONFIGURATION_LAYERS :=
127 $(call gb_CppunitTest_get_target,$(1)) : URE := $(false)
128 $(call gb_CppunitTest_get_target,$(1)) : UNO_SERVICES :=
129 $(call gb_CppunitTest_get_target,$(1)) : UNO_TYPES :=
130 $(call gb_CppunitTest_get_target,$(1)) : DBGSV_ERROR_OUT := shell
131 $(call gb_CppunitTest_get_target,$(1)) : SAL_DIAGNOSE_ABORT :=
132 $(call gb_CppunitTest_get_target,$(1)) : HEADLESS := --headless
133 $$(eval $$(call gb_Module_register_target,$(call gb_CppunitTest_get_target,$(1)),$(call gb_CppunitTest_get_clean_target,$(1))))
134 $(call gb_Helper_make_userfriendly_targets,$(1),CppunitTest)
136 endef
138 define gb_CppunitTest_abort_on_assertion
139 $(call gb_CppunitTest_get_target,$(1)) : DBGSV_ERROR_OUT := abort
140 $(call gb_CppunitTest_get_target,$(1)) : SAL_DIAGNOSE_ABORT := TRUE
142 endef
144 # Add additional command line arguments for the test.
146 # You should practically never need to use this, as there are special
147 # functions for adding many commonly used arguments.
148 define gb_CppunitTest_add_arguments
149 $(call gb_CppunitTest_get_target,$(1)) : ARGS += $(2)
151 endef
153 define gb_CppunitTest_use_ure
154 $(call gb_CppunitTest_use_rdb,$(1),ure/services)
155 $(call gb_CppunitTest_get_target,$(1)) : URE := $(true)
156 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Library_get_target,$(gb_CPPU_ENV)_uno)
157 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Library_get_target,affine_uno)
158 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Library_get_target,unobootstrapprotector)
159 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Library_get_target,unoexceptionprotector)
160 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Package_get_target,cppuhelper_unorc)
162 endef
164 define gb_CppunitTest__use_api
165 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_UnoApi_get_target,$(2))
166 $(call gb_CppunitTest_get_target,$(1)) : UNO_TYPES += $(call gb_UnoApi_get_target,$(2))
168 endef
170 define gb_CppunitTest_use_api
171 $(call gb_LinkTarget_use_api,$(call gb_CppunitTest_get_linktarget,$(1)),$(2))
172 $(foreach rdb,$(2),$(call gb_CppunitTest__use_api,$(1),$(rdb)))
174 endef
176 define gb_CppunitTest_use_udk_api
177 $(call gb_CppunitTest_use_api,$(1),udkapi)
179 endef
181 define gb_CppunitTest_use_sdk_api
182 $(call gb_CppunitTest_use_api,$(1),udkapi offapi)
184 endef
186 define gb_CppunitTest_use_rdb
187 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Rdb_get_target_for_build,$(2))
188 $(call gb_CppunitTest_get_target,$(1)) : UNO_SERVICES += $(call gb_Rdb_get_target_for_build,$(2))
190 endef
192 define gb_CppunitTest_use_rdbs
193 $(foreach rdb,$(2),$(call gb_CppunitTest_use_rdb,$(1),$(rdb)))
195 endef
197 define gb_CppunitTest_use_component
198 $(call gb_CppunitTest_get_target,$(1)) : \
199 $(call gb_ComponentTarget_get_target,$(2))
200 $(call gb_CppunitTest_get_target,$(1)) : \
201 UNO_SERVICES += $(call gb_ComponentTarget_get_target,$(2))
203 endef
205 # Given a list of component files, filter out those corresponding
206 # to libraries not built in this configuration.
207 define gb_CppunitTest__filter_not_built_components
208 $(filter-out \
209 $(if $(filter SCRIPTING,$(BUILD_TYPE)),, \
210 basic/util/sb \
211 sw/util/vbaswobj \
212 scripting/source/basprov/basprov \
213 scripting/util/scriptframe) \
214 $(if $(filter DBCONNECTIVITY,$(BUILD_TYPE)),, \
215 dbaccess/util/dba \
216 forms/util/frm),$(1))
217 endef
219 define gb_CppunitTest_use_components
220 $(foreach component,$(call gb_CppunitTest__filter_not_built_components,$(2)),$(call gb_CppunitTest_use_component,$(1),$(component)))
222 endef
224 define gb_CppunitTest__use_configuration
225 $(call gb_CppunitTest_get_target,$(1)) : CONFIGURATION_LAYERS += $(2):$(call gb_Helper_make_url,$(3))
227 endef
229 # Use standard configuration.
230 define gb_CppunitTest_use_configuration
231 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Package_get_target,postprocess_registry)
232 $(call gb_CppunitTest__use_configuration,$(1),xcsxcu,$(INSTROOT)/$(LIBO_SHARE_FOLDER)/registry)
234 endef
236 define gb_CppunitTest_unset_headless
237 $(call gb_CppunitTest_get_target,$(1)) : HEADLESS=
239 endef
241 # Use configuration in $(WORKDIR)/unittest/registry.
242 define gb_CppunitTest_use_unittest_configuration
243 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Package_get_target,test_unittest)
244 $(call gb_CppunitTest__use_configuration,$(1),xcsxcu,$(WORKDIR)/unittest/registry)
246 endef
248 define gb_CppunitTest_use_executable
249 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Executable_get_target,$(2))
251 endef
253 define gb_CppunitTest__forward_to_Linktarget
254 gb_CppunitTest_$(1) = $$(call gb_LinkTarget_$(1),$$(call gb_CppunitTest_get_linktarget,$$(1)),$$(2),$$(3),CppunitTest_$$(1))
256 endef
258 $(eval $(foreach method,\
259 add_cobject \
260 add_cobjects \
261 add_cxxobject \
262 add_cxxobjects \
263 add_exception_objects \
264 use_executable_objects \
265 use_library_objects \
266 use_libraries \
267 use_static_libraries \
268 add_objcobject \
269 add_objcobjects \
270 add_objcxxobject \
271 add_objcxxobjects \
272 add_asmobject \
273 add_asmobjects \
274 use_package \
275 use_packages \
276 set_precompiled_header \
277 add_sdi_headers \
278 add_cflags \
279 set_cflags \
280 add_cxxflags \
281 set_yaccflags \
282 add_objcflags \
283 add_objcxxflags \
284 add_defs \
285 set_include \
286 add_ldflags \
287 set_ldflags \
288 add_libs \
289 disable_standard_system_libs \
290 use_system_darwin_frameworks \
291 use_system_win32_libs \
292 use_internal_api \
293 use_internal_bootstrap_api \
294 use_internal_comprehensive_api \
295 set_library_path_flags \
296 use_external \
297 use_externals \
298 use_custom_headers \
299 set_visibility_default \
301 $(call gb_CppunitTest__forward_to_Linktarget,$(method))\
304 # vim: set noet sw=4: