Skip to content

Commit

Permalink
Refactor plugin staging to build dir and python script compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
dakcarto committed May 21, 2014
1 parent 2e8ba8b commit 3213d01
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 80 deletions.
65 changes: 48 additions & 17 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,48 @@ FILE (MAKE_DIRECTORY ${QGIS_PYTHON_OUTPUT_DIRECTORY})
SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QGIS_PYTHON_OUTPUT_DIRECTORY})
SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_PYTHON_OUTPUT_DIRECTORY})

# Python plugins and support packages can be staged to PYTHON_OUTPUT_DIRECTORY
# so plugins will function when app is run from build directory

# When staging all plugins, use the following make targets:
# staged-plugins - stage plugins (usually after repo pull/build and project make)
# staged-plugins-pyc - stage and byte-compile all
# clean-staged-plugins - removes the staged plugins' directories
#
# NOTE: regular project 'make install' is unaffected

# Other target dependenciess will be added, per staged resource
ADD_CUSTOM_TARGET(staged-plugins)

# Plugins can also be staged with CMake option at build time
IF(WITH_STAGED_PLUGINS)
ADD_CUSTOM_TARGET(staged-plugins-on-build ALL DEPENDS staged-plugins)
ENDIF(WITH_STAGED_PLUGINS)

# Non-default/non-option-controlled target to stage and compile plugins and extras
ADD_CUSTOM_TARGET(staged-plugins-pyc DEPENDS staged-plugins
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Byte-compiling build output/python directory..."
)

# Other custom commands will be added, per staged resource
ADD_CUSTOM_TARGET(clean-staged-plugins
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PYTHON_OUTPUT_DIRECTORY}/plugins"
)

# Macro to byte-compile a target's staged Python resource(s)
MACRO(PY_COMPILE TARGET_NAME RESOURCE_PATHS)
IF(WITH_PY_COMPILE)
ADD_CUSTOM_COMMAND(TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q ${RESOURCE_PATHS}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Byte-compiling staged resource..."
)
ENDIF(WITH_PY_COMPILE)
ENDMACRO(PY_COMPILE)

ADD_SUBDIRECTORY(plugins)
ADD_SUBDIRECTORY(qsci_apis)
ADD_SUBDIRECTORY(console)
Expand Down Expand Up @@ -172,14 +214,15 @@ IF(WITH_QSCIAPI)
COMMENT "Generating ${PAP_NAME} for console auto-completion (MAY TAKE > 1 MINUTE!)" VERBATIM)
ENDIF(WITH_QSCIAPI)

IF(WITH_CUSTOM_WIDGETS)
INSTALL(FILES custom_widgets/qgis_customwidgets.py DESTINATION "${PYUIC_WIDGET_PLUGIN_DIRECTORY}")
ENDIF(WITH_CUSTOM_WIDGETS)

# Plugin utilities files to copy to staging or install
SET(PY_FILES
__init__.py
utils.py
)
IF(WITH_CUSTOM_WIDGETS)
INSTALL(FILES custom_widgets/qgis_customwidgets.py DESTINATION "${PYUIC_WIDGET_PLUGIN_DIRECTORY}")
ENDIF(WITH_CUSTOM_WIDGETS)

ADD_CUSTOM_TARGET(pyutils ALL)
INSTALL(FILES ${PY_FILES} DESTINATION "${QGIS_PYTHON_DIR}")
Expand All @@ -192,6 +235,7 @@ FOREACH(pyfile ${PY_FILES})
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${pyfile}
)
PY_COMPILE(pyutils "${QGIS_PYTHON_OUTPUT_DIRECTORY}/${pyfile}")
ENDFOREACH(pyfile)

FOREACH(module core gui analysis networkanalysis)
Expand All @@ -207,18 +251,5 @@ FOREACH(module core gui analysis networkanalysis)
DEPENDS ${PY_FILES}
)
ENDFOREACH(pyfile)
PY_COMPILE(py${module} "${QGIS_PYTHON_OUTPUT_DIRECTORY}/${module}")
ENDFOREACH(module)


# Byte-compile staged PyQGIS utilities
IF(WITH_PY_COMPILE)
ADD_CUSTOM_TARGET(pycompile-pyutils ALL
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}/qgis"
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}/console"
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}/pyplugin_installer"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Byte-compiling staged PyQGIS utility modules..."
DEPENDS pyutils
)
ENDIF(WITH_PY_COMPILE)

1 change: 1 addition & 0 deletions python/console/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ FOREACH(pyfile ${PY_CONSOLE_FILES} ${PYUI_FILES})
DEPENDS ${pyfile}
)
ENDFOREACH(pyfile)
PY_COMPILE(pyconsole "${PYTHON_OUTPUT_DIRECTORY}/console")

INSTALL(FILES ${PY_CONSOLE_FILES} ${PYUI_FILES} DESTINATION "${QGIS_CONSOLE_DIR}")

64 changes: 29 additions & 35 deletions python/ext-libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# See ../CMakeLists.txt for info on staged-plugins* and clean-staged-plugins targets

SET (QGIS_PYTHON_DIR ${QGIS_DATA_DIR}/python)
SET (PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python)

Expand All @@ -12,26 +14,22 @@ MACRO(EXT_PYLIB lib)
IF(WITH_INTERNAL_${ulib})
INSTALL(DIRECTORY ${lib} DESTINATION "${QGIS_PYTHON_DIR}")

IF(WITH_STAGED_PLUGINS)
ADD_CUSTOM_TARGET(py${lib} ALL)
ADD_CUSTOM_TARGET(py${lib})

FILE(GLOB_RECURSE files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${lib}/*)
ADD_CUSTOM_COMMAND(TARGET py${lib}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${lib} "${PYTHON_OUTPUT_DIRECTORY}/${lib}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${files}
)
PY_COMPILE(py${lib} "${PYTHON_OUTPUT_DIRECTORY}/${lib}")

FILE(GLOB_RECURSE files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${lib}/*)
ADD_CUSTOM_COMMAND(TARGET py${lib}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${lib} "${PYTHON_OUTPUT_DIRECTORY}/${lib}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${files}
)
ADD_DEPENDENCIES(staged-plugins py${lib})
ADD_CUSTOM_COMMAND(TARGET clean-staged-plugins
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PYTHON_OUTPUT_DIRECTORY}/${lib}"
)

IF(WITH_PY_COMPILE)
ADD_CUSTOM_TARGET(pycompile-py${lib} ALL
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}/${lib}"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Byte-compiling staged extension ${lib}..."
DEPENDS py${lib}
)
ENDIF(WITH_PY_COMPILE)
ENDIF(WITH_STAGED_PLUGINS)
ENDIF(WITH_INTERNAL_${ulib})
ENDMACRO(EXT_PYLIB lib)

Expand All @@ -43,24 +41,20 @@ SET (WITH_INTERNAL_SIX TRUE CACHE BOOL "Determines whether python six should be
IF(WITH_INTERNAL_SIX)
INSTALL(FILES six.py DESTINATION "${QGIS_PYTHON_DIR}")

IF(WITH_STAGED_PLUGINS)
ADD_CUSTOM_TARGET(pysix ALL)
ADD_CUSTOM_TARGET(pysix)

ADD_CUSTOM_COMMAND(TARGET pysix
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy six.py "${PYTHON_OUTPUT_DIRECTORY}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS six.py
)
ADD_CUSTOM_COMMAND(TARGET pysix
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy six.py "${PYTHON_OUTPUT_DIRECTORY}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS six.py
)
PY_COMPILE(pysix "${PYTHON_OUTPUT_DIRECTORY}/six.py")

ADD_DEPENDENCIES(staged-plugins pysix)
ADD_CUSTOM_COMMAND(TARGET clean-staged-plugins
COMMAND ${CMAKE_COMMAND} -E remove "${PYTHON_OUTPUT_DIRECTORY}/six.py"
)

IF(WITH_PY_COMPILE)
ADD_CUSTOM_TARGET(pycompile-pysix ALL
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}/${lib}"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Byte-compiling staged extension ${lib}..."
DEPENDS pysix
)
ENDIF(WITH_PY_COMPILE)
ENDIF(WITH_STAGED_PLUGINS)
ENDIF(WITH_INTERNAL_SIX)

31 changes: 3 additions & 28 deletions python/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
# Python plugins can be staged to PYTHON_OUTPUT_DIRECTORY so plugins
# will function when app is run from build directory

# When staging all plugins, use the following make targets:
# staged-plugins - stage plugins (usually after repo pull/build and project make)
# staged-plugins-pyc - stage and byte-compile all Python scripts
# clean-staged-plugins - removes the plugins directory and all contents
# See ../CMakeLists.txt for info on staged-plugins* and clean-staged-plugins targets
#
# When developing on a plugin, use the following make targets:
# staged-[plugin_dir_name] - stage specific plugin, regenerating any changed resources
# clean-staged-[plugin_dir_name] - removes the plugin directory and its contents
#
# NOTE: regular project 'make install' is unaffected

ADD_CUSTOM_TARGET(staged-plugins)

ADD_CUSTOM_TARGET(staged-plugins-pyc DEPENDS staged-plugins
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}/plugins"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Byte-compiling staged Python plugins..."
)

# plugins can also be staged with CMake option at build time
IF(WITH_STAGED_PLUGINS)
IF(WITH_PY_COMPILE)
ADD_CUSTOM_TARGET(staged-plugins-on-build ALL DEPENDS staged-plugins-pyc)
ELSE(WITH_PY_COMPILE)
ADD_CUSTOM_TARGET(staged-plugins-on-build ALL DEPENDS staged-plugins)
ENDIF(WITH_PY_COMPILE)
ENDIF(WITH_STAGED_PLUGINS)

ADD_CUSTOM_TARGET(clean-staged-plugins
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PYTHON_OUTPUT_DIRECTORY}/plugins
)

FILE(WRITE ${CMAKE_BINARY_DIR}/stagecount 0)

MACRO (PLUGIN_INSTALL plugin subdir )
Expand Down Expand Up @@ -86,3 +59,5 @@ ADD_SUBDIRECTORY(GdalTools)
ADD_SUBDIRECTORY(db_manager)
ADD_SUBDIRECTORY(processing)
ADD_SUBDIRECTORY(MetaSearch)

PY_COMPILE(staged-plugins "${PYTHON_OUTPUT_DIRECTORY}/plugins")
1 change: 1 addition & 0 deletions python/pyplugin_installer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ FOREACH(pyfile ${PY_PLUGININSTALLER_FILES} ${PYUI_FILES})
DEPENDS ${pyfile}
)
ENDFOREACH(pyfile)
PY_COMPILE(pyplugin-installer "${PYTHON_OUTPUT_DIRECTORY}/pyplugin_installer")

INSTALL(FILES ${PY_PLUGININSTALLER_FILES} ${PYUI_FILES} DESTINATION "${QGIS_PLUGININSTALLER_DIR}")

0 comments on commit 3213d01

Please sign in to comment.