Skip to content

Commit

Permalink
[bazel_ros2_rules] Handle cmake failures in dependent packages
Browse files Browse the repository at this point in the history
CMake fails for many packages in the default ros2 humble install,
leaving expected api query results empty. This handles the failure and
surfaces the name of the failing package for investigation.

In order to artificially generate errors, leave `include_packages` empty
in a `ros2_local_repository` instance to pull in all installed packages.
Many will have cmake failures.
  • Loading branch information
abrandemuehl committed Sep 17, 2023
1 parent 1d59967 commit b943996
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion bazel_ros2_rules/ros2/resources/cmake_tools/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def get_cmake_codemodel(project_path: Path, build_path: Path) -> CodeModel:
query_path.joinpath('codemodel-v2').touch()

args = ['cmake', str(project_path)]
subprocess.run(args, cwd=str(build_path))
result = subprocess.run(args, cwd=str(build_path))
if result.returncode != 0:
raise RuntimeError("CMake error occurred on project. See build logs")

# There should only be one file, but just in case the latest is the
# largest file in lexicographic order.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ def collect_ament_cmake_package_properties(name, metadata):
project_path = Path(project_path)
build_path = project_path.joinpath('build')
build_path.mkdir()
codemodel = cmake_tools.get_cmake_codemodel(project_path, build_path)
try:
codemodel = cmake_tools.get_cmake_codemodel(project_path, build_path)
except RuntimeError as e:
raise RuntimeError(f"Error occured while generating build for {name}")

# Should only be one SHARED_LIBRARY target
target = None
Expand Down

0 comments on commit b943996

Please sign in to comment.