Skip to content

Commit a8419ae

Browse files
committed
Only copy during build
Signed-off-by: Nadav Elkabets <[email protected]>
1 parent 143a498 commit a8419ae

File tree

1 file changed

+44
-66
lines changed

1 file changed

+44
-66
lines changed

ament_cmake_python/cmake/ament_python_install_registered_packages.cmake

Lines changed: 44 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Copyright 2025 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
114

215
function(ament_cmake_python_install_registered_packages)
316
get_property(_pkgs GLOBAL PROPERTY AMENT_CMAKE_PYTHON_PKGS)
@@ -12,7 +25,7 @@ function(_ament_cmake_python_install_package_impl package_name)
1225
endforeach()
1326

1427
_ament_cmake_python_prepare_build(${package_name})
15-
_ament_cmake_python_copy_or_symlink(${package_name})
28+
_ament_cmake_python_copy_build_files(${package_name})
1629

1730
# Technically, we should call find_package(Python3) first to ensure that Python3::Interpreter
1831
# is available. But we skip this here because this macro requires ament_cmake, and ament_cmake
@@ -55,79 +68,44 @@ setup(
5568

5669
endmacro()
5770

58-
macro(_ament_cmake_python_copy_or_symlink package_name)
71+
macro(_ament_cmake_python_copy_build_files package_name)
5972
set(_sync_target "ament_cmake_python_sync_${package_name}")
73+
set(_stage_dir "${_build_dir}/${package_name}")
74+
set(_stamp "${_stage_dir}/.sync_stamp")
75+
76+
set(_cmds "")
77+
78+
list(APPEND _cmds
79+
COMMAND ${CMAKE_COMMAND} -E remove_directory "${_stage_dir}")
6080

61-
set(_dsts "")
62-
set(_srcs "")
6381
foreach(_dir IN LISTS _PACKAGE_DIRS)
64-
file(GLOB_RECURSE _dir_files CONFIGURE_DEPENDS RELATIVE "${_dir}" "${_dir}/*")
65-
foreach(_rel IN LISTS _dir_files)
66-
set(_src "${_dir}/${_rel}")
67-
set(_dst "${_build_dir}/${package_name}/${_rel}")
68-
69-
list(FIND _dsts "${_dst}" _idx)
70-
if(NOT _idx EQUAL -1)
71-
list(REMOVE_AT _dsts ${_idx})
72-
list(REMOVE_AT _srcs ${_idx})
73-
endif()
74-
list(APPEND _dsts "${_dst}")
75-
list(APPEND _srcs "${_src}")
76-
endforeach()
82+
list(APPEND _cmds
83+
COMMAND ${CMAKE_COMMAND} -E copy_directory
84+
"${_dir}" "${_stage_dir}")
7785
endforeach()
7886

79-
set(_sync_deps "")
80-
list(LENGTH _dsts _len)
81-
if(_len GREATER 0)
82-
math(EXPR _last "${_len} - 1")
83-
foreach(_file_idx RANGE 0 ${_last})
84-
list(GET _dsts ${_file_idx} _dst)
85-
list(GET _srcs ${_file_idx} _src)
86-
87-
get_filename_component(_dst_parent "${_dst}" DIRECTORY)
88-
file(MAKE_DIRECTORY "${_dst_parent}")
89-
90-
if(AMENT_CMAKE_SYMLINK_INSTALL)
91-
add_custom_command(
92-
OUTPUT "${_dst}"
93-
COMMAND ${CMAKE_COMMAND} -E create_symlink "${_src}" "${_dst}"
94-
DEPENDS "${_src}"
95-
COMMENT "Symlinking ${_dst}"
96-
VERBATIM
97-
)
98-
else()
99-
add_custom_command(
100-
OUTPUT "${_dst}"
101-
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_src}" "${_dst}"
102-
DEPENDS "${_src}"
103-
COMMENT "Copying ${_dst}"
104-
VERBATIM
105-
)
106-
endif()
107-
list(APPEND _sync_deps "${_dst}")
108-
endforeach()
109-
endif()
110-
11187
if(_SETUP_CFG)
112-
set(_cfg_dst "${_build_dir}/setup.cfg")
113-
if(AMENT_CMAKE_SYMLINK_INSTALL)
114-
set(_copy_cmd ${CMAKE_COMMAND} -E create_symlink "${_SETUP_CFG}" "${_cfg_dst}")
115-
else()
116-
set(_copy_cmd ${CMAKE_COMMAND} -E copy_if_different "${_SETUP_CFG}" "${_cfg_dst}")
117-
endif()
118-
119-
add_custom_command(
120-
OUTPUT "${_cfg_dst}"
121-
COMMAND ${_copy_cmd}
122-
DEPENDS "${_SETUP_CFG}"
123-
COMMENT "Synchronising setup.cfg"
124-
VERBATIM
125-
)
126-
list(APPEND _sync_deps "${_cfg_dst}")
88+
list(APPEND _cmds
89+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
90+
"${_SETUP_CFG}" "${_build_dir}/setup.cfg")
12791
endif()
12892

129-
add_custom_target(${_sync_target} DEPENDS ${_sync_deps})
93+
foreach(_dir IN LISTS _PACKAGE_DIRS)
94+
list(APPEND _cmds
95+
COMMAND ${CMAKE_COMMAND} -E touch "${_dir}")
96+
endforeach()
97+
98+
list(APPEND _cmds
99+
COMMAND ${CMAKE_COMMAND} -E touch "${_stamp}")
100+
101+
add_custom_command(
102+
OUTPUT "${_stamp}"
103+
${_cmds}
104+
DEPENDS ${_PACKAGE_DIRS} ${_SETUP_CFG}
105+
COMMENT "Synchronising sources for ${package_name} (copy_directory)"
106+
VERBATIM)
130107

108+
add_custom_target(${_sync_target} DEPENDS "${_stamp}")
131109
endmacro()
132110

133111
macro(_ament_cmake_python_generate_egg package_name)
@@ -195,4 +173,4 @@ macro(_ament_cmake_python_byte_compile package_name)
195173
)
196174
endmacro()
197175

198-
ament_cmake_python_install_registered_packages()
176+
ament_cmake_python_install_registered_packages()

0 commit comments

Comments
 (0)