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 5 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
38 changes: 16 additions & 22 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,28 +160,18 @@ 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}
)
if(POLICY CMP0087)
# Allow generator expressions in install(CODE...)
cmake_policy(SET CMP0087 NEW)
Copy link
Contributor

Choose a reason for hiding this comment

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

@rhaschke which generator expressions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't use generator expressions, but cmake complains about the unset CMP otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The warning is even reported by CI: https://ci.ros2.org/job/ci_linux/16094/cmake/NORMAL

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I wonder if a generator expression is introduced by build_dir. Anyways, we need to cap that warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's what I did. How do you trigger Full CI on this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

How do you trigger Full CI on this PR?

Using our ci_launcher with a custom ros2.repos file (see https://ci.ros2.org/job/ci_launcher/9781).

Yes, that's what I did.

What's funny is that I run CI yesterday and there have not been changes to this PR in weeks. Maybe fe6b3a3 was not enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm really puzzled. Indeed, the previous builds didn't show the warning - although install(CODE ...) was already used:

# compile Python files
install(CODE

However, locally, the suggested change exactly silences the warning for me. I have no clue, why it fails on CI.
My suggestion is to drop it and retry.

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}/"
DESTINATION "${ARG_DESTINATION}/${package_name}"
Expand Down