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

Warn user if cargo ament build is not installed #31

Merged
Merged
Changes from all 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
29 changes: 29 additions & 0 deletions colcon_ros_cargo/package_identification/ament_cargo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Licensed under the Apache License, Version 2.0

import subprocess

from catkin_pkg.package import parse_package
from colcon_cargo.package_identification.cargo \
import CargoPackageIdentification
Expand Down Expand Up @@ -43,6 +45,16 @@ def identify(self, metadata): # noqa: D102
'Got build type ament_cargo but could not find "Cargo.toml"')
return

ament_build = 'cargo ament-build --help'.split()
if subprocess.run(ament_build, capture_output=True).returncode != 0:
if _print_ament_cargo_warning_once():
logger.error(
'\n\nament_cargo package found but cargo ament-build was '
'not detected.'
'\n\nPlease install it by running:'
'\n $ cargo install cargo-ament-build\n')
return

metadata.type = 'ament_cargo'
pkg = _get_package(str(metadata.path))

Expand All @@ -54,3 +66,20 @@ def identify(self, metadata): # noqa: D102
{dep.name for dep in pkg.run_depends}
metadata.dependencies['test'] = \
{dep.name for dep in pkg.test_depends}


def _print_ament_cargo_warning_once():
global has_printed_ament_cargo_warning
try:
# The following line will throw an exception if the global variable
# has never been initialized
has_printed_ament_cargo_warning
except NameError:
# We want to initialize the global variable to false the first time
has_printed_ament_cargo_warning = False

if not has_printed_ament_cargo_warning:
has_printed_ament_cargo_warning = True
return True

return False
Loading