From d479706f0348fe74354ce1365b45a8d633804dfa Mon Sep 17 00:00:00 2001 From: Montgomery Alban Date: Tue, 14 Mar 2023 15:58:58 +0000 Subject: [PATCH] Update sumo builder utility --- ...ubuntu16.sumo1_5 => Dockerfile.sumo_build} | 17 +++-- .../ubuntu_compile/ubuntu_16_04_sumo_1_5.sh | 30 -------- utils/extras/sumo/ubuntu_sumo_build.sh | 75 +++++++++++++++++++ utils/setup/README.pypi.md | 12 ++- 4 files changed, 97 insertions(+), 37 deletions(-) rename utils/extras/sumo/{ubuntu_compile/Dockerfile.ubuntu16.sumo1_5 => Dockerfile.sumo_build} (66%) delete mode 100644 utils/extras/sumo/ubuntu_compile/ubuntu_16_04_sumo_1_5.sh create mode 100644 utils/extras/sumo/ubuntu_sumo_build.sh diff --git a/utils/extras/sumo/ubuntu_compile/Dockerfile.ubuntu16.sumo1_5 b/utils/extras/sumo/Dockerfile.sumo_build similarity index 66% rename from utils/extras/sumo/ubuntu_compile/Dockerfile.ubuntu16.sumo1_5 rename to utils/extras/sumo/Dockerfile.sumo_build index 4f9e257e73..397350b257 100644 --- a/utils/extras/sumo/ubuntu_compile/Dockerfile.ubuntu16.sumo1_5 +++ b/utils/extras/sumo/Dockerfile.sumo_build @@ -1,28 +1,33 @@ -FROM ubuntu:xenial +ARG UBUNTU_VERSION=20.04 +FROM ubuntu:${UBUNTU_VERSION} ARG DEBIAN_FRONTEND=noninteractive +ARG SUMO_REPO_TAG=v1_16_0 -RUN echo "Installing dependencies" +RUN cat /etc/issue +RUN echo "Installing dependencies with ubuntu=${UBUNTU_VERSION} sumo=${SUMO_REPO_TAG}" RUN apt-get update --fix-missing && \ apt-get install -y \ software-properties-common && \ apt-get update && \ apt-get install -y \ + git \ cmake \ - python \ + python3 \ g++ \ libxerces-c-dev \ libfox-1.6-dev \ libgdal-dev \ libproj-dev \ libgl2ps-dev \ - swig \ - git + python3-dev \ + swig \ + ccache RUN cd /usr/src && \ git clone --recursive https://github.com/eclipse/sumo && \ cd sumo && \ - git checkout 3a3be608d2408d7cbf10f6bba939254ef439c209 && \ + git checkout ${SUMO_REPO_TAG} && \ git fetch origin refs/replace/*:refs/replace/* && \ export SUMO_HOME="$PWD" && \ mkdir -p build/cmake-build && cd build/cmake-build && \ diff --git a/utils/extras/sumo/ubuntu_compile/ubuntu_16_04_sumo_1_5.sh b/utils/extras/sumo/ubuntu_compile/ubuntu_16_04_sumo_1_5.sh deleted file mode 100644 index 34179686f4..0000000000 --- a/utils/extras/sumo/ubuntu_compile/ubuntu_16_04_sumo_1_5.sh +++ /dev/null @@ -1,30 +0,0 @@ -endloc=${PWD}/ubuntu_xenial_build - -docker build -t smrt_u16_sumo_1_5 - < Dockerfile.ubuntu16.sumo1_5 && \ -docker create -ti --name intermediate_builder smrt_u16_sumo_1_5 /bin/bash -if docker cp intermediate_builder:/usr/src/sumo ${endloc} && \ -docker rm -f intermediate_builder ; then - echo 'Current SUMO_HOME is:' - printenv | grep 'SUMO_HOME' - read -p "Do you wish to set SUMO_HOME to ${endloc}? [Yn]" should_change_sumo_home - if [[ $should_change_sumo_home =~ ^[yY]$ ]]; then - # should not be doing this if not linux - if ! [[ "$OSTYPE" == "linux-gnu" ]]; then - echo 'Not Linux, exiting...' - exit 1 - fi - # should not be doing this if not Xenial - if ! cat /etc/os-release | grep 'Xenial' ; then - echo 'Not Ubuntu 16(Xenial), exiting...' - exit 1 - fi - # delete current SUMO_HOME from bashrc - sed '/^export SUMO_HOME/d' ~/.bashrc - echo "export SUMO_HOME=${endloc}" >> ~/.bashrc - echo "We've updated your ~/.bashrc. Be sure to run:" - echo "" - echo " source ~/.bashrc" - echo "" - echo "in order to set the SUMO_HOME variable in your current console session" - fi -fi \ No newline at end of file diff --git a/utils/extras/sumo/ubuntu_sumo_build.sh b/utils/extras/sumo/ubuntu_sumo_build.sh new file mode 100644 index 0000000000..bb9586addc --- /dev/null +++ b/utils/extras/sumo/ubuntu_sumo_build.sh @@ -0,0 +1,75 @@ +#!/bin/bash +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +endloc=${SCRIPT_DIR}/build + +echo 'If you are building for your system please check with "cat /etc/os-release | grep VERSION_"' + +# Parse command line arguments +options=$(getopt -o u:s: --long ubuntu-version:,sumo-tag: -- "$@") +eval set -- "$options" + +# Default values +ubuntu_version="" +sumo_tag="" + +# Loop through arguments and set variables +while true; do + case "$1" in + -u | --ubuntu-version ) + ubuntu_version="$2" + shift 2 + ;; + -s | --sumo-tag ) + sumo_tag="$2" + shift 2 + ;; + -- ) + shift + break + ;; + * ) + echo "Invalid argument: $1" + exit 1 + ;; + esac +done + +# Check for empty arguments +if [ -z "$ubuntu_version" ] || [ -z "$sumo_tag" ]; then + echo "Error: both ubuntu-version and sumo-tag options are required" + echo "-u, --ubuntu-version " + echo " See https://hub.docker.com/_/ubuntu/tags" + echo "-s, --sumo-tag " + echo " See https://github.com/eclipse/sumo/tags" + exit 1 +fi + + +# Print arguments +echo "Ubuntu version: $ubuntu_version" +echo "SUMO tag: $sumo_tag" + + +docker build --no-cache --build-arg SUMO_REPO_TAG=${sumo_tag} --build-arg UBUNTU_VERSION=${ubuntu_version} -t sumo_builder - < ${SCRIPT_DIR}/Dockerfile.sumo_build && \ +docker create -ti --name intermediate_builder sumo_builder /bin/bash +if docker cp intermediate_builder:/usr/src/sumo ${endloc} && \ +docker rm -f intermediate_builder ; then + echo 'Current SUMO_HOME is:' + printenv | grep 'SUMO_HOME' + read -p "Do you wish to set SUMO_HOME to ${endloc}? [Yn]" should_change_sumo_home + if [[ $should_change_sumo_home =~ ^[yY]$ ]]; then + # should not be doing this if not linux + if ! [[ "$OSTYPE" == "linux-gnu" ]]; then + echo 'Not Linux, exiting...' + exit 1 + fi + # delete current SUMO_HOME from bashrc + sed '/^export SUMO_HOME/d' ~/.bashrc + echo "export SUMO_HOME=${endloc}" >> ~/.bashrc + echo "We've updated your ~/.bashrc. Be sure to run:" + echo "" + echo " source ~/.bashrc" + echo "" + echo "in order to set the SUMO_HOME variable in your current console session" + fi +fi diff --git a/utils/setup/README.pypi.md b/utils/setup/README.pypi.md index e95e7c258e..0924320142 100644 --- a/utils/setup/README.pypi.md +++ b/utils/setup/README.pypi.md @@ -38,7 +38,17 @@ SUMO primarily targets Ubuntu versions >= 16.04. So you may not be able to downl If you try through a package manager make sure to command-line call `sumo` to make sure that you have the right version of SUMO. -We would recommend using the prebuilt binaries but if you are using Ubuntu 16 (Xenial), there is a bash script in `extras/sumo/ubuntu_build` that you can use to automate the compilation of SUMO version 1.5.0. +We would recommend using the prebuilt binaries but if you are using Ubuntu there is a bash script in the SMARTS repository `utils/extras/sumo/ubuntu_build` that you can use to compile SUMO from the eclipse SUMO repository. + +```bash +# $ ubuntu_sumo_build.sh +# Error: both ubuntu-version and sumo-tag arguments are required +# -u, --ubuntu-version +# See https://hub.docker.com/_/ubuntu/tags?page=1&ordering=-last_updated +# -s, --sumo-tag +# See https://github.com/eclipse/sumo/tags +bash utils/extras/sumo/ubuntu_build/ubuntu_sumo_build.sh -u focal -s v1_16_0 +``` ### MacOS