Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / gbuild / PythonTest.mk
blob561ea648dc8d47b1374096bdc43ab3f0c0ff0488
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/.
10 # PythonTest class
12 ifeq ($(SYSTEM_PYTHON),)
13 gb_PythonTest_EXECUTABLE := $(gb_Python_INSTALLED_EXECUTABLE)
14 gb_PythonTest_EXECUTABLE_GDB := $(gb_Python_INSTALLED_EXECUTABLE_GDB)
15 ifeq ($(OS),MACOSX)
16 gb_PythonTest_DEPS := $(call gb_GeneratedPackage_get_target,python3)
17 else
18 gb_PythonTest_DEPS := $(call gb_Package_get_target,python3)
19 endif
20 gb_PythonTest_DEPS += $(if $(filter-out WNT,$(OS)),$(call gb_Package_get_target,python_shell))
21 else
22 gb_PythonTest_EXECUTABLE := $(PYTHON_FOR_BUILD)
23 gb_PythonTest_EXECUTABLE_GDB := $(PYTHON_FOR_BUILD)
24 gb_PythonTest_DEPS :=
25 endif
27 gb_PythonTest_COMMAND := $(gb_PythonTest_EXECUTABLE) -m unittest
29 .PHONY : $(call gb_PythonTest_get_clean_target,%)
30 $(call gb_PythonTest_get_clean_target,%) :
31 $(call gb_Helper_abbreviate_dirs,\
32 rm -f $@ $@.log)
34 ifneq ($(DISABLE_PYTHON),TRUE)
36 .PHONY : $(call gb_PythonTest_get_target,%)
37 $(call gb_PythonTest_get_target,%) :| $(gb_PythonTest_DEPS)
38 $(call gb_Output_announce,$*,$(true),PYT,2)
39 $(call gb_Helper_abbreviate_dirs,\
40 rm -rf $(dir $(call gb_PythonTest_get_target,$*)) && \
41 mkdir -p $(dir $(call gb_PythonTest_get_target,$*)) && \
42 $(if $(gb_CppunitTest__interactive),, \
43 $(if $(value gb_CppunitTest_postprocess), \
44 rm -fr $@.core && mkdir $@.core && cd $@.core &&)) \
45 ($(gb_PythonTest_PRECOMMAND) \
46 $(if $(G_SLICE),G_SLICE=$(G_SLICE)) \
47 $(if $(GLIBCXX_FORCE_NEW),GLIBCXX_FORCE_NEW=$(GLIBCXX_FORCE_NEW)) \
48 $(DEFS) \
49 TEST_LIB=$(call gb_Library_get_target,test) \
50 URE_BOOTSTRAP=vnd.sun.star.pathname:$(call gb_Helper_get_rcfile,$(INSTROOT)/$(LIBO_ETC_FOLDER)/fundamental) \
51 PYTHONPATH="$(PYPATH)" \
52 UserInstallation=$(call gb_Helper_make_url,$(dir $(call gb_PythonTest_get_target,$*))user) \
53 TestUserDir="$(call gb_Helper_make_url,$(dir $(call gb_PythonTest_get_target,$*)))" \
54 PYTHONDONTWRITEBYTECODE=1 \
55 $(if $(filter-out MACOSX WNT,$(OS_FOR_BUILD)),$(if $(ENABLE_HEADLESS),, \
56 SAL_USE_VCLPLUGIN=svp \
57 )) \
58 $(gb_CppunitTest_GDBTRACE) $(gb_CppunitTest_VALGRINDTOOL) \
59 $(gb_PythonTest_COMMAND) \
60 $(MODULES) \
61 $(if $(gb_CppunitTest__interactive),, \
62 > $@.log 2>&1 \
63 || ($(if $(value gb_CppunitTest_postprocess), \
64 RET=$$?; \
65 $(call gb_CppunitTest_postprocess,$(gb_PythonTest_EXECUTABLE_GDB),$@.core,$$RET) >> $@.log 2>&1;) \
66 cat $@.log; $(SRCDIR)/solenv/bin/unittest-failed.sh Python $*))))
68 # always use udkapi and URE services
69 define gb_PythonTest_PythonTest
70 $(call gb_PythonTest_get_target,$(1)) : PYPATH := $(SRCDIR)/unotest/source/python$$(gb_CLASSPATHSEP)$(INSTROOT)/$(LIBO_LIB_PYUNO_FOLDER)$(if $(filter-out $(LIBO_LIB_PYUNO_FOLDER),$(LIBO_LIB_FOLDER)),$(gb_CLASSPATHSEP)$(INSTROOT)/$(LIBO_LIB_FOLDER))
71 $(call gb_PythonTest_get_target,$(1)) : MODULES :=
73 $(eval $(call gb_Module_register_target,$(call gb_PythonTest_get_target,$(1)),$(call gb_PythonTest_get_clean_target,$(1))))
74 $(call gb_Helper_make_userfriendly_targets,$(1),PythonTest)
76 endef
78 define gb_PythonTest_set_defs
79 $(call gb_PythonTest_get_target,$(1)) : DEFS := $(2)
81 endef
83 # put the directory on the PYTHONPATH because the "unittest" loader
84 # mysteriously fails to load modules given as absolute path unless the $PWD is
85 # a prefix of the absolute path, which it is not when we go into a certain
86 # dir to get a core dump there
88 # gb_PythonTest_add_modules directory module(s)
89 define gb_PythonTest_add_modules
90 $(call gb_PythonTest_get_target,$(1)) : PYPATH := $$(PYPATH)$$(gb_CLASSPATHSEP)$(2)
91 $(call gb_PythonTest_get_target,$(1)) : MODULES += $(3)
93 endef
95 define gb_PythonTest_use_customtarget
96 $(call gb_PythonTest_get_target,$(1)) : $(call gb_CustomTarget_get_workdir,$(2))
98 endef
101 else # DISABLE_PYTHON
103 .PHONY : $(call gb_PythonTest_get_target,$(1))
104 $(call gb_PythonTest_get_target,%) :
105 $(call gb_Output_announce,$* (skipped - no PythonTest),$(true),PYT,2)
106 @true
108 define gb_PythonTest_PythonTest
109 $(eval $(call gb_Module_register_target,$(call gb_PythonTest_get_target,$(1)),$(call gb_PythonTest_get_clean_target,$(1))))
110 $(call gb_Helper_make_userfriendly_targets,$(1),PythonTest)
112 endef
114 gb_PythonTest_set_defs :=
115 gb_PythonTest_add_modules :=
116 gb_PythonTest_use_customtarget :=
118 endif # DISABLE_PYTHON
119 # vim: set noet sw=4: