Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements to ament_python_install_package #372

Open
wants to merge 7 commits into
base: rolling
Choose a base branch
from
Open
Changes from 6 commits
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
35 changes: 12 additions & 23 deletions ament_cmake_python/cmake/ament_python_install_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# directory (default: PYTHON_INSTALL_DIR)
# :type DESTINATION: string
# :param SCRIPTS_DESTINATION: the path to the Python package scripts'
# installation directory, scripts (if any) will be ignored if not set
# installation directory (default: lib/${PROJECT_NAME})
# :type SCRIPTS_DESTINATION: string
# :param SKIP_COMPILE: if set do not byte-compile the installed package
# :type SKIP_COMPILE: option
Expand All @@ -41,7 +41,7 @@ endmacro()

function(_ament_cmake_python_install_package package_name)
cmake_parse_arguments(
ARG "SKIP_COMPILE" "PACKAGE_DIR;VERSION;SETUP_CFG;DESTINATION;SCRIPTS_DESTINATION" "" ${ARGN})
ARG "SKIP_COMPILE" "PACKAGE_DIR;VERSION;SETUP_CFG;DESTINATION" "SCRIPTS_DESTINATION" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "ament_python_install_package() called with unused "
"arguments: ${ARG_UNPARSED_ARGUMENTS}")
Expand Down Expand Up @@ -83,6 +83,10 @@ function(_ament_cmake_python_install_package package_name)
set(ARG_DESTINATION ${PYTHON_INSTALL_DIR})
endif()

if(NOT ARG_SCRIPTS_DESTINATION)
set(ARG_SCRIPTS_DESTINATION "lib/${PROJECT_NAME}")
endif()

set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/ament_cmake_python/${package_name}")

string(CONFIGURE "\
Expand Down Expand Up @@ -156,27 +160,12 @@ setup(
DESTINATION "${ARG_DESTINATION}/${egg_install_name}.egg-info"
)

if(ARG_SCRIPTS_DESTINATION)
file(MAKE_DIRECTORY "${build_dir}/scripts") # setup.py may or may not create it

add_custom_target(
ament_cmake_python_build_${package_name}_scripts ALL
COMMAND ${python_interpreter} setup.py install_scripts -d scripts
WORKING_DIRECTORY "${build_dir}"
DEPENDS ${egg_dependencies}
)

if(NOT AMENT_CMAKE_SYMLINK_INSTALL)
# Not needed for nor supported by symlink installs
set(_extra_install_args USE_SOURCE_PERMISSIONS)
endif()

install(
DIRECTORY "${build_dir}/scripts/"
DESTINATION "${ARG_SCRIPTS_DESTINATION}/"
${_extra_install_args}
)
endif()
# generate/install entry-point console scripts
foreach(_dest ${ARG_SCRIPTS_DESTINATION})
get_filename_component(ABS_SCRIPTS_DESTINATION "${_dest}" ABSOLUTE BASE_DIR "${CMAKE_INSTALL_PREFIX}")
install(CODE "execute_process(COMMAND ${python_interpreter} setup.py install_scripts --install-dir \"${ABS_SCRIPTS_DESTINATION}\"
Copy link
Contributor

Choose a reason for hiding this comment

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

${python_interpreter} comes from

get_executable_path(python_interpreter Python3::Interpreter BUILD)

The BUILD argument will result in the path being a generator expression:

set(output_var "$<TARGET_PROPERTY:${target_or_path},LOCATION>")

A workaround to make the install(CODE warnings go away is to call get_executable_path again with the CONFIGURE arugment.

 get_executable_path(python_interpreter_config Python3::Interpreter CONFIGURE)
 # ...
install(CODE "execute_process(COMMAND ${python_interpreter} setup.py ...

The same workaround is already used a little lower in the file

get_executable_path(python_interpreter_config Python3::Interpreter CONFIGURE)
# compile Python files
install(CODE
"execute_process(
COMMAND
\"${python_interpreter_config}\" \"-m\" \"compileall\"
\"${CMAKE_INSTALL_PREFIX}/${ARG_DESTINATION}/${package_name}\"
)"
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot for this valuable hint. I adapted the code accordingly - sorry for the long delay.
Should be ready for merging now.

WORKING_DIRECTORY \"${build_dir}\")")
endforeach()

install(
DIRECTORY "${ARG_PACKAGE_DIR}/"
Expand Down