@@ -1009,7 +1009,173 @@ def tue_install_dpkg_now(self, pkg_file: str) -> bool:
10091009 tue_install_dpkg = tue_install_dpkg_now
10101010
10111011 def tue_install_ros (self , source_type : str , ** kwargs ) -> bool :
1012- return True
1012+ self .tue_install_debug (f"tue-install-ros { source_type = } { kwargs = } " )
1013+
1014+ if not source_type :
1015+ self .tue_install_error ("Invalid tue-install-ros call: needs source type as argument" )
1016+ # ToDo: This depends on behaviour of tue-install-error
1017+ return False
1018+
1019+ TUE_ROS_DISTRO = os .getenv ("TUE_ROS_DISTRO" , None )
1020+ if not TUE_ROS_DISTRO :
1021+ self .tue_install_error ("TUE_ROS_DISTRO is not set" )
1022+ # ToDo: This depends on behaviour of tue-install-error
1023+ return False
1024+ TUE_ROS_VERSION = os .getenv ("TUE_ROS_VERSION" , None )
1025+ if not TUE_ROS_VERSION :
1026+ self .tue_install_error ("TUE_ROS_VERSION is not set" )
1027+ # ToDo: This depends on behaviour of tue-install-error
1028+ return False
1029+
1030+ ros_pkg_name = self ._current_target .lstrip ("ros-" )
1031+ if "-" in ros_pkg_name :
1032+ correct_ros_pkg_name = ros_pkg_name .replace ("-" , "_" )
1033+ self .tue_install_error (f"A ROS package cannot contain dashes ({ ros_pkg_name } ), "
1034+ f"make sure the package is named '{ correct_ros_pkg_name } ' and rename the "
1035+ f"target to 'ros-{ correct_ros_pkg_name } '" )
1036+ # ToDo: This depends on behaviour of tue-install-error
1037+ return False
1038+
1039+ # First of all, make sure ROS itself is installed
1040+ if not self .tue_install_target (f"ros{ TUE_ROS_VERSION } " ):
1041+ self .tue_install_error (f"Failed to install ros{ TUE_ROS_VERSION } " )
1042+
1043+ if source_type == "system" :
1044+ """
1045+ Install a ROS package from the system repository
1046+ kwargs:
1047+ - name: The name of the package to install
1048+ """
1049+ name = kwargs ["name" ]
1050+ if name is None :
1051+ self .tue_install_error ("Invalid tue-install-ros call(system): needs src as argument" )
1052+ self .tue_install_debug (f"tue-install-system ros-{ TUE_ROS_DISTRO } -{ src } " )
1053+ if not self .tue_install_system (["ros-{TUE_ROS_DISTRO}-{src}" ]):
1054+ self .tue_install_error (f"Failed to append ros-{ TUE_ROS_DISTRO } -{ src } " )
1055+ # ToDo: This depends on behaviour of tue-install-error
1056+ return False
1057+
1058+ return True
1059+
1060+ if source_type != "git" :
1061+ self .tue_install_error (f"Unknown ROS source type: { source_type } " )
1062+ # ToDo: This depends on behaviour of tue-install-error
1063+ return False
1064+
1065+ """
1066+ Install a ROS package from a git repository
1067+ kwargs:
1068+ - url: The git repository to clone
1069+ - sub_dir (optional): The subdirectory of the repository to install
1070+ - version (optional): The version of the package to install
1071+ - target_dir (optional): The directory to install the package to
1072+ """
1073+
1074+ url = kwargs ["url" ]
1075+ if url is None :
1076+ self .tue_install_error ("Invalid tue-install-ros call(git): needs url as argument" )
1077+
1078+ sub_dir = kwargs ["sub_dir" ]
1079+ version = kwargs ["version" ]
1080+ target_dir = kwargs ["target_dir" ]
1081+
1082+ TUE_SYSTEM_DIR = os .getenv ("TUE_SYSTEM_DIR" , None )
1083+ if not TUE_SYSTEM_DIR :
1084+ self .tue_install_error ("ROS_PACKAGE_INSTALL_DIR is not set" )
1085+ # ToDo: This depends on behaviour of tue-install-error
1086+ return False
1087+
1088+ # Make sure the ROS package install dir exists
1089+ ROS_PACKAGE_INSTALL_DIR = os .path .join (TUE_SYSTEM_DIR , "src" )
1090+ if not os .path .isdir (ROS_PACKAGE_INSTALL_DIR ):
1091+ self .tue_install_error (f"ROS_PACKAGE_INSTALL_DIR is not a directory: { ROS_PACKAGE_INSTALL_DIR } " )
1092+ # ToDo: This depends on behaviour of tue-install-error
1093+ return False
1094+
1095+
1096+
1097+ # If repos_dir is not set, try generating the default path from git url
1098+ if target_dir is None :
1099+ # ToDo: convert _git_url_to_repos_dir to python
1100+ target_dir = sp .check_output (f"bash -c '_git_url_to_repos_dir { url } '" , text = True ).strip ()
1101+ if not target_dir :
1102+ self .tue_install_error (f"Could not create target_dir path from the git url: '{ url } '" )
1103+ # ToDo: This depends on behaviour of tue-install-error
1104+ return False
1105+
1106+ self .tue_install_debug (f"{ target_dir = } " )
1107+
1108+ ros_pkg_dir = os .path .join (ROS_PACKAGE_INSTALL_DIR , ros_pkg_name )
1109+
1110+ if not self .tue_install_git (url , target_dir , version ):
1111+ self .tue_install_error (f"Failed to clone ros package '{ ros_pkg_name } ' from '{ url } '" )
1112+
1113+ if not os .path .isdir (target_dir ):
1114+ if not os .path .isdir (os .path .join (target_dir , sub_dir )):
1115+ self .tue_install_error (f"Subdirectory '{ sub_dir } ' does not exist for url '{ url } '" )
1116+ # ToDo: This depends on behaviour of tue-install-error
1117+ return False
1118+
1119+ # Test if the current symbolic link points to the same repository dir. If not, give a warning
1120+ # because it means the source URL has changed
1121+ if os .path .islink (ros_pkg_dir ):
1122+ if os .path .realpath (ros_pkg_dir ) != os .path .realpath (os .path .join (target_dir , sub_dir )):
1123+ self .tue_install_info (f"url has changed to { url } /{ sub_dir } " )
1124+ os .remove (ros_pkg_dir )
1125+ os .symlink (os .path .join (target_dir , sub_dir ), ros_pkg_dir )
1126+ elif os .path .isdir (ros_pkg_dir ):
1127+ self .tue_install_error (f"Can not create a symlink at '{ ros_pkg_dir } ' as it is a directory" )
1128+ # ToDo: This depends on behaviour of tue-install-error
1129+ return False
1130+ elif not os .path .exists (ros_pkg_dir ):
1131+ os .symlink (os .path .join (target_dir , sub_dir ), ros_pkg_dir )
1132+ else :
1133+ self .tue_install_error (f"'{ ros_pkg_dir } ' should not exist or be a symlink. "
1134+ "Aany other option is incorrect" )
1135+
1136+
1137+ if [- d "$repos_dir" ]
1138+ then
1139+
1140+
1141+ if [- L "$ros_pkg_dir" ]
1142+ then
1143+
1144+
1145+ if [["$TUE_INSTALL_SKIP_ROS_DEPS" != "all" ]]
1146+ then
1147+ local
1148+ pkg_xml = "$ros_pkg_dir" / package .xml
1149+ if [- f "$pkg_xml" ]
1150+ then
1151+ # Catkin
1152+ tue - install - debug
1153+ "Parsing $pkg_xml"
1154+ local
1155+ deps
1156+ deps = $("$TUE_INSTALL_SCRIPTS_DIR" / parse_package_xml .py "$pkg_xml" )
1157+ tue - install - debug
1158+ "Parsed package.xml\n $deps"
1159+
1160+ for dep in $deps
1161+ do
1162+ # Preference given to target name starting with ros-
1163+ tue - install - target ros - "$dep" | | tue - install - target "$dep" | | \
1164+ tue - install - error "Targets 'ros-$dep' and '$dep' don't exist"
1165+ done
1166+
1167+ else
1168+ tue - install - warning "Does not contain a valid ROS package.xml"
1169+ fi
1170+ else
1171+ tue - install - debug "No need to parse package.xml for dependencies"
1172+ fi
1173+
1174+ else
1175+ tue - install - error "Checking out $src was not successful."
1176+ fi
1177+
1178+ TUE_INSTALL_PKG_DIR = $ros_pkg_dir
10131179
10141180
10151181if __name__ == "__main__" :
0 commit comments