Skip to content

Commit 0892c89

Browse files
committed
Add a wtf script to check if any packages are mistaken as catkin package.
1 parent 1d97c5f commit 0892c89

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
try:
3+
from colcon_core.plugin_system import get_package_identification_extensions
4+
except ImportError:
5+
from colcon_core.package_identification import get_package_identification_extensions
6+
from colcon_core.package_identification import identify, IgnoreLocationException
7+
from tuda_workspace_scripts.print import print_header, print_info, print_warn
8+
from tuda_workspace_scripts.workspace import get_packages_in_workspace, get_package_path
9+
import re
10+
import os
11+
12+
13+
def fix() -> tuple[int, int]:
14+
print_header("Checking ament_cmake packages for export")
15+
identification_extensions = get_package_identification_extensions()
16+
packages = get_packages_in_workspace()
17+
buildtool_regex = re.compile(
18+
r"<buildtool_depend>\s*([a-z0-9_]+)\s*</buildtool_depend>"
19+
)
20+
count_warnings = 0
21+
for package in packages:
22+
try:
23+
path = get_package_path(package)
24+
result = identify(identification_extensions, path)
25+
if result.type != "ros.catkin":
26+
continue
27+
with open(os.path.join(path, "package.xml"), "r") as f:
28+
content = f.read()
29+
30+
is_ament_cmake = any(
31+
[
32+
match.group(1) == "ament_cmake"
33+
for match in buildtool_regex.finditer(content)
34+
]
35+
)
36+
if is_ament_cmake:
37+
print_warn(
38+
f"Package {package} is ament_cmake but has no export tag. This leads to the package being incorrectly identified as catkin package which can cause further issues."
39+
)
40+
count_warnings += 1
41+
except IgnoreLocationException:
42+
continue
43+
if count_warnings == 0:
44+
print_info("All good.")
45+
return count_warnings, 0
46+
47+
48+
if __name__ == "__main__":
49+
fix()

scripts/wtf.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,42 @@ def main():
2424
print_workspace_error()
2525
return 1
2626

27+
count_problems = 0
2728
count_fixes = 0
2829
hooks = list(sorted(get_hooks_for_command("wtf"), key=basename))
2930
# Collect all wtf scripts in hooks/wtf folders of TUDA_WSS_SCRIPTS environment variable
3031
for script in hooks:
3132
# Load script and run fix command and obtain result
3233
if script.endswith(".py"):
3334
fix = load_method_from_file(script, "fix")
34-
count_fixes += fix()
35+
result = fix()
36+
if isinstance(result, tuple):
37+
count_problems += result[0]
38+
count_fixes += result[1]
39+
elif isinstance(result, int):
40+
count_problems += result
41+
count_fixes += result
42+
elif result is not None:
43+
print_error(f"Unknown return type from {script}: {type(result)}")
44+
continue
3545
elif script.endswith(".bash") or script.endswith(".sh"):
3646
executable = "bash" if script.endswith(".bash") else "sh"
3747
proc = subprocess.run([executable, script], cwd=get_workspace_root())
48+
count_problems += proc.returncode
3849
count_fixes += proc.returncode
3950
else:
4051
print_error(f"Unknown file type for hook: {script}")
4152
continue
42-
if count_fixes > 0:
43-
print_success(f"{len(hooks)} checks have fixed {count_fixes} potential issues.")
53+
if count_problems > 0:
54+
print_success(
55+
f"{len(hooks)} checks have fixed {count_fixes} out of {count_problems} potential issues."
56+
)
4457
else:
4558
print_success(f"{len(hooks)} checks have found no potential issues.")
59+
if count_problems > count_fixes:
60+
print_warn(
61+
f"{count_problems - count_fixes} issues could not be fixed automatically, please review these issues yourself."
62+
)
4663

4764

4865
if __name__ == "__main__":

0 commit comments

Comments
 (0)