Skip to content

Commit

Permalink
sync KDPySide2ModuleBuild.py and KDFixupShiboken2.py to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Winter committed Apr 9, 2024
1 parent 99e70c7 commit 7d2cfa6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cmake/KDAB/modules/KDFixupShiboken2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: BSD-3-Clause
#

"""
Script to fix bugs in code generated by shiboken-generator vr2
"""

import sys
import re


def removeExtraNamespaceForDefaultEnumValue(filename):
"""
Remove namespace from default flag value
this is a shiboken2 bug fixed on shiboken6
"""
regex = re.compile(r"\s=\s[^\s]+::{}")
newContent = ""
with open(filename, encoding='utf-8') as f:
for line in f:
newContent += re.sub(regex, ' = {}', line)

with open(filename, "w", encoding='utf-8') as f:
f.write(newContent)


# Usage: <script> <list-of-files>
# It will fix the file inplace
if __name__ == '__main__':
for fileToFix in sys.argv[1:]:
print("Fixup: {}".format(fileToFix))
removeExtraNamespaceForDefaultEnumValue(fileToFix)
4 changes: 4 additions & 0 deletions cmake/KDAB/modules/KDPySide2ModuleBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# SPDX-License-Identifier: BSD-3-Clause
#

# Save path to this cmake file (so it can be used later in the macros)
set(THIS_CMAKE_LIST_DIR ${CMAKE_CURRENT_LIST_DIR})

if(NOT ${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX)
# cmake-lint: disable=C0103
set(${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX
Expand Down Expand Up @@ -129,6 +132,7 @@ macro(
$<TARGET_PROPERTY:Shiboken2::shiboken,LOCATION> ${GENERATOR_EXTRA_FLAGS} ${globalInclude}
--include-paths=${shiboken_include_dirs} --typesystem-paths=${shiboken_typesystem_dirs}
${shiboken_framework_include_dirs_option} --output-directory=${CMAKE_CURRENT_BINARY_DIR} ${typesystemXML}
COMMAND ${Python3_EXECUTABLE} ${THIS_CMAKE_LIST_DIR}/KDFixupShiboken2.py ${outputSource}
DEPENDS ${typesystemXML} ${dependsArg}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Running generator for ${libraryName} binding..."
Expand Down

0 comments on commit 7d2cfa6

Please sign in to comment.