diff options
| -rw-r--r-- | sources/pyside6/doc/CMakeLists.txt | 54 | ||||
| -rw-r--r-- | tools/doc_modules.py | 94 |
2 files changed, 102 insertions, 46 deletions
diff --git a/sources/pyside6/doc/CMakeLists.txt b/sources/pyside6/doc/CMakeLists.txt index 242302aa4..819db870a 100644 --- a/sources/pyside6/doc/CMakeLists.txt +++ b/sources/pyside6/doc/CMakeLists.txt @@ -119,13 +119,21 @@ if (FULLDOCSBUILD) # The last element of the include list is the mkspec directory containing qplatformdefs.h list(GET Qt${QT_MAJOR_VERSION}Core_INCLUDE_DIRS -1 mkspecInclude) - configure_file("pyside-config.qdocconf.in" "${CMAKE_CURRENT_LIST_DIR}/pyside-config.qdocconf" @ONLY) + set(config_docconf "${CMAKE_CURRENT_LIST_DIR}/pyside-config.qdocconf") + configure_file("pyside-config.qdocconf.in" "${config_docconf}" @ONLY) + set(global_header "${pyside6_BINARY_DIR}/qdoc.h") file(READ "${pyside6_BINARY_DIR}/pyside6_global.h" docHeaderContents) + file(WRITE ${global_header} "${docHeaderContents}") + + set(global_typesystem "${CMAKE_CURRENT_BINARY_DIR}/typesystem_doc.xml") file(READ "typesystem_doc.xml.in" typeSystemDocXmlContents) + file(WRITE ${global_typesystem} "${typeSystemDocXmlContents}") execute_process( - COMMAND ${PYTHON_EXECUTABLE} "${TOOLS_DIR}/doc_modules.py" "${QT_INCLUDE_DIR}" + COMMAND ${PYTHON_EXECUTABLE} "${TOOLS_DIR}/doc_modules.py" + -t "${global_typesystem}" -g "${global_header}" -d "${config_docconf}" + "${QT_INCLUDE_DIR}" "${SUPPORTED_QT_VERSION}" OUTPUT_VARIABLE ALL_DOC_MODULES OUTPUT_STRIP_TRAILING_WHITESPACE) separate_arguments (ALL_DOC_MODULES UNIX_COMMAND "${ALL_DOC_MODULES}") @@ -138,47 +146,9 @@ if (FULLDOCSBUILD) get_filename_component(BASENAME ${OUTFILE} NAME) configure_file(${docConf} "${CMAKE_CURRENT_LIST_DIR}/qtmodules/${BASENAME}" @ONLY) file(APPEND "pyside.qdocconf.in" "\@CMAKE_CURRENT_LIST_DIR\@/qtmodules/${BASENAME}\n") - # Handle docconf files in Qt that contain multiple modules - if ("${moduleIn}" STREQUAL "3DExtras") - set(modules 3DCore 3DRender 3DInput 3DLogic 3DAnimation "${moduleIn}") - elseif ("${moduleIn}" STREQUAL "OpenGL") - set(modules "${moduleIn}" OpenGLWidgets) - elseif ("${moduleIn}" STREQUAL "QuickWidgets") - set(modules Qml Quick "${moduleIn}") - elseif ("${moduleIn}" STREQUAL "MultimediaWidgets") - set(modules Multimedia "${moduleIn}") - elseif ("${moduleIn}" STREQUAL "Pdf") - set(modules "${moduleIn}" PdfWidgets) - elseif ("${moduleIn}" STREQUAL "Scxml") - set(modules StateMachine "${moduleIn}") - elseif ("${moduleIn}" STREQUAL "Svg") - set(modules "${moduleIn}" SvgWidgets) - elseif ("${moduleIn}" STREQUAL "WebEngineWidgets") - set(modules WebEngineCore WebEngineWidgets WebEngineQuick "${moduleIn}") - set(HAS_WEBENGINE_WIDGETS 1) - else() - set(modules "${moduleIn}") - endif() - foreach(module ${modules}) - string(TOLOWER "${module}" lowerModule) - # -- @TODO fix this for macOS frameworks. - file(APPEND "${CMAKE_CURRENT_LIST_DIR}/pyside-config.qdocconf" - " -I${QT_INCLUDE_DIR}/Qt${module} \\\n" - " -I${QT_INCLUDE_DIR}/Qt${module}/${Qt${QT_MAJOR_VERSION}Core_VERSION} \\\n" - " -I${QT_INCLUDE_DIR}/Qt${module}/${Qt${QT_MAJOR_VERSION}Core_VERSION}/Qt${module} \\\n") - - set(globalHeader "Qt${module}") - set(docHeaderContents "${docHeaderContents}\n#include <Qt${module}/${globalHeader}>") - set(typeSystemDocXmlContents "${typeSystemDocXmlContents}\n<load-typesystem name=\"Qt${module}/typesystem_${lowerModule}.xml\" generate=\"yes\"/>") - endforeach() endif() endforeach() - set(typeSystemDocXmlContents "${typeSystemDocXmlContents}\n</typesystem>\n") - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/typesystem_doc.xml" "${typeSystemDocXmlContents}") - - set(docHeader "${pyside6_BINARY_DIR}/qdoc.h") - file(WRITE ${docHeader} "${docHeaderContents}") configure_file("pyside.qdocconf.in" "pyside.qdocconf" @ONLY) @@ -244,7 +214,7 @@ configure_file("conf.py.in" "rst/conf.py" @ONLY) set(CODE_SNIPPET_ROOT "${CMAKE_CURRENT_BINARY_DIR}/rst/codesnippets") add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/rst/PySide6/QtCore/index.rst" - COMMAND Shiboken6::shiboken6 --generator-set=qtdoc ${docHeader} + COMMAND Shiboken6::shiboken6 --generator-set=qtdoc ${global_header} --enable-pyside-extensions --include-paths="${QT_INCLUDE_DIR}${PATH_SEP}${pyside6_SOURCE_DIR}${PATH_SEP}${TS_ROOT}" --api-version=${SUPPORTED_QT_VERSION} @@ -257,7 +227,7 @@ add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/rst/PySide6/QtCore/index. --documentation-extra-sections-dir=${CMAKE_CURRENT_BINARY_DIR}/rst/extras --additional-documentation=${CMAKE_CURRENT_BINARY_DIR}/rst/additionaldocs.lst --inheritance-file=${ENV_INHERITANCE_FILE} - ${CMAKE_CURRENT_BINARY_DIR}/typesystem_doc.xml + ${global_typesystem} WORKING_DIRECTORY ${${module}_SOURCE_DIR} COMMENT "Running generator to generate documentation...") diff --git a/tools/doc_modules.py b/tools/doc_modules.py index 9b22c23a1..7738e21bd 100644 --- a/tools/doc_modules.py +++ b/tools/doc_modules.py @@ -18,6 +18,10 @@ ROOT_DIR = Path(__file__).parents[1].resolve() SOURCE_DIR = ROOT_DIR / "sources" / "pyside6" / "PySide6" +qt_version = None +qt_include_dir = None + + class TypeSystemContentHandler(ContentHandler): """XML SAX content handler that extracts required modules from the "load-typesystem" elements of the typesystem_file. Nodes that start @@ -54,6 +58,13 @@ def required_typesystems(module): return handler.required_modules +def query_qtpaths(keyword): + query_cmd = ["qtpaths", "-query", keyword] + output = subprocess.check_output(query_cmd, stderr=subprocess.STDOUT, + universal_newlines=True) + return output.strip() + + def sort_modules(dependency_dict): """Sort the modules by dependencies using brute force: Keep adding modules all of whose requirements are present to the result list @@ -77,6 +88,66 @@ def sort_modules(dependency_dict): return result +def _write_type_system(modules, file): + """Helper to write the type system for shiboken. It needs to be in + dependency order to prevent shiboken from loading the included + typesystems with generate="no", which causes those modules to be + missing.""" + for module in modules: + name = module[2:].lower() + filename = f"{module}/typesystem_{name}.xml" + print(f' <load-typesystem name="{filename}" generate="yes"/>', + file=file) + print("</typesystem>", file=file) + + +def write_type_system(modules, filename): + """Write the type system for shiboken in dependency order.""" + if filename == "-": + _write_type_system(modules, sys.stdout) + else: + path = Path(filename) + exists = path.exists() + with path.open(mode="a") as f: + if not exists: + print('<typesystem package="PySide">', file=f) + _write_type_system(modules, f) + + +def _write_global_header(modules, file): + """Helper to write the global header for shiboken.""" + for module in modules: + print(f"#include <{module}/{module}>", file=file) + + +def write_global_header(modules, filename): + """Write the global header for shiboken.""" + if filename == "-": + _write_global_header(modules, sys.stdout) + else: + with Path(filename).open(mode="a") as f: + _write_global_header(modules, f) + + +def _write_docconf(modules, file): + """Helper to write the include paths for the .qdocconf file.""" + # @TODO fix this for macOS frameworks. + for module in modules: + root = f" -I/{qt_include_dir}/{module}" + print(f"{root} \\", file=file) + print(f"{root}/{qt_version} \\", file=file) + print(f"{root}/{qt_version}/{module} \\", file=file) + + +def write_docconf(modules, filename): + """Write the include paths for the .qdocconf file.""" + if filename == "-": + _write_docconf(modules, sys.stdout) + else: + with Path(filename).open(mode="a") as f: + _write_docconf(modules, f) + + if __name__ == "__main__": argument_parser = ArgumentParser(description=DESC, formatter_class=RawTextHelpFormatter) @@ -84,9 +155,17 @@ if __name__ == "__main__": help="Verbose") argument_parser.add_argument("qt_include_dir", help="Qt Include dir", nargs='?', type=str) + argument_parser.add_argument("qt_version", help="Qt version string", + nargs='?', type=str) + argument_parser.add_argument("--typesystem", "-t", help="Typesystem file to write", + action="store", type=str) + argument_parser.add_argument("--global-header", "-g", help="Global header to write", + action="store", type=str) + argument_parser.add_argument("--docconf", "-d", help="docconf file to write", + action="store", type=str) + options = argument_parser.parse_args() verbose = options.verbose - qt_include_dir = None if options.qt_include_dir: qt_include_dir = Path(options.qt_include_dir) if not qt_include_dir.is_dir(): @@ -96,13 +175,13 @@ if __name__ == "__main__": else: verbose = True # Called by hand to find out about available modules query_cmd = ["qtpaths", "-query", "QT_INSTALL_HEADERS"] - output = subprocess.check_output(query_cmd, stderr=subprocess.STDOUT, - universal_newlines=True) - qt_include_dir = Path(output.strip()) + qt_include_dir = Path(query_qtpaths("QT_INSTALL_HEADERS")) if not qt_include_dir.is_dir(): print("Cannot determine include directory", file=sys.stderr) sys.exit(-1) + qt_version = options.qt_version if options.qt_version else query_qtpaths("QT_VERSION") + # Build a typesystem dependency dict of the available modules in order # to be able to sort_modules by dependencies. This is required as # otherwise shiboken will read the required typesystems with @@ -118,3 +197,10 @@ if __name__ == "__main__": modules = sort_modules(module_dependency_dict) print(" ".join([m[2:] for m in modules])) + + if options.typesystem: + write_type_system(modules, options.typesystem) + if options.global_header: + write_global_header(modules, options.global_header) + if options.docconf: + write_docconf(modules, options.docconf) |
