diff --git a/pyuno/CppunitTest_pyuno_pythonhome.mk b/pyuno/CppunitTest_pyuno_pythonhome.mk new file mode 100644 index 000000000000..44cb301ef857 --- /dev/null +++ b/pyuno/CppunitTest_pyuno_pythonhome.mk @@ -0,0 +1,45 @@ +# -*- 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_CppunitTest_CppunitTest,pyuno_pythonhome)) + +$(eval $(call gb_CppunitTest_add_exception_objects,pyuno_pythonhome, \ + pyuno/qa/cppunit/testpythonhome \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,pyuno_pythonhome, \ + cppu \ + cppuhelper \ + sal \ + subsequenttest \ + test \ + tl \ + unotest \ + utl \ +)) + +$(eval $(call gb_CppunitTest_use_externals,pyuno_pythonhome,\ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_use_api,pyuno_pythonhome,\ + udkapi \ + offapi \ +)) + +$(eval $(call gb_CppunitTest_use_components,pyuno_pythonhome,\ + pyuno/source/loader/pythonloader \ +)) + +$(eval $(call gb_CppunitTest_use_ure,pyuno_pythonhome)) +$(eval $(call gb_CppunitTest_use_vcl,pyuno_pythonhome)) +$(eval $(call gb_CppunitTest_use_rdb,pyuno_pythonhome,services)) +$(eval $(call gb_CppunitTest_use_configuration,pyuno_pythonhome)) + +# vim: set noet sw=4 ts=4: diff --git a/pyuno/Module_pyuno.mk b/pyuno/Module_pyuno.mk index f69e89fa791c..fd24dc8c93cd 100644 --- a/pyuno/Module_pyuno.mk +++ b/pyuno/Module_pyuno.mk @@ -46,6 +46,7 @@ endif $(eval $(call gb_Module_add_check_targets,pyuno, \ PythonTest_pyuno_pytests_testimports \ + $(if $(SYSTEM_PYTHON),,CppunitTest_pyuno_pythonhome) \ )) endif # !SYSTEM_PYTHON diff --git a/pyuno/qa/cppunit/testpythonhome.cxx b/pyuno/qa/cppunit/testpythonhome.cxx new file mode 100644 index 000000000000..b90ea82ad8a4 --- /dev/null +++ b/pyuno/qa/cppunit/testpythonhome.cxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 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/. + */ + +#include + +#include + +#include +#include +#include + +namespace +{ +class PythonHomeTest : public UnoApiTest +{ +public: + PythonHomeTest() + : UnoApiTest(u"/pyuno/qa/extras"_ustr) + { + } + +private: + void testHome(); + + CPPUNIT_TEST_SUITE(PythonHomeTest); + CPPUNIT_TEST(testHome); + CPPUNIT_TEST_SUITE_END(); +}; + +void PythonHomeTest::testHome() +{ + // Tests that the Python environment has the Python home correctly configured. See tdf#169387 + + css::uno::Reference xLoader( + m_xFactory->createInstanceWithContext(u"com.sun.star.loader.Python"_ustr, m_xContext), + css::uno::UNO_QUERY_THROW); + + css::uno::Reference xFactory( + xLoader->activate(u"org.libreoffice.pyuno.check_python_home"_ustr, u""_ustr, + createFileURL(u"check_python_home.py"), + css::uno::Reference()), + css::uno::UNO_QUERY_THROW); + + css::uno::Reference xJob(xFactory->createInstanceWithContext(m_xContext), + css::uno::UNO_QUERY_THROW); + + // Execute the job contained in the test service. This should throw an exception if the test + // fails. + xJob->execute(css::uno::Sequence()); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(PythonHomeTest); + +} // namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/pyuno/qa/extras/check_python_home.py b/pyuno/qa/extras/check_python_home.py new file mode 100644 index 000000000000..2cdac9849f93 --- /dev/null +++ b/pyuno/qa/extras/check_python_home.py @@ -0,0 +1,47 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# 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/. +# + +from com.sun.star.task import XJob +from com.sun.star.uri import UriReferenceFactory +from com.sun.star.util import theMacroExpander +import os.path +import sys +import uno +import unohelper + + +g_ImplementationHelper = unohelper.ImplementationHelper() +g_implName = "org.libreoffice.pyuno.check_python_home" + + +class CheckPythonHome(unohelper.Base, XJob): + def __init__(self, ctx): + self.ctx = ctx + + def execute(self, args): + # Make sure that the Python prefix is a subdirectory of $BRAND_BASE_DIR + + xServiceManager = self.ctx.ServiceManager + xUriFactory = UriReferenceFactory.create(self.ctx) + xUriReference = xUriFactory.parse("vnd.sun.star.expand:$BRAND_BASE_DIR") + uri = xUriReference.expand(theMacroExpander.get(self.ctx)) + brand_path = os.path.realpath(uno.fileUrlToSystemPath(uri)) + prefix_path = os.path.realpath(sys.prefix) + + assert prefix_path.startswith(brand_path) + + +g_ImplementationHelper.addImplementation( + CheckPythonHome, + g_implName, + ( + ), +) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: