diff --git a/colcon_cargo/package_identification/cargo.py b/colcon_cargo/package_identification/cargo.py index d93e261..3ba345c 100644 --- a/colcon_cargo/package_identification/cargo.py +++ b/colcon_cargo/package_identification/cargo.py @@ -50,6 +50,8 @@ def identify(self, metadata): # noqa: D102 metadata.type = 'cargo' if metadata.name is None: metadata.name = data['name'] + metadata.metadata['version'] = data['version'] + metadata.dependencies['build'] |= data['depends'] metadata.dependencies['run'] |= data['depends'] @@ -78,6 +80,7 @@ def extract_data(cargo_toml): toml_name_attr = extract_project_name(content) data['name'] = toml_name_attr if toml_name_attr is not None else \ cargo_toml.parent.name + data['version'] = extract_project_version(content) depends = extract_dependencies(content) # exclude self references @@ -100,6 +103,20 @@ def extract_project_name(content): return None +def extract_project_version(content): + """ + Extract the Cargo project version from the Cargo.toml file. + + :param str content: The Cargo.toml parsed dictionary + :returns: The project version, otherwise None + :rtype: str + """ + try: + return content['package']['version'] + except KeyError: + return None + + def extract_dependencies(content): """ Extract the dependencies from the Cargo.toml file.