def test_sanitize(self): """Test sanitize string function""" # test with an empty string ret = sanitize_string('', 'aeiouy') self.assertEqual(ret, '') # test empty second argument ret = sanitize_string('first', '') self.assertEqual(ret, 'first') # test escaping every character ret = sanitize_string('aaaaeeeeoooo', 'aeo') self.assertEqual(ret, '\\a\\a\\a\\a\\e\\e\\e\\e\\o\\o\\o\\o')
def get_ebuild_text(self, distributor, license_text): """ Generate the ebuild in text, given the distributor line and the license text. """ ret = "# Copyright " + strftime("%Y", gmtime()) + " " ret += distributor + "\n" ret += "# Distributed under the terms of the " + license_text ret += " license\n\n" # EAPI=<eapi> ret += "EAPI=" + self.eapi + "\n" if self.python_3: ret += "PYTHON_COMPAT=( python{2_7,3_5} )\n\n" else: ret += "PYTHON_COMPAT=( python2_7 )\n\n" # inherits ret += "inherit ros-cmake\n\n" # description, homepage, src_uri self.description =\ sanitize_string(self.description, self.illegal_desc_chars) self.description = trim_string(self.description) ret += "DESCRIPTION=\"" + self.description + "\"\n" ret += "HOMEPAGE=\"" + self.homepage + "\"\n" self.src_uri = self.src_uri.replace(self.name, '${PN}') ret += "SRC_URI=\"" + self.src_uri ret += " -> ${PN}-" + self.distro + "-release-${PV}.tar.gz\"\n\n" # license -- only add if valid if isinstance(self.upstream_license, str): split = self.upstream_license.split(',') if len(split) > 1: # they did something like "BSD,GPL,blah" ret += 'LICENSE="( ' ret += ' '.join([get_license(l) for l in split]) ret += ') "\n' else: ret += "LICENSE=\"" ret += get_license(self.upstream_license) + "\"\n\n" elif isinstance(self.upstream_license, list): ret += "LICENSE=\"( " ret += ' '.join([get_license(ul) for ul in self.upstream_license]) ret += " )\"\n" # iterate through the keywords, adding to the KEYWORDS line. ret += "KEYWORDS=\"" ret += ' '.join([key.to_string() for key in self.keys]) ret += "\"\n" # RDEPEND ret += "RDEPEND=\"\n" for rdep in sorted(self.rdepends): ret += " " + "ros-" + self.distro + "/" + rdep + "\n" for rdep in sorted(self.rdepends_external): try: for res in resolve_dep(rdep, 'gentoo')[0]: if res in depend_only_pkgs: self.depends_external.append(rdep) break else: ret += " " + res + "\n" except UnresolvedDependency: self.unresolved_deps.append(rdep) ret += "\"\n" # DEPEND ret += "DEPEND=\"${RDEPEND}\n" for bdep in sorted(self.depends): ret += " " + 'ros-{0}/{1}\n'.format(self.distro, bdep) for bdep in sorted(self.depends_external): try: for res in resolve_dep(bdep, 'gentoo')[0]: ret += " " + res + "\n" except UnresolvedDependency: self.unresolved_deps.append(bdep) ret += "\"\n\n" # SLOT ret += "SLOT=\"0\"\n" # CMAKE_BUILD_TYPE if self.name == "catkin": ret += "BUILD_BINARY=\"0\"\n" ret += "ROS_DISTRO=\"{0}\"\n".format(self.distro) ret += "ROS_PREFIX=\"opt/ros/${ROS_DISTRO}\"\n" # Patch source if needed. if self.has_patches: ret += "\nsrc_prepare() {\n" ret += " cd ${P}\n" ret += " EPATCH_SOURCE=\"${FILESDIR}\"" ret += " EPATCH_SUFFIX=\"patch\" \\\n" ret += " EPATCH_FORCE=\"yes\" epatch\n" ret += " ros-cmake_src_prepare\n" ret += "}\n" special_pkgs = ['opencv3', 'stage'] # source configuration if self.name in special_pkgs: ret += "\nsrc_configure() {\n" if self.name == 'opencv3': ret += " filter-flags '-march=*' '-mcpu=*' '-mtune=*'\n" elif self.name == 'stage': ret += " filter-flags '-std=*'\n" ret += " ros-cmake_src_configure\n" ret += "}\n" if len(self.unresolved_deps) > 0: raise UnresolvedDependency("failed to satisfy dependencies!") return ret.replace(' ', '\t')
def get_pkgbuild_text(self, distributor, license_text): """ Generate the pkgbuild in text, given the distributor line and the license text. """ # EAPI=<eapi> entries = [] entries.append("# Script generated with superflore") entries.append("# Maintainer: Sebastian Mai <*****@*****.**>") self.description =\ sanitize_string(self.description, self.illegal_desc_chars) self.description = trim_string(self.description) entries.append(f"pkgname='ros-{self.distro}-{self.name}'") entries.append(f'pkgdesc="{self.description}"') entries.append(f"url={self.homepage}") version_str = self.version.split("-")[0] rc = self.version.split("-")[1][1:] entries.append(f"pkgver={version_str}") entries.append(f"arch=('any')") entries.append(f"pkgrel={rc}") license_str = [f"'{ul}'" for ul in self.upstream_license] entries.append(f"license=({' '.join(license_str)})") entries.append(f"epoch=0") entries.append(f"groups=('ros' 'ros-{self.distro}')") ros_deps = [f"ros-{self.distro}-{d}" for d in self.depends] dependencies = (ros_deps + self.depends_external) for i, dep in enumerate(dependencies): if dep.startswith("python3"): dependencies[i] = dep.replace("python3", "python", 1) entries.append(f"makedepends=({' '.join(dependencies)})") ros_rdeps = [f"ros-{self.distro}-{d}" for d in self.rdepends] rdependencies = (ros_rdeps + self.rdepends_external) for i, dep in enumerate(rdependencies): if dep.startswith("python3"): rdependencies[i] = dep.replace("python3", "python", 1) entries.append(f"depends=({' '.join(rdependencies)})") entries.append( f'source=("ros-{self.distro}-{self.name}-{self.version}.tar.gz::{self.src_uri}")' ) entries.append(f"md5sums=('SKIP')") entries.append(f""" build() {{ cd "${{srcdir}}" [ -f /opt/ros/{self.distro}/setup.bash ] && source /opt/ros/{self.distro}/setup.bash colcon build }} """) entries.append(f""" package() {{ cd "${{srcdir}}" colcon build --install-base "${{pkgdir}}"/opt/ros/{self.distro} rm "${{pkgdir}}"/opt/ros/{self.distro}/*setup* rm "${{pkgdir}}"/opt/ros/{self.distro}/COLCON_IGNORE rm "${{pkgdir}}"/opt/ros/{self.distro}/.colcon_install_layout chown -R ros:ros "${{pkgdir}}"/opt/ros/{self.distro} chmod -R 777 "${{pkgdir}}"/opt/ros/{self.distro} }} """) return "\n".join(entries)
def get_ebuild_text(self, distributor, license_text): """ Generate the ebuild in text, given the distributor line and the license text. """ # EAPI=<eapi> ret = self.get_license_line(distributor, license_text) ret += self.get_eapi_line() if self.python_3 and not self.is_ros2: # enable python 2.7 and python 3.5 ret += self.get_python_compat(['2_7', '3_5']) elif self.python_3: # only use 3.5, 3.6 for ROS 2 ret += self.get_python_compat(['3_5', '3_6']) else: # fallback to python 2.7 ret += self.get_python_compat(['2_7']) # inherits ret += self.get_inherit_line() # description, homepage, src_uri self.description =\ sanitize_string(self.description, self.illegal_desc_chars) self.description = trim_string(self.description) ret += "DESCRIPTION=\"" + self.description + "\"\n" ret += "HOMEPAGE=\"" + self.homepage + "\"\n" self.src_uri = self.src_uri.replace(self.name, '${PN}') ret += "SRC_URI=\"" + self.src_uri ret += " -> ${PN}-" + self.distro + "-release-${PV}.tar.gz\"\n\n" # license -- only add if valid if len(self.upstream_license) == 1: self.upstream_license = [ l.replace(', ', ' ') for l in self.upstream_license ] split = self.upstream_license[0].split(',') if len(split) > 1: # they did something like "BSD,GPL,blah" ret += 'LICENSE="( ' ret += ' '.join([get_license(l.strip()) for l in split]) ret += ' )"\n' else: ret += "LICENSE=\"" ret += get_license(self.upstream_license[0]) + "\"\n\n" else: ret += "LICENSE=\"( " ret += ' '.join( [get_license(ul) for ul in self.upstream_license] ) ret += " )\"\n" # iterate through the keywords, adding to the KEYWORDS line. ret += "KEYWORDS=\"" ret += ' '.join([key.to_string() for key in self.keys]) ret += "\"\n" if len(self.tdepends) or len(self.tdepends_external): ret += 'IUSE="test"\n' # RDEPEND ret += "RDEPEND=\"\n" for rdep in sorted(self.rdepends): ret += " " + "ros-" + self.distro + "/" + rdep + "\n" # internal test dependencies for tdep in sorted(self.tdepends): ret += " " + "test? ( ros-" + self.distro + "/" + tdep + " )\n" for rdep in sorted(self.rdepends_external): try: for res in resolve_dep(rdep, 'gentoo')[0]: if res in depend_only_pkgs: self.depends_external.append(rdep) break else: ret += " " + res + "\n" except UnresolvedDependency: self.unresolved_deps.append(rdep) # external test dependencies for tdep in sorted(self.tdepends_external): try: for res in resolve_dep(tdep, 'gentoo')[0]: ret += " test? ( " + res + " )\n" except UnresolvedDependency: self.unresolved_deps.append(tdep) ret += "\"\n" # DEPEND ret += "DEPEND=\"${RDEPEND}\n" for bdep in sorted(self.depends): ret += " " + 'ros-{0}/{1}\n'.format(self.distro, bdep) for bdep in sorted(self.depends_external): try: for res in resolve_dep(bdep, 'gentoo')[0]: ret += " " + res + "\n" except UnresolvedDependency: self.unresolved_deps.append(bdep) ret += "\"\n\n" # SLOT ret += "SLOT=\"0\"\n" # CMAKE_BUILD_TYPE if self.name == "catkin": ret += "BUILD_BINARY=\"0\"\n" ret += "ROS_DISTRO=\"{0}\"\n".format(self.distro) ret += "ROS_PREFIX=\"opt/ros/${ROS_DISTRO}\"\n" # Patch source if needed. if self.has_patches: # TODO(allenh1): explicitly list patches ret += "\nsrc_prepare() {\n" ret += " cd ${P}\n" ret += " EPATCH_SOURCE=\"${FILESDIR}\"" ret += " EPATCH_SUFFIX=\"patch\" \\\n" ret += " EPATCH_FORCE=\"yes\" epatch\n" if self.build_type in ['catkin', 'cmake']: ret += " ros-cmake_src_prepare\n" ret += "}\n" # source configuration if self.name == 'opencv3': ret += "\nsrc_configure() {\n" ret += " filter-flags '-march=*' '-mcpu=*' '-mtune=*'\n" ret += " if [[ $(gcc-major-version) -gt 4 ]]; then\n" ret += " local mycmakeargs=(\n" ret += " -DWITH_CUDA=OFF\n" ret += " )\n" ret += ' ewarn "Cuda does not support GCC > 4, so cuda' ret += ' has been disabled."\n' ret += " fi\n" ret += " ros-cmake_src_configure\n" ret += "}\n" elif self.name == 'stage': ret += "\nsrc_configure() {\n" ret += " filter-flags '-std=*'\n" ret += " ros-cmake_src_configure\n" ret += "}\n" if len(self.unresolved_deps) > 0: raise UnresolvedDependency("failed to satisfy dependencies!") return ret.replace(' ', '\t')