Skip to content

Commit 5523184

Browse files
committed
WIP tue-install-ros
1 parent 3678888 commit 5523184

File tree

1 file changed

+159
-1
lines changed

1 file changed

+159
-1
lines changed

src/tue_get/installer_impl.py

+159-1
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,165 @@ 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 [["$TUE_INSTALL_SKIP_ROS_DEPS" != "all"]]
1138+
then
1139+
local
1140+
pkg_xml = "$ros_pkg_dir" / package.xml
1141+
if [-f "$pkg_xml"]
1142+
then
1143+
# Catkin
1144+
tue - install - debug
1145+
"Parsing $pkg_xml"
1146+
local
1147+
deps
1148+
deps =$("$TUE_INSTALL_SCRIPTS_DIR" / parse_package_xml.py "$pkg_xml")
1149+
tue - install - debug
1150+
"Parsed package.xml\n$deps"
1151+
1152+
for dep in $deps
1153+
do
1154+
# Preference given to target name starting with ros-
1155+
tue-install-target ros-"$dep" | | tue-install-target "$dep" | | \
1156+
tue-install-error "Targets 'ros-$dep' and '$dep' don't exist"
1157+
done
1158+
1159+
else
1160+
tue-install-warning "Does not contain a valid ROS package.xml"
1161+
fi
1162+
else
1163+
tue-install-debug "No need to parse package.xml for dependencies"
1164+
fi
1165+
1166+
else
1167+
tue-install-error "Checking out $src was not successful."
1168+
fi
1169+
1170+
TUE_INSTALL_PKG_DIR=$ros_pkg_dir
10131171

10141172

10151173
if __name__ == "__main__":

0 commit comments

Comments
 (0)