Skip to content

Commit

Permalink
FEATURE: Additional rework of package structure
Browse files Browse the repository at this point in the history
Implementation of Python packaging workflow using the CPack function and Python installer external executable.

Implementation BeagleBone/Texas Instruments PRU package structure.
  • Loading branch information
cerna committed Dec 22, 2021
1 parent 952f8b1 commit 4274b64
Show file tree
Hide file tree
Showing 78 changed files with 1,606 additions and 53 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ string(TOLOWER ${MACHINEKIT_HAL_PACKAGE_PREFIX_NORMALIZED}
MACHINEKIT_HAL_PACKAGE_PREFIX)
string(REGEX REPLACE "_" "/" MACHINEKIT_HAL_PACKAGE_PREFIX_PATH
${MACHINEKIT_HAL_PACKAGE_PREFIX})
string(REGEX REPLACE "[-~ .]" "" MACHINEKIT_HAL_PACKAGE_NAME
${CMAKE_PROJECT_NAME})

include(GNUInstallDirs)
include(CPackComponent)
Expand All @@ -70,6 +72,8 @@ set(MACHINEKIT_HAL_LOCAL_STATE_DIRECTORY "${CMAKE_INSTALL_LOCALSTATEDIR}")
set(MACHINEKIT_HAL_TEST_DIRECTORY
"${CMAKE_INSTALL_DATAROOTDIR}/${MACHINEKIT_HAL_PACKAGE_PREFIX_PATH}/testsuite"
)
set(MACHINEKIT_HAL_CMAKE_PACKAGE_DIRECTORY
"${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}")

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/support/cmake/tools"
"${PROJECT_SOURCE_DIR}/support/cmake/languages")
Expand Down
7 changes: 7 additions & 0 deletions debian/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
# directory artifacts
/tmp
/machinekit-hal*/
/libmachinekit-hal*/
/modmachinekit-hal*/
/python3*/

/.cpack/

# file artifacts
/*substvars
Expand All @@ -16,4 +21,6 @@
/files
/__pycache__

/debhelper-build-stamp

!/changelog.in
28 changes: 28 additions & 0 deletions debian/control.in
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,34 @@ Description: Universal framework for machine control based on Hardware Abstracti
motion and other control for atomation, robot and CNC machine tool
applications.

Package: python3-machinekit-hal
Architecture: any
Multi-Arch: foreign
Depends: ${shlibs:Depends}, ${misc:Depends}, ${cpack:Depends}, ${python3:Depends}
Description: Machinekit-HAL's Python exacutables
This package contains the executables written in Python for the Machinekit-HAL project

Package: python3-libmachinekit-hal
Architecture: any
Multi-Arch: foreign
Depends: ${shlibs:Depends}, ${misc:Depends}, ${cpack:Depends}, ${python3:Depends}
Description: Machinekit-HAL's Python libraries
This package contains the libraries written in Python for the Machinekit-HAL project

Package: python3-modmachinekit-hal-unmanaged-components
Architecture: any
Multi-Arch: foreign
Depends: ${shlibs:Depends}, ${misc:Depends}, ${cpack:Depends}, ${python3:Depends}
Description: Machinekit-HAL's Python unmanaged modules - components
This package contains the unmanaged modules - components written in Python3 for the Machinekit-HAL project.

Package: python3-modmachinekit-hal-unmanaged-drivers
Architecture: any
Multi-Arch: foreign
Depends: ${shlibs:Depends}, ${misc:Depends}, ${cpack:Depends}, ${python3:Depends}
Description: Machinekit-HAL's Python unmanaged modules - drivers
This package contains the unmanaged modules - drivers written in Python3 for the Machinekit-HAL project.

#Package: machinekit-hal-dev
#Architecture: any
#Depends:
Expand Down
1 change: 1 addition & 0 deletions debian/python3-libmachinekit-hal.cpack-component-groups
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MachinekitHAL_Package_Base_Python_Libraries
1 change: 1 addition & 0 deletions debian/python3-machinekit-hal.cpack-component-groups
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MachinekitHAL_Package_Base_Python_Executables
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MachinekitHAL_Package_Base_Python_Unmanaged_Modules_Components
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MachinekitHAL_Package_Base_Python_Unmanaged_Modules_Drivers
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ else
endif

%:
dh $@ --buildsystem=cmake
dh $@ --buildsystem=cmake --with=python3
128 changes: 115 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ set(THREADS_PREFER_PTHREAD_FLAG TRUE)

option(BUILD_PYTHON_DISTRIBUTIONS "Build Python3 distribution packages" TRUE)

if(BUILD_PYTHON_DISTRIBUTIONS)
include(PEP503PythonIndex)
# Create a simple PEP503 conforming local Python index
if(NOT MACHINEKIT_HAL_PYTHON_INDEX)
set(MACHINEKIT_HAL_PYTHON_INDEX
"${CMAKE_BINARY_DIR}/$<CONFIG>/python_index")
endif()
endif()

# Define the outer rules for output directories for build artifacts
set(MACHINEKIT_HAL_ARTIFACTS_MOUNTPOINT_DIRECTORY
"${CMAKE_BINARY_DIR}/$<CONFIG>")
Expand Down Expand Up @@ -89,6 +80,15 @@ if(NOT MACHINEKIT_HAL_TEST_OUTPUT_DIRECTORY)
"${MACHINEKIT_HAL_ARTIFACTS_MOUNTPOINT_DIRECTORY}/${MACHINEKIT_HAL_TEST_DIRECTORY}"
)
endif()
# The export contains versions for all configuration, so there is no need for the configuration
# specific ${MACHINEKIT_HAL_ARTIFACTS_MOUNTPOINT_DIRECTORY} (and it even cannot be used for generator
# expression in it), but to have direct similarity to install TREE, use the './lib/<GNU-triplet>/cmake'
# format even for BUILD tree (even though it may seem odd)
# TODO: Investigate if this is really the best solution (as the relative path change does not matter much)
if(NOT MACHINEKIT_HAL_CMAKE_PACKAGE_OUTPUT_DIRECTORY)
set(MACHINEKIT_HAL_CMAKE_PACKAGE_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}/${MACHINEKIT_HAL_CMAKE_PACKAGE_DIRECTORY}")
endif()

# Full install paths for Machinekit-HAL specific directories
GNUInstallDirs_get_absolute_install_dir(
Expand Down Expand Up @@ -118,14 +118,116 @@ GNUInstallDirs_get_absolute_install_dir(
GNUInstallDirs_get_absolute_install_dir(
MACHINEKIT_HAL_TEST_FULL_INSTALL_DIRECTORY MACHINEKIT_HAL_TEST_DIRECTORY
"DATAROOTDIR")

add_subdirectory(libraries)
add_subdirectory(executables)
add_subdirectory(modules)
GNUInstallDirs_get_absolute_install_dir(
MACHINEKIT_HAL_CMAKE_PACKAGE_FULL_INSTALL_DIRECTORY
MACHINEKIT_HAL_CMAKE_PACKAGE_DIRECTORY "LIBDIR")

if(BUILD_PYTHON_DISTRIBUTIONS)
#[[
Installation of Python modules requires a higher logic for determining where
to put the files on the filesystem. Depending on the exact way how the Machinekit-HAL
installation will be used (Debian [and other linux distributions's] packaging,
local, /opt, user's HOME installation schemas or virtual environments), the paths
will be different and DOES NOT need to be in any way depending on what GNUInstallDirs
CMake module is defining for C and C++ language targets
TODO: Write smarter logic for default paths
This SIMPLE setting of defaults for full installation folders to the current active
"Python" using the FindPython CMake module
What FindPython reports is superior to what 'sysconfig.get_paths()' reports, at leas
on Debian system (some reported paths do NOT exist):
Python_STDLIB: '/usr/lib/python3.9'
Python_STDARCH:'/usr/lib/python3.9'
Python_SITELIB:'/usr/lib/python3/dist-packages'
Python_SITEARCH:'/usr/lib/python3/dist-packages'
Python_INCLUDE_DIRS:'/usr/include/python3.9'
Python_LIBRARY_DIRS:'/usr/lib/x86_64-linux-gnu'
Python_RUNTIME_LIBRARY_DIRS:'/usr/lib/x86_64-linux-gnu'
vs
{'data': '/usr',
'include': '/usr/include/python3.9',
'platinclude': '/usr/include/python3.9',
'platlib': '/usr/lib/python3.9/site-packages',
'platstdlib': '/usr/lib/python3.9',
'purelib': '/usr/lib/python3.9/site-packages',
'scripts': '/usr/bin',
'stdlib': '/usr/lib/python3.9'}
or for VENV virtual environment:
Python_STDLIB: '/usr/lib/python3.9'
Python_STDARCH: '/usr/lib/python3.9'
Python_SITELIB: '/tmp/venv/lib/python3.9/site-packages'
Python_SITEARCH: '/tmp/venv/lib/python3.9/site-packages'
Python_INCLUDE_DIRS: '/usr/include/python3.9'
Python_LIBRARY_DIRS: '/usr/lib/x86_64-linux-gnu'
Python_RUNTIME_LIBRARY_DIRS: '/usr/lib/x86_64-linux-gnu'
vs
{'data': '/tmp/venv',
include': '/usr/include/python3.9',
platinclude': '/usr/include/python3.9',
platlib': '/tmp/venv/lib/python3.9/site-packages',
platstdlib': '/tmp/venv/lib/python3.9',
purelib': '/tmp/venv/lib/python3.9/site-packages',
scripts': '/tmp/venv/bin',
stdlib': '/usr/lib/python3.9'}
]]

find_package(
Python
COMPONENTS Interpreter Development
REQUIRED)

if(NOT MACHINEKIT_HAL_PYTHON_STDLIB_FULL_INSTALL_DIRECTORY)
set(MACHINEKIT_HAL_PYTHON_STDLIB_FULL_INSTALL_DIRECTORY "${Python_STDLIB}")
endif()
if(NOT MACHINEKIT_HAL_PYTHON_PURELIB_FULL_INSTALL_DIRECTORY)
set(MACHINEKIT_HAL_PYTHON_PURELIB_FULL_INSTALL_DIRECTORY
"${Python_SITELIB}")
endif()
if(NOT MACHINEKIT_HAL_PYTHON_PLATSTDLIB_FULL_INSTALL_DIRECTORY)
set(MACHINEKIT_HAL_PYTHON_PLATSTDLIB_FULL_INSTALL_DIRECTORY
"${Python_STDARCH}")
endif()
if(NOT MACHINEKIT_HAL_PYTHON_PLATLIB_FULL_INSTALL_DIRECTORY)
set(MACHINEKIT_HAL_PYTHON_PLATLIB_FULL_INSTALL_DIRECTORY
"${Python_SITEARCH}")
endif()
if(NOT MACHINEKIT_HAL_PYTHON_INCLUDE_FULL_INSTALL_DIRECTORY)
set(MACHINEKIT_HAL_PYTHON_INCLUDE_FULL_INSTALL_DIRECTORY
"${Python_INCLUDE_DIRS}")
endif()
if(NOT MACHINEKIT_HAL_PYTHON_PLATINCLUDE_FULL_INSTALL_DIRECTORY)
set(MACHINEKIT_HAL_PYTHON_PLATINCLUDE_FULL_INSTALL_DIRECTORY
"${Python_INCLUDE_DIRS}")
endif()
if(NOT MACHINEKIT_HAL_PYTHON_SCRIPTS_FULL_INSTALL_DIRECTORY)
set(MACHINEKIT_HAL_PYTHON_SCRIPTS_FULL_INSTALL_DIRECTORY
"${MACHINEKIT_HAL_EXECUTABLE_FULL_INSTALL_DIRECTORY}")
endif()
if(NOT MACHINEKIT_HAL_PYTHON_DATA_FULL_INSTALL_DIRECTORY)
set(MACHINEKIT_HAL_PYTHON_DATA_FULL_INSTALL_DIRECTORY
"${CMAKE_INSTALL_PREFIX}")
endif()

# Create a simple PEP503 conforming local Python index
if(NOT MACHINEKIT_HAL_PYTHON_INDEX)
set(MACHINEKIT_HAL_PYTHON_INDEX
"${CMAKE_BINARY_DIR}/$<CONFIG>/python_index")
endif()
include(PEP503PythonIndex)
endif()

add_subdirectory(libraries)
add_subdirectory(executables)
add_subdirectory(modules)

# Terrible, ugly and hopefully temporary hack
add_subdirectory(${CMAKE_SOURCE_DIR}/tests ${CMAKE_BINARY_DIR}/tests)
12 changes: 12 additions & 0 deletions src/executables/bitfile/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if(BUILD_PYTHON_DISTRIBUTIONS)

if(BUILD_BITFILE_EXECUTABLE)
find_program(PYPROJECT_BUILD "pyproject-build" REQUIRED)
include(PEP427Installer)

set(PACKAGE_NAME "bitfile")

Expand Down Expand Up @@ -72,5 +73,16 @@ if(BUILD_PYTHON_DISTRIBUTIONS)
COMMAND ${PYPROJECT_BUILD} -s -w -o ${OUTPUT_INDEX}
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}
COMMENT "Building Python package ${DISTRIBUTION_NAME} via external tool")

install_wheel(WHEEL "${OUTPUT_INDEX}" COMPONENT
MachinekitHAL_Executable_Bitfile_Python_Packages)

cpack_add_component(MachinekitHAL_Executable_Bitfile_Python_Packages
GROUP MachinekitHAL_Executable_Bitfile)

# Specification of artifacts placement in package tree
cpack_add_component_group(
MachinekitHAL_Executable_Bitfile
PARENT_GROUP MachinekitHAL_Package_Base_Python_Executables)
endif()
endif()
2 changes: 1 addition & 1 deletion src/executables/bitfile/src/pyproject.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ documentation = "https://machinekit.io"
repository = "https://github.com/machinekit/machinekit-hal"

[project.scripts]
comp = "machinekit.hal.bitfile:cli"
bitfile = "machinekit.hal.bitfile:cli"

[tool]
[tool.pdm]
Expand Down
12 changes: 12 additions & 0 deletions src/executables/comp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if(BUILD_PYTHON_DISTRIBUTIONS)
if(BUILD_COMP_EXECUTABLE)
find_program(YAPPS2 "yapps2" REQUIRED)
find_program(PYPROJECT_BUILD "pyproject-build" REQUIRED)
include(PEP427Installer)

set(PACKAGE_NAME "comp")

Expand Down Expand Up @@ -77,5 +78,16 @@ if(BUILD_PYTHON_DISTRIBUTIONS)
COMMAND ${PYPROJECT_BUILD} -s -w -o ${OUTPUT_INDEX}
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}
COMMENT "Building Python package ${DISTRIBUTION_NAME} via external tool")

install_wheel(WHEEL "${OUTPUT_INDEX}" COMPONENT
MachinekitHAL_Executable_Comp_Python_Packages)

cpack_add_component(MachinekitHAL_Executable_Comp_Python_Packages
GROUP MachinekitHAL_Executable_Comp)

# Specification of artifacts placement in package tree
cpack_add_component_group(
MachinekitHAL_Executable_Comp
PARENT_GROUP MachinekitHAL_Package_Base_Python_Executables)
endif()
endif()
38 changes: 38 additions & 0 deletions src/executables/fix_uuid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,41 @@
#
# #####################################################################
# ~~~

option(BUILD_FIX_UUID_EXECUTABLE "Build the Fix UUID executable." TRUE)

if(BUILD_FIX_UUID_EXECUTABLE)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/fix-uuid
${CMAKE_CURRENT_BINARY_DIR}/src/fix-uuid
FILE_PERMISSIONS
OWNER_READ
OWNER_EXECUTE
GROUP_READ
GROUP_EXECUTE
WORLD_READ
WORLD_EXECUTE
@ONLY
NEWLINE_STYLE UNIX)

add_custom_target(
fix_uuid ALL
COMMENT "Creating the Fix UUID executable"
COMMAND
${CMAKE_COMMAND} "-E" "copy_if_different"
"${CMAKE_CURRENT_BINARY_DIR}/src/fix-uuid"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/src/fix-uuid")

install(
PROGRAMS "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fix-uuid"
DESTINATION "${MACHINEKIT_HAL_EXECUTABLE_DIRECTORY}"
COMPONENT MachinekitHAL_Executable_Fix_UUID_Binaries)

cpack_add_component(MachinekitHAL_Executable_Fix_UUID_Binaries
GROUP MachinekitHAL_Executable_Fix_UUID)

# Specification of artifacts placement in package tree
cpack_add_component_group(MachinekitHAL_Executable_Fix_UUID
PARENT_GROUP MachinekitHAL_Package_Base_Executables)
endif()
17 changes: 16 additions & 1 deletion src/executables/instcomp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
# ~~~

if(BUILD_PYTHON_DISTRIBUTIONS)
find_package(Python COMPONENTS Interpreter)
find_package(
Python
COMPONENTS Interpreter
REQUIRED)
option(BUILD_INSTCOMP_EXECUTABLE
"Built the Instcomp executable Python distribution." TRUE)

if(BUILD_INSTCOMP_EXECUTABLE)
find_program(YAPPS2 "yapps2" REQUIRED)
find_program(PYPROJECT_BUILD "pyproject-build" REQUIRED)
include(PEP427Installer)

set(PACKAGE_NAME "instcomp")

Expand Down Expand Up @@ -111,5 +115,16 @@ if(BUILD_PYTHON_DISTRIBUTIONS)
GLOBAL APPEND PROPERTY MACHINEKIT_HAL_MODULE_PATH
"${CMAKE_CURRENT_BINARY_DIR}/cmake_module")

install_wheel(WHEEL "${OUTPUT_INDEX}" COMPONENT
MachinekitHAL_Executable_Instcomp_Python_Packages)

cpack_add_component(MachinekitHAL_Executable_Instcomp_Python_Packages
GROUP MachinekitHAL_Executable_Instcomp)

# Specification of artifacts placement in package tree
cpack_add_component_group(
MachinekitHAL_Executable_Instcomp
PARENT_GROUP MachinekitHAL_Package_Base_Python_Executables)

endif()
endif()
Loading

0 comments on commit 4274b64

Please sign in to comment.