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

Make ament_cmake_python_install() handle symlink installs. #325

Closed
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
120 changes: 74 additions & 46 deletions ament_cmake_python/cmake/ament_python_install_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function(_ament_cmake_python_install_package package_name)
endif()

set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/ament_cmake_python/${package_name}")
file(RELATIVE_PATH source_dir "${build_dir}" "${ARG_PACKAGE_DIR}")

if(ARG_NO_DATA)
string(CONFIGURE "\
Expand All @@ -83,9 +82,7 @@ setup(
name='${package_name}',
version='${ARG_VERSION}',
packages=find_packages(
where=os.path.normpath('${source_dir}/..'),
include=('${package_name}', '${package_name}.*')),
package_dir={'${package_name}': '${source_dir}'},
)
" setup_py_content)
else()
Expand All @@ -100,11 +97,8 @@ setup(
name='${package_name}',
version='${ARG_VERSION}',
packages=find_packages(
where=os.path.normpath('${source_dir}/..'),
include=('${package_name}', '${package_name}.*')),
package_dir={'${package_name}': '${source_dir}'},
package_data=find_packages_data(
where=os.path.normpath('${source_dir}/..'),
include=('${package_name}', '${package_name}.*'))
)
" setup_py_content)
Expand All @@ -116,52 +110,86 @@ setup(
)

if(ARG_SETUP_CFG)
add_custom_command(
OUTPUT "${build_dir}/setup.cfg"
COMMAND ${CMAKE_COMMAND} -E copy "${ARG_SETUP_CFG}" "${build_dir}/setup.cfg"
MAIN_DEPENDENCY "${ARG_SETUP_CFG}"
)
add_custom_target(${package_name}_setup ALL
DEPENDS "${build_dir}/setup.cfg"
add_custom_target(
ament_cmake_python_symlink_${package_name}_setup ALL
COMMAND ${CMAKE_COMMAND} -E create_symlink
"${ARG_SETUP_CFG}" "${build_dir}/setup.cfg"
)
endif()

if(NOT ARG_SKIP_COMPILE)
set(extra_install_args --compile)
add_custom_target(
ament_cmake_python_symlink_${package_name} ALL
COMMAND ${CMAKE_COMMAND} -E create_symlink
"${ARG_PACKAGE_DIR}" "${build_dir}/${package_name}"
)

set(install_dir "${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_DIR}")

if(NOT AMENT_CMAKE_SYMLINK_INSTALL)
# Install as flat Python egg to mimic https://github.com/colcon/colcon-core
# handling of pure Python packages for non-symlink installs.
if(NOT ARG_SKIP_COMPILE)
set(extra_install_args --compile)
else()
set(extra_install_args --no-compile)
endif()

# NOTE(hidmic): Allow setup.py install to build, as there is no way to
# determine the Python package's source dependencies for proper build
# invalidation.
install(CODE
"set(install_dir ${install_dir})
set(extra_install_args ${extra_install_args})
if(DEFINED ENV{DESTDIR} AND NOT \"\$ENV{DESTDIR}\" STREQUAL \"\")
list(APPEND extra_install_args --root \$ENV{DESTDIR})
file(TO_CMAKE_PATH \"\$ENV{DESTDIR}/\${install_dir}\" install_dir)
endif()
message(STATUS
\"Installing: ${package_name} as flat Python egg under \${install_dir}\")
file(TO_NATIVE_PATH \"${CMAKE_INSTALL_PREFIX}\" install_prefix)
file(TO_NATIVE_PATH \"${CMAKE_INSTALL_PREFIX}/bin\" install_scripts_dir)
execute_process(
COMMAND
\"${PYTHON_EXECUTABLE}\" setup.py install
--single-version-externally-managed
--install-scripts \${install_scripts_dir}
--prefix \${install_prefix}
--record install.log
\${extra_install_args}
WORKING_DIRECTORY \"${build_dir}\"
OUTPUT_QUIET
)"
)
else()
set(extra_install_args --no-compile)
# Install as Python egg link to mimic https://github.com/colcon/colcon-core
# handling of pure Python packages for symlink installs.
install(CODE
"message(STATUS
\"Symlinking: ${package_name} as flat Python egg under ${install_dir}\")
file(TO_NATIVE_PATH \"${CMAKE_INSTALL_PREFIX}\" install_prefix)
file(TO_NATIVE_PATH \"${CMAKE_INSTALL_PREFIX}/bin\" install_scripts_dir)
execute_process(
COMMAND
\"${PYTHON_EXECUTABLE}\" setup.py develop
--prefix \${install_prefix}
--script-dir \${install_scripts_dir}
--editable --no-deps
--build-directory build
WORKING_DIRECTORY \"${build_dir}\"
OUTPUT_QUIET
)
# NOTE(hidmic): ensure package can be found
# in and imported from the install space
execute_process(
COMMAND
\"${CMAKE_COMMAND}\" -E create_symlink
\"${build_dir}/${package_name}\"
\"${install_dir}/${package_name}\"
OUTPUT_QUIET
)"
)
endif()

# Install as flat Python .egg to mimic https://github.com/colcon/colcon-core
# handling of pure Python packages.

# NOTE(hidmic): Allow setup.py install to build, as there is no way to
# determine the Python package's source dependencies for proper build
# invalidation.
install(CODE
"set(extra_install_args ${extra_install_args})
set(install_dir \"${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_DIR}\")
if(DEFINED ENV{DESTDIR} AND NOT \"\$ENV{DESTDIR}\" STREQUAL \"\")
list(APPEND extra_install_args --root \$ENV{DESTDIR})
file(TO_CMAKE_PATH \"\$ENV{DESTDIR}/\${install_dir}\" install_dir)
endif()
message(STATUS
\"Installing: ${package_name} as flat Python egg under \${install_dir}\")
file(TO_NATIVE_PATH \"${CMAKE_INSTALL_PREFIX}\" install_prefix)
file(TO_NATIVE_PATH \"${CMAKE_INSTALL_PREFIX}/bin\" scripts_install_dir)
execute_process(
COMMAND
\"${PYTHON_EXECUTABLE}\" setup.py install
--single-version-externally-managed
--install-scripts \${scripts_install_dir}
--prefix \${install_prefix}
--record install.log
\${extra_install_args}
WORKING_DIRECTORY \"${build_dir}\"
OUTPUT_QUIET
)"
)

if(package_name IN_LIST AMENT_CMAKE_PYTHON_INSTALL_INSTALLED_NAMES)
message(FATAL_ERROR
"ament_python_install_package() a Python module file or package with "
Expand Down