Skip to content

Commit ccf6e0b

Browse files
Clearer error message if cargo.toml is not found (#10)
* Clearer error message if cargo.toml is not found Currently if a `Cargo.toml` is missing or has the wrong name, the error message is not very clearly formatted. This PR will give a clear log output if `ament_cargo` is selected and we are missing a `Cargo.toml`. Signed-off-by: Arjo Chakravarty <[email protected]> Signed-off-by: Luca Della Vedova <[email protected]> Co-authored-by: Luca Della Vedova <[email protected]>
1 parent c9ca4c1 commit ccf6e0b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

colcon_ros_cargo/package_identification/ament_cargo.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Licensed under the Apache License, Version 2.0
22

3+
from catkin_pkg.package import parse_package
34
from colcon_cargo.package_identification.cargo \
45
import CargoPackageIdentification
6+
from colcon_core.logging import colcon_logger
57
from colcon_core.package_identification \
68
import PackageIdentificationExtensionPoint
79
from colcon_core.plugin_system import satisfies_version
810
from colcon_ros.package_identification.ros import _get_package
911

12+
logger = colcon_logger.getChild(__name__)
13+
1014

1115
class AmentCargoPackageIdentification(CargoPackageIdentification):
1216
"""Identify Cargo packages with `Cargo.toml` and `package.xml` files."""
@@ -20,17 +24,25 @@ def __init__(self): # noqa: D107
2024
'^1.0')
2125

2226
def identify(self, metadata): # noqa: D102
23-
if metadata.type is not None and metadata.type != 'ament_cargo':
24-
return
2527

26-
cargo_toml = metadata.path / 'Cargo.toml'
27-
if not cargo_toml.is_file():
28+
if metadata.type is not None and metadata.type != 'ament_cargo':
2829
return
2930

3031
package_xml = metadata.path / 'package.xml'
3132
if not package_xml.is_file():
3233
return
3334

35+
pkg_desc = parse_package(package_xml)
36+
37+
if pkg_desc.get_build_type() != 'ament_cargo':
38+
return
39+
40+
cargo_toml = metadata.path / 'Cargo.toml'
41+
if not cargo_toml.is_file():
42+
logger.warn(
43+
'Got build type ament_cargo but could not find "Cargo.toml"')
44+
return
45+
3446
metadata.type = 'ament_cargo'
3547
pkg = _get_package(str(metadata.path))
3648

0 commit comments

Comments
 (0)