Skip to content

Commit

Permalink
fix: Fixed has target check taking ages for large projects
Browse files Browse the repository at this point in the history
The old implementation took up to 30 seconds for packages,
were a lot of targets existed. This is a common case for
interface packages containing a lot of messages.

Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>
  • Loading branch information
Janosch Machowinski authored and Janosch Machowinski committed Nov 7, 2024
1 parent 1509c77 commit 5ca3725
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion colcon_cmake/task/cmake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def has_target(path, target):
"""
generator = get_generator(path)
if 'Unix Makefiles' in generator:
return target in await get_makefile_targets(path)
return await get_makefile_has_targets(path, target)
if 'Ninja' in generator:
return target in get_ninja_targets(path)
if 'Visual Studio' in generator:
Expand All @@ -65,6 +65,11 @@ async def has_target(path, target):
"'has_target' not implemented for CMake generator '{generator}'" \
.format_map(locals())

async def get_makefile_has_targets(path, target):
output = subprocess.run([
CMAKE_EXECUTABLE, '--build', path, '--', '-n', target], stderr=subprocess.STDOUT, cwd=path).stdout

return output is None or not "No rule to make target" in output

async def get_makefile_targets(path):
"""
Expand Down

0 comments on commit 5ca3725

Please sign in to comment.