Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Validates and formats `package.xml` files to enforce consistency and ROS 2 schem
- Launch-File Dependency Validation
- Scans Python (.py), YAML (.yaml/.yml), and XML (.xml) launch files for package references
- validates and corrects that all referenced pkgs are declared in the package xml (as `<exec_depend>` or `<depend>`)
- similarly the test folder is parsed to extract missing `<test_depend>` dependencies
- Rosdep Key Checking
- verifies that all declared pkgs exist as rodsdep key (optional)
- CMakeFile Comparison and Synchronization
Expand Down
2 changes: 1 addition & 1 deletion package_xml_validation/helpers/pkg_xml_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def retrieve_build_dependencies(self, root):
def retrieve_test_dependencies(self, root):
"""Retrieve all test dependencies from the XML file."""
test_dependencies = []
test_deps = ["test_depend"]
test_deps = ["test_depend", "depend"]
for elem in root:
if isinstance(elem.tag, str) and elem.tag in test_deps and elem.text:
test_dependencies.append(elem.text.strip())
Expand Down
91 changes: 55 additions & 36 deletions package_xml_validation/package_xml_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ def validate_xml_with_xmllint(self, xml_file):
return False

def validate_launch_dependencies(
self, root, package_xml_file: str, package_name: str, exec_deps: List[str]
self,
root,
package_xml_file: str,
package_name: str,
exec_deps: List[str],
test_deps: List[str] = [],
):
"""Validate launch dependencies in the package.xml file."""

Expand All @@ -176,44 +181,57 @@ def extract_launch_deps(folder_names: List[str]) -> List[str]:
launch_deps.extend(scan_files(launch_dir))
return launch_deps

launch_folder_names = ["launch", "components"]
launch_deps = extract_launch_deps(launch_folder_names)
if not launch_deps:
self.logger.debug(
f"No launch dependencies found in {package_name}/package.xml."
)
return True

missing_deps = [
dep for dep in launch_deps if dep not in exec_deps and dep != package_name
]
if missing_deps:
sep = "\n\t - "
self.logger.warning(
f"Missing launch dependencies in {package_name}/package.xml: {sep}{sep.join(missing_deps)}"
)

if self.check_only:
return False
else:
self.logger.info(
f"Auto-filling {len(missing_deps)} missing launch dependencies in {package_name}/package.xml."
def validate_launch_folders(
launch_folder_names: List[str], xml_deps: List[str], depend_tag: str
) -> bool:
launch_deps = extract_launch_deps(launch_folder_names)
if not launch_deps:
self.logger.debug(
f"No launch dependencies found in {package_name}/package.xml."
)
return True

missing_deps = [
dep
for dep in launch_deps
if dep not in xml_deps and dep != package_name
]
if missing_deps:
sep = "\n\t - "
self.logger.warning(
f"Missing <{depend_tag}> dependencies in {package_name}/package.xml: {sep}{sep.join(missing_deps)}"
)
# before adding dependencies make sure they are valid rosdeps
if self.check_rosdeps:
invalid_deps = self.rosdep_validator.check_rosdeps_and_local_pkgs(
missing_deps

if self.check_only:
return False
else:
self.logger.info(
f"Auto-filling {len(missing_deps)} missing <{depend_tag}> dependencies in {package_name}/package.xml."
)
valid_deps = [d for d in missing_deps if d not in invalid_deps]
if invalid_deps:
self.logger.error(
f"Cannot auto-fill invalid launch dependencies: {', '.join(invalid_deps)}"
# before adding dependencies make sure they are valid rosdeps
if self.check_rosdeps:
invalid_deps = (
self.rosdep_validator.check_rosdeps_and_local_pkgs(
missing_deps
)
)
return False
missing_deps = valid_deps
self.formatter.add_dependencies(root, missing_deps, "exec_depend")
return False
return True
valid_deps = [d for d in missing_deps if d not in invalid_deps]
if invalid_deps:
self.logger.error(
f"Cannot auto-fill invalid launch dependencies: {', '.join(invalid_deps)}"
)
return False
missing_deps = valid_deps
self.formatter.add_dependencies(root, missing_deps, depend_tag)
return False
return True

launch_folder_names = ["launch", "components"]
launch_deps_valid = validate_launch_folders(
launch_folder_names, exec_deps, "exec_depend"
)
test_deps_valid = validate_launch_folders(["test"], test_deps, "test_depend")
return launch_deps_valid and test_deps_valid

def validate_ament_exports(self, root, xml_file: str):
"""Validate ament_export tags in the package.xml file.
Expand Down Expand Up @@ -359,6 +377,7 @@ def check_and_format_files(self, package_xml_files):
xml_file,
self.formatter.get_package_name(root),
self.formatter.retrieve_exec_dependencies(root),
self.formatter.retrieve_test_dependencies(root),
)

self.perform_check(
Expand Down