From d94809c06fc020eb9e35f87b124cd45de99bc938 Mon Sep 17 00:00:00 2001 From: Michael Wetter Date: Fri, 1 Oct 2021 16:06:14 -0700 Subject: [PATCH] Updated OpenModelica version (#2649) * Updated OpenModelica version to 1.18, switched to use of Docker for OMC. --- .travis.yml | 14 +-- Buildings/Resources/Scripts/travis/Makefile | 3 +- Buildings/Resources/Scripts/travis/omc/omc.sh | 97 +++++++++++++++++++ .../Scripts/travis/omc/testOpenModelica.sh | 4 +- 4 files changed, 104 insertions(+), 14 deletions(-) create mode 100755 Buildings/Resources/Scripts/travis/omc/omc.sh diff --git a/.travis.yml b/.travis.yml index 2b67773dc53..72074773db5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,17 +24,6 @@ services: - docker - xvfb - -addons: - apt: - sources: - - sourceline: "deb https://build.openmodelica.org/omc/builds/linux/releases/1.16.1/ bionic release" - key_url: "http://build.openmodelica.org/apt/openmodelica.asc" - packages: - - omc=1.16.1-1 - - omlib-modelica-3.2.2 #3.2.3 is not in https://build.openmodelica.org/omc/builds/linux/releases/1.16.1/dists/bionic/release/binary-amd64/Packages.gz - - env: global: - ENERGYPLUS_VERSION=EnergyPlus-9.5.0-de239b2e5f-Linux-Ubuntu18.04-x86_64 @@ -130,6 +119,9 @@ before_install: cd -; echo "Installed modelica-json in ${MODELICA_JSON_HOME}"; fi; + - if [[ "$TEST_ARG" == *test-omc* ]]; then + docker pull "$DOCKER_USERNAME"/ubuntu-2004-omc:1.18.0; + fi; # Install dependencies # For sphinx, we need to install specific package versions, otherwise diff --git a/Buildings/Resources/Scripts/travis/Makefile b/Buildings/Resources/Scripts/travis/Makefile index 27194d932e7..9ba77c37fa3 100644 --- a/Buildings/Resources/Scripts/travis/Makefile +++ b/Buildings/Resources/Scripts/travis/Makefile @@ -50,7 +50,8 @@ test-spawn-portability: grep "terminated successfully" dslog.txt ) test-omc: - (cd $(ROOT) && $(TRAVIS_BUILD_DIR)/Buildings/Resources/Scripts/travis/omc/testOpenModelica.sh) + (cd $(ROOT) && \ + $(TRAVIS_BUILD_DIR)/Buildings/Resources/Scripts/travis/omc/testOpenModelica.sh) test-dymola: (cd $(ROOT)/Buildings && \ diff --git a/Buildings/Resources/Scripts/travis/omc/omc.sh b/Buildings/Resources/Scripts/travis/omc/omc.sh new file mode 100755 index 00000000000..8be29b5dee4 --- /dev/null +++ b/Buildings/Resources/Scripts/travis/omc/omc.sh @@ -0,0 +1,97 @@ +#!/bin/bash +################################################# +# Shell script that simulates with OpenModelica using +# a docker image of OMC +# +# The main purpose of this script is to export +# MODELICAPATH +# updated for the docker, and to mount the +# required directories. +################################################# +set -e +IMG_NAME=ubuntu-2004-omc:1.18.0 +DOCKER_USERNAME=michaelwetter + +# Function declarations +function create_mount_command() +{ + local pat="$1" + # Each entry in pat will be a mounted read-only volume + local mnt_cmd="" + for ele in ${pat//:/ }; do + mnt_cmd="${mnt_cmd} -v ${ele}:/mnt${ele}:ro" + done + + # On Darwin, the exported temporary folder needs to be /private/var/folders, not /var/folders + # see https://askubuntu.com/questions/600018/how-to-display-the-paths-in-path-separately + if [ `uname` == "Darwin" ]; then + mnt_cmd=`echo ${mnt_cmd} | sed -e 's| /var/folders/| /private/var/folders/|g'` + fi + echo "${mnt_cmd}" +} + +function update_path_variable() +{ + # Prepend /mnt/ in front of each entry of a PATH variable in which the arguments are + # separated by a colon ":" + # This allows for example to create the new MODELICAPATH + local pat="$1" + local new_pat=`(set -f; IFS=:; printf "/mnt%s:" ${pat})` + # Cut the trailing ':' + new_pat=${new_pat%?} + echo "${new_pat}" +} + +# Export the MODELICAPATH +if [ -z ${MODELICAPATH+x} ]; then + MODELICAPATH=`pwd` +else + # Add the current directory to the front of the Modelica path. + # This will export the directory to the docker, and also set + # it in the MODELICAPATH so that JModelica finds it. + MODELICAPATH=`pwd`:${MODELICAPATH} +fi + +# Create the command to mount all directories in read-only mode +MOD_MOUNT=`create_mount_command ${MODELICAPATH}` + +# Prepend /mnt/ in front of each entry, which will then be used as the MODELICAPATH +DOCKER_MODELICAPATH=`update_path_variable ${MODELICAPATH}` + +# If the current directory is part of the argument list, +# replace it with . as the docker may have a different file structure +cur_dir=`pwd` +bas_nam=`basename ${cur_dir}` +arg_lis=`echo $@ | sed -e "s|${cur_dir}|.|g"` + +# Set variable for shared directory +sha_dir=`dirname ${cur_dir}` + +# Check if the python script should be run interactively (if -i is specified) +while [ $# -ne 0 ] +do + arg="$1" + case "$arg" in + -i) + interactive=true + DOCKER_INTERACTIVE=-t + ;; + esac + shift +done + +# --user=${UID} \ + +docker run \ + --user=${UID} \ + -i \ + $DOCKER_INTERACTIVE \ + --detach=false \ + ${MOD_MOUNT} \ + -v ${sha_dir}:/mnt/shared \ + --rm \ + ${DOCKER_USERNAME}/${IMG_NAME} /bin/bash -c \ + "export OPENMODELICALIBRARY=${DOCKER_MODELICAPATH}:/usr/lib/omlibrary && \ + cd /mnt/shared/${bas_nam} && \ + omc ${arg_lis}" +exit $? diff --git a/Buildings/Resources/Scripts/travis/omc/testOpenModelica.sh b/Buildings/Resources/Scripts/travis/omc/testOpenModelica.sh index 14ad930e167..f9440484612 100755 --- a/Buildings/Resources/Scripts/travis/omc/testOpenModelica.sh +++ b/Buildings/Resources/Scripts/travis/omc/testOpenModelica.sh @@ -1,3 +1,4 @@ +#!/bin/bash # This file translates and simulates all models in FILES with omc # Upon success, it exits with 0, otherwise it exits with a non-zero value. # @@ -40,8 +41,7 @@ done export OPENMODELICALIBRARY=`pwd`:/usr/lib/omlibrary #omc +d=nogen,initialization,backenddaeinfo,discreteinfo,stateselection --newBackend $mosScript -omc $mosScript - +${TRAVIS_BUILD_DIR}/Buildings/Resources/Scripts/travis/omc/omc.sh $mosScript # Check for failures exiFla=0