Skip to content

Commit

Permalink
Missing script for cucr-env
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan David Hernandez Vega committed Feb 16, 2024
1 parent 13407f5 commit 29da9d1
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
2 changes: 1 addition & 1 deletion installer/bootstrap_cucr.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function conditional_apt_update
{
CUCR_APT_GET_UPDATED_FILE=/tmp/tue_get_apt_get_updated
CUCR_APT_GET_UPDATED_FILE=/tmp/cucr_get_apt_get_updated
if [[ ! -f ${CUCR_APT_GET_UPDATED_FILE} ]]
then
echo "[tue-env](bootstrap) sudo apt-get update -qq"
Expand Down
96 changes: 96 additions & 0 deletions installer/generate_deb_control_cucr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#! /usr/bin/env python3

import platform
import sys
import os
from typing import Mapping
from parse_package_xml import packagexml_parser
from parse_install_yaml import installyaml_parser


CUCR_ENV_TARGETS_DIR = os.environ["CUCR_ENV_TARGETS_DIR"]
CUCR_ROS_DISTRO = os.environ["CUCR_ROS_DISTRO"]
ARCHITECTURES = {"x86_64": "amd64", "aarch64": "arm64"}
CONTROL_FILE_TEMPLATE = """
Package: {package}
Version: {version}
Architecture: {arch}
Maintainer: {maintainer}
Description: {description}
"""


def main() -> int:
if len(sys.argv) != 4:
print("Usage: generate_deb_control RELEASE_DIR PACKAGE.XML TIMESTAMP")
return 1

# print(generate_control_file(sys.argv[2])["control"])
create_dirs(sys.argv[1], sys.argv[2], sys.argv[3])
return 0


def generate_control_file(path: str) -> Mapping:
parsed = packagexml_parser(path)["parser"]

maintainer_string = ", ".join(f"{m} <{parsed['emails'][m]}>" for m in parsed["maintainer"])

system_deps = []
for dep in parsed["depend"]:
install_yaml = os.path.join(CUCR_ENV_TARGETS_DIR, dep, "install.yaml")
if not os.path.exists(install_yaml):
install_yaml = os.path.join(CUCR_ENV_TARGETS_DIR, f"ros-{dep}", "install.yaml")
system_deps += installyaml_parser(install_yaml)["system_packages"]

system_dep_string = ""
if system_deps:
system_dep_string = ", ".join(set(system_deps))

version = list(parsed["version"])[0]
description = list(parsed["description"])[0]
arch = ARCHITECTURES[platform.machine()]

build_type = list(parsed["build_type"])

package = list(parsed["name"])[0]
package = package.replace("_", "-")
if "ament_cmake" in build_type:
package = f"ros-{CUCR_ROS_DISTRO}-{package}"

control_file = CONTROL_FILE_TEMPLATE.format(
package=package,
version=version,
arch=arch,
maintainer=maintainer_string,
description=description,
)
if system_dep_string:
control_file += f"Depends: {system_dep_string}\n"

return {"package": package, "version": version, "arch": arch, "control": control_file}


def create_dirs(release_dir_path: str, package_xml_path: str, timestamp: str) -> None:
cfdict = generate_control_file(package_xml_path)

# timestamp = str(datetime.datetime.now()).replace("-", "")
# timestamp = timestamp.replace(":", "")
# timestamp = timestamp.replace(".", "")
# timestamp = timestamp.replace(" ", "")

rev = f"build{timestamp}"

package_release_dirname = f"{cfdict['package']}_{cfdict['version']}-{rev}_{cfdict['arch']}"

control_file_dir = os.path.join(release_dir_path, package_release_dirname, "DEBIAN")
control_file_path = os.path.join(control_file_dir, "control")

os.makedirs(control_file_dir)
with open(control_file_path, "w") as f:
f.write(cfdict["control"])

print(package_release_dirname)


if __name__ == "__main__":
sys.exit(main())
2 changes: 1 addition & 1 deletion setup/cucr-functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ function cucr-deb-generate
for package in $packages_list
do
local pkg_rel_dir
pkg_rel_dir="$("${CUCR_DIR}"/installer/generate_deb_control.py "${CUCR_RELEASE_DIR}" "${CUCR_SYSTEM_DIR}"/src/"${package}"/package.xml "${timestamp}")"
pkg_rel_dir="$("${CUCR_DIR}"/installer/generate_deb_control_cucr.py "${CUCR_RELEASE_DIR}" "${CUCR_SYSTEM_DIR}"/src/"${package}"/package.xml "${timestamp}")"


if [[ ! -d "${pkg_rel_dir}" ]]
Expand Down

0 comments on commit 29da9d1

Please sign in to comment.