bump product version to 4.1.6.2
[LibreOffice.git] / solenv / gbuild / CppunitTest.mk
blobbf209d676e247e9c55459019c01b0c9f7b10f38c
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 GDBCPPUNITTRACE="gdb --args" # for interactive debugging\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 $(OUTDIR)/lib" --command=$(SOLARENV)/bin/gdbtrycatchtrace-stdout -return-child-result --args
31 else ifneq ($(strip $(GDBCPPUNITTRACE)),)
32 gb_CppunitTest_GDBTRACE := $(GDBCPPUNITTRACE)
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,cppunit/cppunittester)
49 gb_CppunitTest_CPPTESTCOMMAND := $(call gb_Executable_get_target_for_build,cppunit/cppunittester)
51 gb_CppunitTest__get_linktargetname = CppunitTest/$(call gb_CppunitTest_get_filename,$(1))
53 define gb_CppunitTest__make_args
54 --headless \
55 "-env:BRAND_BASE_DIR=$(call gb_Helper_make_url,$(OUTDIR)/unittest/install)" \
56 $(if $(URE),\
57 $(if $(strip $(CONFIGURATION_LAYERS)),\
58 "-env:CONFIGURATION_LAYERS=$(strip $(CONFIGURATION_LAYERS))") \
59 $(if $(strip $(UNO_TYPES)),\
60 "-env:UNO_TYPES=$(foreach item,$(UNO_TYPES),$(call gb_Helper_make_url,$(item)))") \
61 $(if $(strip $(UNO_SERVICES)),\
62 "-env:UNO_SERVICES=$(foreach item,$(UNO_SERVICES),$(call gb_Helper_make_url,$(item)))") \
63 $(foreach dir,URE_INTERNAL_LIB_DIR LO_LIB_DIR,\
64 -env:$(dir)=$(call gb_Helper_make_url,$(gb_CppunitTest_LIBDIR))) \
65 --protector unoexceptionprotector$(gb_Library_DLLEXT) unoexceptionprotector \
66 --protector unobootstrapprotector$(gb_Library_DLLEXT) 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,CppunitTest/$(call gb_CppunitTest_get_libfilename,$*)) \
91 $(call gb_CppunitTest__make_args) \
92 $(if $(gb_CppunitTest__interactive),, \
93 > $@.log 2>&1 \
94 || (RET=$$? && cat $@.log && $(call gb_UNIT_FAILED_MSG,Cppunit,$*) \
95 $(if $(value gb_CppunitTest_postprocess), \
96 && $(call gb_CppunitTest_postprocess,$(gb_CppunitTest_CPPTESTCOMMAND),$@.core,$$RET)) \
97 && false))))
99 define gb_CppunitTest_CppunitTest
100 $(call gb_CppunitTest__CppunitTest_impl,$(1),$(call gb_CppunitTest__get_linktargetname,$(1)))
102 endef
104 define gb_CppunitTest__CppunitTest_impl
105 $(call gb_LinkTarget_LinkTarget,$(2),CppunitTest_$(1))
106 $(call gb_LinkTarget_set_targettype,$(2),CppunitTest)
107 $(call gb_LinkTarget_add_libs,$(2),$(gb_STDLIBS))
108 $(call gb_LinkTarget_add_defs,$(2),\
109 $(gb_CppunitTest_DEFS) \
111 $(call gb_LinkTarget_use_external,$(2),cppunit)
112 $(call gb_LinkTarget_set_include,$(2),\
113 $$(INCLUDE) \
114 $(filter -I%,$(CPPUNIT_CFLAGS)) \
116 $(call gb_LinkTarget_add_defs,$(2), \
117 $(filter-out -I%,$(CPPUNIT_CFLAGS)) \
118 -DCPPUNIT_PLUGIN_EXPORT='extern "C" SAL_DLLPUBLIC_EXPORT' \
120 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_LinkTarget_get_target,$(2))
121 $(call gb_CppunitTest_get_clean_target,$(1)) : $(call gb_LinkTarget_get_clean_target,$(2))
122 $(call gb_CppunitTest_CppunitTest_platform,$(1),$(2),$(gb_CppunitTest_DLLDIR)/$(call gb_CppunitTest_get_libfilename,$(1)))
123 $(call gb_CppunitTest_get_target,$(1)) : ARGS :=
124 $(call gb_CppunitTest_get_target,$(1)) : CONFIGURATION_LAYERS :=
125 $(call gb_CppunitTest_get_target,$(1)) : URE := $(false)
126 $(call gb_CppunitTest_get_target,$(1)) : UNO_SERVICES :=
127 $(call gb_CppunitTest_get_target,$(1)) : UNO_TYPES :=
128 $(call gb_CppunitTest_get_target,$(1)) : DBGSV_ERROR_OUT := shell
129 $(call gb_CppunitTest_get_target,$(1)) : SAL_DIAGNOSE_ABORT :=
130 $$(eval $$(call gb_Module_register_target,$(call gb_CppunitTest_get_target,$(1)),$(call gb_CppunitTest_get_clean_target,$(1))))
131 $(call gb_Helper_make_userfriendly_targets,$(1),CppunitTest)
133 endef
135 define gb_CppunitTest_abort_on_assertion
136 $(call gb_CppunitTest_get_target,$(1)) : DBGSV_ERROR_OUT := abort
137 $(call gb_CppunitTest_get_target,$(1)) : SAL_DIAGNOSE_ABORT := TRUE
139 endef
141 define gb_CppunitTest_set_args
142 $$(call gb_Output_error,gb_CppunitTest_set_args: use gb_CppunitTest_add_arguments instead.))
143 endef
145 # Add additional command line arguments for the test.
147 # You should practically never need to use this, as there are special
148 # functions for adding many commonly used arguments.
149 define gb_CppunitTest_add_arguments
150 $(call gb_CppunitTest_get_target,$(1)) : ARGS += $(2)
152 endef
154 define gb_CppunitTest_uses_ure
155 $$(call gb_Output_error,gb_CppunitTest_uses_ure: use gb_CppunitTest_use_ure instead.))
156 endef
158 define gb_CppunitTest_use_ure
159 $(call gb_CppunitTest_use_rdb,$(1),ure/services)
160 $(call gb_CppunitTest_get_target,$(1)) : URE := $(true)
161 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Library_get_target,$(gb_CPPU_ENV)_uno)
162 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Library_get_target,unobootstrapprotector)
163 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Library_get_target,unoexceptionprotector)
164 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Package_get_target,cppuhelper_unorc)
166 endef
168 define gb_CppunitTest_add_type_rdb
169 $$(call gb_Output_error,\
170 gb_CppunitTest_add_type_rdb: use gb_CppunitTest_use_api instead.)
171 endef
173 define gb_CppunitTest_use_type_rdb
174 $$(call gb_Output_error,\
175 gb_CppunitTest_use_type_rdb: use gb_CppunitTest_use_api instead.)
176 endef
178 define gb_CppunitTest__use_api
179 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_UnoApi_get_target,$(2))
180 $(call gb_CppunitTest_get_target,$(1)) : UNO_TYPES += $(call gb_UnoApi_get_target,$(2))
182 endef
184 define gb_CppunitTest_add_type_rdbs
185 $$(call gb_Output_error,\
186 gb_CppunitTest_add_type_rdbs: use gb_CppunitTest_use_api instead.)
187 endef
189 define gb_CppunitTest_use_type_rdbs
190 $$(call gb_Output_error,\
191 gb_CppunitTest_use_type_rdbs: use gb_CppunitTest_use_api instead.)
192 endef
194 define gb_CppunitTest_use_api
195 $(call gb_LinkTarget_use_api,$(call gb_CppunitTest__get_linktargetname,$(1)),$(2))
196 $(foreach rdb,$(2),$(call gb_CppunitTest__use_api,$(1),$(rdb)))
198 endef
200 define gb_CppunitTest_use_udk_api
201 $(call gb_CppunitTest_use_api,$(1),udkapi)
203 endef
205 define gb_CppunitTest_use_sdk_api
206 $(call gb_CppunitTest_use_api,$(1),udkapi offapi)
208 endef
210 define gb_CppunitTest_add_service_rdb
211 $$(call gb_Output_error,\
212 gb_CppunitTest_add_service_rdb: use gb_CppunitTest_use_rdb instead.)
213 endef
215 define gb_CppunitTest_use_service_rdb
216 $$(call gb_Output_error,gb_CppunitTest_use_service_rdb: use gb_CppunitTest_use_rdb instead.))
217 endef
219 define gb_CppunitTest_use_rdb
220 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Rdb_get_outdir_target,$(2))
221 $(call gb_CppunitTest_get_target,$(1)) : UNO_SERVICES += $(call gb_Rdb_get_outdir_target,$(2))
223 endef
225 define gb_CppunitTest_add_service_rdbs
226 $$(call gb_Output_error,\
227 gb_CppunitTest_add_service_rdbs: use gb_CppunitTest_use_rdbs instead.)
228 endef
230 define gb_CppunitTest_use_service_rdbs
231 $$(call gb_Output_error,gb_CppunitTest_use_service_rdbs: use gb_CppunitTest_use_rdbs instead.))
232 endef
234 define gb_CppunitTest_use_rdbs
235 $(foreach rdb,$(2),$(call gb_CppunitTest_use_rdb,$(1),$(rdb)))
237 endef
239 define gb_CppunitTest_add_component
240 $$(call gb_Output_error,\
241 gb_CppunitTest_add_component: use gb_CppunitTest_use_component instead.)
242 endef
244 define gb_CppunitTest_use_component
245 $(call gb_CppunitTest_get_target,$(1)) : \
246 $(call gb_ComponentTarget_get_outdir_target,$(2))
247 $(call gb_CppunitTest_get_target,$(1)) : \
248 UNO_SERVICES += $(call gb_ComponentTarget_get_outdir_target,$(2))
250 endef
252 # Given a list of component files, filter out those corresponding
253 # to libraries not built in this configuration.
254 define gb_CppunitTest__filter_not_built_components
255 $(filter-out \
256 $(if $(filter SCRIPTING,$(BUILD_TYPE)),, \
257 basic/util/sb \
258 sw/util/vbaswobj \
259 scripting/source/basprov/basprov \
260 scripting/util/scriptframe) \
261 $(if $(filter DBCONNECTIVITY,$(BUILD_TYPE)),, \
262 dbaccess/util/dba \
263 forms/util/frm),$(1))
264 endef
266 define gb_CppunitTest_add_components
267 $$(call gb_Output_error,\
268 gb_CppunitTest_add_components: use gb_CppunitTest_use_components instead.)
269 endef
271 define gb_CppunitTest_use_components
272 $(foreach component,$(call gb_CppunitTest__filter_not_built_components,$(2)),$(call gb_CppunitTest_use_component,$(1),$(component)))
274 endef
276 define gb_CppunitTest__use_configuration
277 $(call gb_CppunitTest_get_target,$(1)) : CONFIGURATION_LAYERS += $(2):$(call gb_Helper_make_url,$(3))
279 endef
281 # Use standard configuration.
282 define gb_CppunitTest_use_configuration
283 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Configuration_get_target,registry)
284 $(call gb_CppunitTest__use_configuration,$(1),xcsxcu,$(gb_Configuration_registry))
286 endef
288 # Use configuration for filters.
290 # Okay, this is not exactly true, because there may be configuration
291 # for more things than just filters in spool, but it is good enough.
292 define gb_CppunitTest_use_filter_configuration
293 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Configuration_get_target,fcfg_langpack)
294 $(call gb_CppunitTest__use_configuration,$(1),module,$(gb_Configuration_registry)/spool)
296 endef
298 define gb_CppunitTest_use_extra_configuration
299 $$(call gb_Output_error,gb_CppunitTest_use_extra_configuration: use gb_CppunitTest_use_unittest_configuration instead.))
300 endef
302 # Use configuration in $(OUTDIR)/unittest/registry.
303 define gb_CppunitTest_use_unittest_configuration
304 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Package_get_target,test_unittest)
305 $(call gb_CppunitTest__use_configuration,$(1),xcsxcu,$(OUTDIR)/unittest/registry)
307 endef
309 define gb_CppunitTest_use_executable
310 $(call gb_CppunitTest_get_target,$(1)) : \
311 $(call gb_CppunitTestFakeExecutable_get_target,$(2))
313 $(call gb_CppunitTest_get_clean_target,$(1)) : \
314 $(call gb_CppunitTestFakeExecutable_get_clean_target,$(2))
316 $(call gb_CppunitTestFakeExecutable_get_target,$(2)) : \
317 $(call gb_Executable_get_target,$(2))
318 $(call gb_Helper_abbreviate_dirs,mkdir -p $$(dir $$@) && cp $$< $$@)
320 .PHONY : $(call gb_CppunitTestFakeExecutable_get_clean_target,$(2))
321 $(call gb_CppunitTestFakeExecutable_get_clean_target,$(2)) :
322 $(call gb_Helper_abbreviate_dirs, \
323 rm -f $(call gb_CppunitTestFakeExecutable_get_target,$(2)))
325 endef
327 define gb_CppunitTest__forward_to_Linktarget
328 gb_CppunitTest_$(1) = $$(call gb_LinkTarget_$(1),$$(call gb_CppunitTest__get_linktargetname,$$(1)),$$(2),$$(3),CppunitTest_$$(1))
330 endef
332 $(eval $(foreach method,\
333 add_cobject \
334 add_cobjects \
335 add_cxxobject \
336 add_cxxobjects \
337 add_exception_objects \
338 add_executable_objects \
339 use_executable_objects \
340 add_library_objects \
341 use_library_objects \
342 add_linked_libs \
343 use_libraries \
344 add_linked_static_libs \
345 use_static_libraries \
346 add_noexception_objects \
347 add_objcobject \
348 add_objcobjects \
349 add_objcxxobject \
350 add_objcxxobjects \
351 add_asmobject \
352 add_asmobjects \
353 add_package_headers \
354 use_package \
355 use_packages \
356 set_precompiled_header \
357 add_precompiled_header \
358 add_sdi_headers \
359 add_cflags \
360 set_cflags \
361 add_cxxflags \
362 set_yaccflags \
363 add_objcflags \
364 add_objcxxflags \
365 add_defs \
366 set_defs \
367 set_include \
368 add_ldflags \
369 set_ldflags \
370 add_libs \
371 disable_standard_system_libs \
372 use_system_darwin_frameworks \
373 use_system_win32_libs \
374 use_internal_api \
375 use_internal_bootstrap_api \
376 use_internal_comprehensive_api \
377 set_library_path_flags \
378 set_objcflags \
379 set_objcxxflags \
380 use_external \
381 use_externals \
382 use_custom_headers \
383 set_visibility_default \
385 $(call gb_CppunitTest__forward_to_Linktarget,$(method))\
388 # vim: set noet sw=4: