Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions ament_cmake_python/cmake/ament_python_install_module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# :param DESTINATION_SUFFIX: the base package to install the module to
# (default: empty, install as a top level module)
# :type DESTINATION_SUFFIX: string
# :param SKIP_COMPILE: if set do not compile the installed module
# :param SKIP_COMPILE: if set do not byte-compile the installed module
# :type SKIP_COMPILE: option
#
macro(ament_python_install_module)
Expand Down Expand Up @@ -60,12 +60,14 @@ function(_ament_cmake_python_install_module module_file)
get_filename_component(module_file "${module_file}" NAME)
if(NOT ARG_SKIP_COMPILE)
get_executable_path(python_interpreter Python3::Interpreter CONFIGURE)
set(_bytecompile_target "\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${ARG_DESTINATION}/${module_file}")
# compile Python files
install(CODE
"execute_process(
"message(STATUS \"Byte-compiling: ${_bytecompile_target}\")
execute_process(
COMMAND
\"${python_interpreter}\" \"-m\" \"compileall\"
\"${CMAKE_INSTALL_PREFIX}/${destination}/${module_file}\"
\"${python_interpreter}\" \"-m\" \"compileall\" \"-q\"
\"${_bytecompile_target}\"
)"
)
endif()
Expand Down
8 changes: 5 additions & 3 deletions ament_cmake_python/cmake/ament_python_install_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,14 @@ setup(

if(NOT ARG_SKIP_COMPILE)
get_executable_path(python_interpreter_config Python3::Interpreter CONFIGURE)
set(_bytecompile_target "\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${ARG_DESTINATION}/${package_name}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about generating the code at build time and then using install()

# compile Python files
install(CODE
"execute_process(
"message(STATUS \"Byte-compiling: ${_bytecompile_target}\")
execute_process(
COMMAND
\"${python_interpreter_config}\" \"-m\" \"compileall\"
\"${CMAKE_INSTALL_PREFIX}/${ARG_DESTINATION}/${package_name}\"
\"${python_interpreter_config}\" \"-m\" \"compileall\" \"-q\"
\"${_bytecompile_target}\"
)"
)
endif()
Expand Down