Skip to content

Commit 2ee9b00

Browse files
authored
3P Package source for Pyside / Linux (#67)
1 parent 90480ca commit 2ee9b00

File tree

9 files changed

+418
-9
lines changed

9 files changed

+418
-9
lines changed

package-system/Qt/build.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,3 @@ for qtlib in "${qtarray[@]}"; do
8484
echo $qtlib installed.
8585
done
8686
echo Qt installed successfully!
87-
88-
if [[ "$OSTYPE" != "darwin"* ]]; then
89-
VERSION=$($TARGET_INSTALL_ROOT/bin/qmake -query QT_VERSION)
90-
# Strip libQt5Core for WSL compatibility
91-
strip --remove-section=.note.ABI-tag $TARGET_INSTALL_ROOT/lib/libQt5Core.so.$VERSION
92-
# Remove symlinks from the build dir, we regenerate them
93-
find $TARGET_INSTALL_ROOT/lib -type l | xargs rm
94-
echo Qt install post-processing complete!
95-
fi
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0 OR MIT
5+
#
6+
#
7+
8+
# this file actually ingests the library and defines targets.
9+
10+
set(MY_NAME "pyside2")
11+
set(TARGET_WITH_NAMESPACE "3rdParty::${MY_NAME}")
12+
if (TARGET ${TARGET_WITH_NAMESPACE})
13+
return()
14+
endif()
15+
16+
add_library(${TARGET_WITH_NAMESPACE} INTERFACE IMPORTED GLOBAL)
17+
18+
ly_pip_install_local_package_editable(${CMAKE_CURRENT_LIST_DIR}/pyside2 pyside2)
19+
20+
set(pyside2_RUNTIME_DEPENDENCIES
21+
${PYSIDE_BASE_PATH}/PySide2/libpyside2.abi3.so.5.14
22+
${PYSIDE_BASE_PATH}/PySide2/libpyside2.abi3.so.5.14.2.3
23+
${PYSIDE_BASE_PATH}/shiboken2/shiboken2.abi3.so
24+
${PYSIDE_BASE_PATH}/shiboken2/libshiboken2.abi3.so.5.14
25+
${PYSIDE_BASE_PATH}/shiboken2/libshiboken2.abi3.so.5.14.2.3
26+
)
27+
28+
set(${MY_NAME}_FOUND True)

package-system/pyside2-qt/__init__.py

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"git_url": "https://code.qt.io/cgit/pyside/pyside-setup.git",
3+
"git_tag": "v5.14.2.3",
4+
"package_name": "pyside2",
5+
"package_version": "5.15.2-rev1",
6+
"package_url": "https://code.qt.io/cgit/pyside/pyside-setup.git",
7+
"package_license": "custom",
8+
"package_license_file": "pyside2/LICENSE.LGPLv3",
9+
"patch_file": "pyside_o3de-v5.14.2.3.patch",
10+
"cmake_find_target": "Findpyside2.cmake",
11+
"Platforms": {
12+
"Linux": {
13+
"Linux": {
14+
"depends_on_packages" :[
15+
["python-3.7.10-rev2-linux", "6b9cf455e6190ec38836194f4454bb9db6bfc6890b4baff185cc5520aa822f05", ""],
16+
["qt-5.15.2-rev6-linux", "a37bd9989f1e8fe57d94b98cbf9bd5c3caaea740e2f314e5162fa77300551531", ""]
17+
],
18+
"cmake_find_source": "Findpyside2.cmake.Linux",
19+
"custom_build_cmd": [
20+
"./build_linux.sh"
21+
],
22+
"custom_install_cmd": [
23+
"./package_linux.sh"
24+
]
25+
}
26+
}
27+
}
28+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (c) Contributors to the Open 3D Engine Project.
5+
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
6+
#
7+
# SPDX-License-Identifier: Apache-2.0 OR MIT
8+
#
9+
#
10+
11+
12+
# Get the python executable from the package dependency
13+
LOCAL_PYTHON37_BIN=$TEMP_FOLDER/python-3.7.10-rev2-linux/python/bin/python3
14+
15+
SCRIPT_PATH=`dirname $0`
16+
17+
18+
if [ ! -f "$LOCAL_PYTHON37_BIN" ]
19+
then
20+
echo "Missing 3P dependency of python3.7 $LOCAL_PYTHON37_BIN"
21+
echo "You will need to build the 3P version of python under the '`readlink -f ../python`'' folder"
22+
echo "with the following command:"
23+
echo
24+
echo "python3 build_package_image.py"
25+
echo
26+
exit 1
27+
fi
28+
29+
# Get the qt package's qmake location
30+
LOCAL_3P_QTBUILD_PATH=$TEMP_FOLDER/qt-5.15.2-rev6-linux/qt
31+
LOCAL_3P_QTBUILD_QMAKE_PATH=`readlink -f $LOCAL_3P_QTBUILD_PATH/bin/qmake`
32+
LOCAL_3P_QTBUILD_LIB_PATH=`readlink -f $LOCAL_3P_QTBUILD_PATH/lib`
33+
if [ ! -f "$LOCAL_3P_QTBUILD_QMAKE_PATH" ]
34+
then
35+
echo "Missing 3P dependency of Qt $LOCAL_3P_QTBUILD_PATH"
36+
echo
37+
exit 1
38+
fi
39+
40+
41+
# TEMP_FOLDER and TARGET_INSTALL_ROOT get set from the pull_and_build_from_git.py script
42+
echo Building source
43+
pushd $TEMP_FOLDER/src
44+
45+
LD_LIBRARY_PATH=$LOCAL_3P_QTBUILD_LIB_PATH/
46+
export LD_LIBRARY_PATH
47+
48+
echo "$LOCAL_PYTHON37_BIN setup.py install --qmake=$LOCAL_3P_QTBUILD_QMAKE_PATH --build-type=all --limited-api=yes --skip-modules=Qml,Quick,Positioning,Location,RemoteObjects,Scxml,TextToSpeech,3DCore,3DRender,3DInput,3DLogic,3DAnimation,3DExtras,Multimedia,MultimediaWidgets,AxContainer"
49+
$LOCAL_PYTHON37_BIN setup.py install --qmake=$LOCAL_3P_QTBUILD_QMAKE_PATH --build-type=all --limited-api=yes --skip-modules=Qml,Quick,QuickWidgets,Positioning,Location,RemoteObjects,Scxml,TextToSpeech,3DCore,3DRender,3DInput,3DLogic,3DAnimation,3DExtras,Multimedia,MultimediaWidgets,AxContainer
50+
51+
popd
52+
53+
exit 0
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (c) Contributors to the Open 3D Engine Project.
5+
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
6+
#
7+
# SPDX-License-Identifier: Apache-2.0 OR MIT
8+
#
9+
#
10+
11+
# TEMP_FOLDER and TARGET_INSTALL_ROOT get set from the pull_and_build_from_git.py script
12+
13+
PACKAGE_BASE=$TARGET_INSTALL_ROOT
14+
15+
INSTALL_SOURCE=$TEMP_FOLDER/src/pyside3a_install/`ls $TEMP_FOLDER/src/pyside3a_install`
16+
echo INSTALL_SOURCE=$INSTALL_SOURCE
17+
18+
# Copy the LICENSE and README files
19+
cp $TEMP_FOLDER/src/LICENSE.* $PACKAGE_BASE/
20+
cp $TEMP_FOLDER/src/README.* $PACKAGE_BASE/
21+
22+
# Copy the Pyside2 package, and create major version sylmink
23+
cp -r $INSTALL_SOURCE/lib/python3.7/site-packages/PySide2 $PACKAGE_BASE
24+
cp $INSTALL_SOURCE/lib/libpyside2.abi3.so.5.14.2.3 $PACKAGE_BASE/PySide2/
25+
ln -s libpyside2.abi3.so.5.14.2.3 $PACKAGE_BASE/PySide2/libpyside2.abi3.so.5.14
26+
27+
# Copy the shiboken2 package, and create major version sylmink
28+
cp -r $INSTALL_SOURCE/lib/python3.7/site-packages/shiboken2 $PACKAGE_BASE
29+
cp $INSTALL_SOURCE/lib/libshiboken2.abi3.so.5.14.2.3 $PACKAGE_BASE/shiboken2/
30+
ln -s libshiboken2.abi3.so.5.14.2.3 $PACKAGE_BASE/shiboken2/libshiboken2.abi3.so.5.14
31+
32+
# Patch the Pyside2 shared library to resolve shiboken2
33+
$TEMP_FOLDER/src/patchelf --set-rpath ../shiboken2:\$ORIGIN $PACKAGE_BASE/PySide2/libpyside2.abi3.so.5.14.2.3
34+
35+
# Patch the shiboken2.abi.so module to resolve the libshiboken at ORIGIN
36+
$TEMP_FOLDER/src/patchelf --set-rpath \$ORIGIN $PACKAGE_BASE/shiboken2/shiboken2.abi3.so
37+
38+
# Add additional files needed for pip install
39+
cp $TEMP_FOLDER/../__init__.py $PACKAGE_BASE/
40+
cp $TEMP_FOLDER/../setup.py $PACKAGE_BASE/
41+
42+
exit 0
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
diff --git a/build_scripts/main.py b/build_scripts/main.py
2+
index cf56850df..0e1a0fa4b 100644
3+
--- a/build_scripts/main.py
4+
+++ b/build_scripts/main.py
5+
@@ -544,6 +544,9 @@ class PysideBuild(_build):
6+
py_include_dir = os.path.join(py_prefix, "include")
7+
else:
8+
py_include_dir = os.path.join(py_prefix, "include/python{}".format(py_version))
9+
+ if not os.path.isdir(py_include_dir):
10+
+ py_include_dir = os.path.join(py_prefix, "include/python{}m".format(py_version))
11+
+
12+
dbg_postfix = ""
13+
if build_type == "Debug":
14+
dbg_postfix = "_d"
15+
diff --git a/sources/pyside2/libpyside/CMakeLists.txt b/sources/pyside2/libpyside/CMakeLists.txt
16+
index 7493a453a..f67196815 100644
17+
--- a/sources/pyside2/libpyside/CMakeLists.txt
18+
+++ b/sources/pyside2/libpyside/CMakeLists.txt
19+
@@ -1,13 +1,5 @@
20+
project(libpyside)
21+
22+
-if(${Qt5Qml_FOUND})
23+
- if(NOT "${Qt5Qml_PRIVATE_INCLUDE_DIRS}" MATCHES "/QtQml/")
24+
- string(REPLACE "/QtCore" "/QtQml" replaceme "${Qt5Core_PRIVATE_INCLUDE_DIRS}")
25+
- list(APPEND Qt5Qml_PRIVATE_INCLUDE_DIRS ${replaceme})
26+
- list(REMOVE_DUPLICATES Qt5Qml_PRIVATE_INCLUDE_DIRS)
27+
- endif()
28+
-endif()
29+
-
30+
if(${Qt5Quick_FOUND})
31+
if(NOT "${Qt5Quick_PRIVATE_INCLUDE_DIRS}" MATCHES "/QtQuick/")
32+
string(REPLACE "/QtCore" "/QtQuick" replaceme "${Qt5Core_PRIVATE_INCLUDE_DIRS}")
33+
@@ -17,26 +9,11 @@ if(${Qt5Quick_FOUND})
34+
endif()
35+
endif()
36+
37+
+# Disable QML support
38+
+set(QML_SUPPORT 0)
39+
set(QML_PRIVATE_API_SUPPORT 0)
40+
-if(Qt5Qml_FOUND)
41+
- # Used for registering custom QQuickItem classes defined in Python code.
42+
- set(QML_SUPPORT 1)
43+
- set(QML_INCLUDES ${Qt5Qml_INCLUDE_DIRS})
44+
- set(QML_LIBRARIES ${Qt5Qml_LIBRARIES})
45+
-
46+
- if(Qt5Qml_PRIVATE_INCLUDE_DIRS)
47+
- # Used for transforming QML exceptions into Python exceptions.
48+
- set(QML_PRIVATE_API_SUPPORT 1)
49+
- set(QML_INCLUDES ${QML_INCLUDES} ${Qt5Qml_PRIVATE_INCLUDE_DIRS})
50+
- else()
51+
- message(WARNING "QML private API include files could not be found, support for catching QML exceptions inside Python code will not work.")
52+
- endif()
53+
-else()
54+
- set(QML_SUPPORT 0)
55+
- set(QML_PRIVATE_API_SUPPORT 0)
56+
- set(QML_INCLUDES "")
57+
- set(QML_LIBRARIES "")
58+
-endif()
59+
+set(QML_INCLUDES "")
60+
+set(QML_LIBRARIES "")
61+
62+
qt5_wrap_cpp(DESTROYLISTENER_MOC "destroylistener.h")
63+
64+
diff --git a/sources/pyside2/libpyside/pyside.cpp b/sources/pyside2/libpyside/pyside.cpp
65+
index e2b8708ce..0541c7d91 100644
66+
--- a/sources/pyside2/libpyside/pyside.cpp
67+
+++ b/sources/pyside2/libpyside/pyside.cpp
68+
@@ -423,7 +423,7 @@ static const char invalidatePropertyName[] = "_PySideInvalidatePtr";
69+
// class by walking up the meta objects.
70+
static const char *typeName(QObject *cppSelf)
71+
{
72+
- const char *typeName = typeid(*cppSelf).name();
73+
+ const char *typeName = getTypeId(*cppSelf).name();
74+
if (!Shiboken::Conversions::getConverter(typeName)) {
75+
for (auto metaObject = cppSelf->metaObject(); metaObject; metaObject = metaObject->superClass()) {
76+
const char *name = metaObject->className();
77+
@@ -459,7 +459,6 @@ PyObject *getWrapperForQObject(QObject *cppSelf, SbkObjectType *sbk_type)
78+
}
79+
80+
pyOut = Shiboken::Object::newObject(sbk_type, cppSelf, false, false, typeName(cppSelf));
81+
-
82+
return pyOut;
83+
}
84+
85+
diff --git a/sources/pyside2/libpyside/pyside.h b/sources/pyside2/libpyside/pyside.h
86+
index ae400e1fe..b7412594b 100644
87+
--- a/sources/pyside2/libpyside/pyside.h
88+
+++ b/sources/pyside2/libpyside/pyside.h
89+
@@ -50,12 +50,57 @@
90+
91+
#include <QtCore/QMetaType>
92+
#include <QtCore/QHash>
93+
+#include <QtCore/QMetaObject>
94+
+#include <QtCore/QObject>
95+
+
96+
+#include <type_traits>
97+
+#include <typeinfo>
98+
99+
struct SbkObjectType;
100+
101+
namespace PySide
102+
{
103+
104+
+// Analog for std::type_info with the name field, to allow getTypeId to be used in lieu of typeid
105+
+class TypeInfo
106+
+{
107+
+private:
108+
+ const char* m_name = nullptr;
109+
+
110+
+public:
111+
+ explicit TypeInfo(const char* name) : m_name(name) {}
112+
+ const char* name() const { return m_name; }
113+
+};
114+
+
115+
+// getTypeId returns an interface similar to the std::type_info returned by typeid, but will attempt to use
116+
+// Qt's meta-object system for QObject subclasses instead - this allows Shiboken to interop with libraries that
117+
+// are built without RTTI
118+
+template <class T>
119+
+const TypeInfo getTypeId(typename std::enable_if<std::is_base_of<QObject, T>::value>::type* = 0)
120+
+{
121+
+ const char* typeName = T::staticMetaObject.className();
122+
+ return TypeInfo(typeName);
123+
+}
124+
+
125+
+template <class T>
126+
+const TypeInfo getTypeId(typename std::enable_if<!std::is_base_of<QObject, T>::value>::type* = 0)
127+
+{
128+
+ return TypeInfo(typeid(T).name());
129+
+}
130+
+
131+
+template <class T>
132+
+const TypeInfo getTypeId(const T& t, typename std::enable_if<std::is_base_of<QObject, T>::value>::type* = 0)
133+
+{
134+
+ const char* typeName = t.metaObject() ? t.metaObject()->className() : T::staticMetaObject.className();
135+
+ return TypeInfo(typeName);
136+
+}
137+
+
138+
+template <class T>
139+
+const TypeInfo getTypeId(const T& t, typename std::enable_if<!std::is_base_of<QObject, T>::value>::type* = 0)
140+
+{
141+
+ return TypeInfo(typeid(t).name());
142+
+}
143+
+
144+
PYSIDE_API void init(PyObject *module);
145+
146+
/**
147+
diff --git a/sources/shiboken2/CMakeLists.txt b/sources/shiboken2/CMakeLists.txt
148+
index c1349cae6..5e6071bb7 100644
149+
--- a/sources/shiboken2/CMakeLists.txt
150+
+++ b/sources/shiboken2/CMakeLists.txt
151+
@@ -76,7 +76,7 @@ if (NOT PYTHON_EXTENSION_SUFFIX)
152+
get_python_extension_suffix()
153+
endif()
154+
155+
-option(FORCE_LIMITED_API "Enable the limited API." "yes")
156+
+option(FORCE_LIMITED_API "Enable the limited API." ON)
157+
set(PYTHON_LIMITED_API 0)
158+
159+
shiboken_check_if_limited_api()
160+
diff --git a/sources/shiboken2/data/shiboken_helpers.cmake b/sources/shiboken2/data/shiboken_helpers.cmake
161+
index 6bd75d0ea..316b52f05 100644
162+
--- a/sources/shiboken2/data/shiboken_helpers.cmake
163+
+++ b/sources/shiboken2/data/shiboken_helpers.cmake
164+
@@ -298,7 +298,7 @@ macro(shiboken_check_if_limited_api)
165+
OUTPUT_VARIABLE PYTHON_LIMITED_LIBRARIES
166+
OUTPUT_STRIP_TRAILING_WHITESPACE)
167+
168+
- if(FORCE_LIMITED_API STREQUAL "yes")
169+
+ if(FORCE_LIMITED_API)
170+
if (${PYTHON_VERSION_MAJOR} EQUAL 3 AND ${PYTHON_VERSION_MINOR} GREATER 4)
171+
# GREATER_EQUAL is available only from cmake 3.7 on. We mean python 3.5 .
172+
set(PYTHON_LIMITED_API 1)
173+
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
174+
index 64467e3d1..e729c49ea 100644
175+
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
176+
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
177+
@@ -58,7 +58,11 @@ static const char typeNameFunc[] = R"CPP(
178+
template <class T>
179+
static const char *typeNameOf(const T &t)
180+
{
181+
+#ifdef PYSIDE_H
182+
+ const char *typeName = PySide::getTypeId<T>(t).name();
183+
+#else
184+
const char *typeName = typeid(t).name();
185+
+#endif //PYSIDE_H
186+
auto size = std::strlen(typeName);
187+
#if defined(Q_CC_MSVC) // MSVC: "class QPaintDevice * __ptr64"
188+
if (auto lastStar = strchr(typeName, '*')) {
189+
@@ -1522,18 +1526,31 @@ void CppGenerator::writeConverterRegister(QTextStream &s, const AbstractMetaClas
190+
cppSignature.removeFirst();
191+
}
192+
193+
- s << INDENT << "Shiboken::Conversions::registerConverterName(converter, typeid(::";
194+
+ if (usePySideExtensions() && metaClass->isQObject()) {
195+
+ s << INDENT << "Shiboken::Conversions::registerConverterName(converter, PySide::getTypeId<::";
196+
+ } else {
197+
+ s << INDENT << "Shiboken::Conversions::registerConverterName(converter, typeid(::";
198+
+ }
199+
QString qualifiedCppNameInvocation;
200+
if (!classContext.forSmartPointer())
201+
qualifiedCppNameInvocation = metaClass->qualifiedCppName();
202+
else
203+
qualifiedCppNameInvocation = classContext.preciseType()->cppSignature();
204+
205+
- s << qualifiedCppNameInvocation << ").name());\n";
206+
+ if (usePySideExtensions() && metaClass->isQObject()) {
207+
+ s << qualifiedCppNameInvocation << ">().name());\n";
208+
+ } else {
209+
+ s << qualifiedCppNameInvocation << ").name());\n";
210+
+ }
211+
212+
if (shouldGenerateCppWrapper(metaClass)) {
213+
- s << INDENT << "Shiboken::Conversions::registerConverterName(converter, typeid(::";
214+
- s << wrapperName(metaClass) << ").name());\n";
215+
+ if (usePySideExtensions() && metaClass->isQObject()) {
216+
+ s << INDENT << "Shiboken::Conversions::registerConverterName(converter, PySide::getTypeId<::";
217+
+ s << wrapperName(metaClass) << ">().name());\n";
218+
+ } else {
219+
+ s << INDENT << "Shiboken::Conversions::registerConverterName(converter, typeid(::";
220+
+ s << wrapperName(metaClass) << ").name());\n";
221+
+ }
222+
}
223+
224+
s << endl;

0 commit comments

Comments
 (0)