diff --git a/ros2caret/verb/check_caret_rclcpp.py b/ros2caret/verb/check_caret_rclcpp.py index 7a5025c7..0dcaf9fc 100644 --- a/ros2caret/verb/check_caret_rclcpp.py +++ b/ros2caret/verb/check_caret_rclcpp.py @@ -71,6 +71,7 @@ class RclcppCheck(): def __init__(self, root_dir_path: str) -> None: RclcppCheck._ensure_dir_exist(root_dir_path) + RclcppCheck._validate_ros_distribution(root_dir_path) get_package_name = RclcppCheck._create_get_package_name(root_dir_path) ros_obj_paths = RclcppCheck._get_obj_paths(root_dir_path) @@ -171,6 +172,15 @@ def _ensure_dir_exist(path: str): 'where the build command completed.') exit(1) + @staticmethod + def _validate_ros_distribution(path: str): + distribution = os.environ['ROS_DISTRO'] + if distribution[0] < 'i': + return + logger.info('There is no need to build packages ' + f'using caret-rclcpp under ROS 2 {distribution}.') + exit(0) + @staticmethod def get_package_name_from_path(root_dir_path: str, path: str) -> str: package_name = path.replace(root_dir_path, '').split('/')[0] diff --git a/test/verb/test_check_caret_rclcpp.py b/test/verb/test_check_caret_rclcpp.py index 84bdeabc..962a68f5 100644 --- a/test/verb/test_check_caret_rclcpp.py +++ b/test/verb/test_check_caret_rclcpp.py @@ -21,6 +21,8 @@ class TestCheckCaretRclcpp: def test_file_exist(self, caplog, mocker): mocker.patch('os.path.exists', return_value=True) + mocker.patch('ros2caret.verb.check_caret_rclcpp.RclcppCheck._validate_ros_distribution', + return_value=None) mocker.patch( 'ros2caret.verb.check_caret_rclcpp.RclcppCheck._get_obj_paths', return_value=[]) RclcppCheck('') @@ -30,6 +32,8 @@ def test_file_exist(self, caplog, mocker): def test_ng_case(self, caplog, mocker): mocker.patch('os.path.exists', return_value=True) + mocker.patch('ros2caret.verb.check_caret_rclcpp.RclcppCheck._validate_ros_distribution', + return_value=None) base_path = 'ros2caret.verb.check_caret_rclcpp.RclcppCheck.' mocker.patch(base_path+'_get_obj_paths', return_value=['']) mocker.patch(base_path+'_has_caret_rclcpp_tp', return_value=False) @@ -40,6 +44,8 @@ def test_ng_case(self, caplog, mocker): assert record.levelno == WARNING def test_ok_case(self, caplog, mocker): + mocker.patch('ros2caret.verb.check_caret_rclcpp.RclcppCheck._validate_ros_distribution', + return_value=None) mocker.patch('os.path.exists', return_value=True) base_path = 'ros2caret.verb.check_caret_rclcpp.RclcppCheck.' mocker.patch(base_path+'_get_obj_paths', return_value=['']) @@ -69,3 +75,14 @@ def test_get_package_name(self): get_package_name = RclcppCheck._create_get_package_name('foo/bar/') assert get_package_name('foo/bar/baz') == 'baz' + + def test_validate_ros_distribution(self, mocker, caplog): + mocker.patch('os.path.exists', return_value=True) + mocker.patch.dict('os.environ', {'ROS_DISTRO': 'iron'}) + + try: + RclcppCheck('') + except SystemExit: + assert len(caplog.records) == 1 + assert 'There is no need to build packages ' \ + 'using caret-rclcpp under ROS 2 iron.' in caplog.messages[0]