From c224db3b95a1d857eac79e3d0068fb185fd406d1 Mon Sep 17 00:00:00 2001 From: "David P. Chassin" Date: Fri, 24 Sep 2021 15:44:31 -0700 Subject: [PATCH] Develop fix version check (#1006) * Update gridlabd-version * Update gridlabd-version * Update gridlabd-version * Update gridlabd-version * Update Makefile.am * Update gridlabd.m4sh * Update gridlabd.in * Update Makefile.mk * Update gridlabd.in * Update gridlabd-version * Add support for logging version checks --- Makefile.am | 4 +-- gldcore/Makefile.mk | 2 +- gldcore/gridlabd.in | 8 +++--- gldcore/gridlabd.m4sh | 8 +++--- gldcore/link/python/Makefile.mk | 2 +- gldcore/scripts/gridlabd-version | 47 ++++++++++++++++---------------- 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/Makefile.am b/Makefile.am index 3345e3e08..41e716dc0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -278,7 +278,7 @@ distclean-local: python-clean libtool: $(LIBTOOL_DEPS) $(SHELL) $(PWD)/config.status libtool > /dev/null -install-exec-hook: index python-requirements python-install docs +install-exec-hook: index python-requirements docs @cp ${top_srcdir}/{COPYRIGHT,LICENSE} $(prefix) @echo "" @echo "Install complete. Here are some useful commands now:" @@ -315,7 +315,7 @@ $(PREFIX)/docker.img: docker/Dockerfile Makefile @mkdir -p $(prefix) docker save $(PACKAGE)/$(PACKAGE_VERSION)-$(PACKAGE_BRANCH):latest -o $(prefix)/docker.img -system: install +system: python-install install @echo "Setting $$($(top_srcdir)/build-aux/version.sh --install) to the current system version" @$(DESTDIR)$(bindir)/gridlabd version set @if [ ! "$$(gridlabd --version=install)" == "$$($(top_srcdir)/build-aux/version.sh --install)" ]; then \ diff --git a/gldcore/Makefile.mk b/gldcore/Makefile.mk index 26cd6fc70..f3fb69a9a 100644 --- a/gldcore/Makefile.mk +++ b/gldcore/Makefile.mk @@ -124,8 +124,8 @@ gridlabddir = $(prefix)/share/gridlabd gridlabd_DATA = origin.txt gldcore/gridlabd.in: gldcore/gridlabd.m4sh - @autoreconf -isf @autom4te -l m4sh $< > $@ + @echo "$@ updated, please run 'make reconfigure && make TARGET' again" && false gldcore/build.h: buildnum diff --git a/gldcore/gridlabd.in b/gldcore/gridlabd.in index 6232eacf2..d6fa12331 100644 --- a/gldcore/gridlabd.in +++ b/gldcore/gridlabd.in @@ -280,7 +280,7 @@ HAS_DOCKER="no" which docker > /dev/null 2>&1 && HAS_DOCKER="yes" if test "x$1" = "xdocker" ; then : if test "x$HAS_DOCKER" = "xno"; then : - echo "docker is not installed" + echo "ERROR: docker is not installed" exit 1 elif test "x$2" = "xhelp"; then : echo "Syntax: gridlabd docker " @@ -298,7 +298,7 @@ if test "x$1" = "xdocker" ; then : docker images | grep gridlabd exit 0 else - echo "missing docker image name" + echo "ERROR: missing docker image name" exit 1 fi elif test "x$2" = "xdisable" ; then : @@ -359,7 +359,7 @@ elif test "x$1" = "xlldb" ; then : elif test "x$1" = "xvalgrind" ; then : shift if test -z "${VALGRIND_OPTIONS}" ; then : - echo "warning: VALGRIND_OPTIONS is not set, using default valgrind options" + echo "WARNING: VALGRIND_OPTIONS is not set, using default valgrind options" fi valgrind ${VALGRIND_OPTIONS} $bindir/gridlabd.bin $@ exit 0 @@ -374,5 +374,5 @@ if test -x "${bindir}/gridlabd-$1" then : "${bindir}/gridlabd"-"$@" else $as_nop - "$bindir/gridlabd.bin" "$@" + "${bindir}/gridlabd.bin" "$@" && "${bindir}/gridlabd-version" check -w fi diff --git a/gldcore/gridlabd.m4sh b/gldcore/gridlabd.m4sh index f1db1a816..a3ecff3bb 100644 --- a/gldcore/gridlabd.m4sh +++ b/gldcore/gridlabd.m4sh @@ -16,7 +16,7 @@ HAS_DOCKER="no" which docker > /dev/null 2>&1 && HAS_DOCKER="yes" if test "x$1" = "xdocker" ; then : if test "x$HAS_DOCKER" = "xno"; then : - echo "docker is not installed" + echo "ERROR: docker is not installed" exit 1 elif test "x$2" = "xhelp"; then : echo "Syntax: gridlabd docker " @@ -34,7 +34,7 @@ if test "x$1" = "xdocker" ; then : docker images | grep gridlabd exit 0 else - echo "missing docker image name" + echo "ERROR: missing docker image name" exit 1 fi elif test "x$2" = "xdisable" ; then : @@ -92,7 +92,7 @@ elif test "x$1" = "xlldb" ; then : elif test "x$1" = "xvalgrind" ; then : shift if test -z "${VALGRIND_OPTIONS}" ; then : - echo "warning: VALGRIND_OPTIONS is not set, using default valgrind options" + echo "WARNING: VALGRIND_OPTIONS is not set, using default valgrind options" fi valgrind ${VALGRIND_OPTIONS} $bindir/gridlabd.bin $@ exit 0 @@ -104,4 +104,4 @@ AS_IF([test -f "${pkgdatadir}/gridlabd.rc"], AS_IF([test -x "${bindir}/gridlabd-$1"], ["${bindir}/gridlabd"-"$@"], - ["$bindir/gridlabd.bin" "$@"]) + ["${bindir}/gridlabd.bin" "$@" && "${bindir}/gridlabd-version" check -w]) diff --git a/gldcore/link/python/Makefile.mk b/gldcore/link/python/Makefile.mk index 93503a1c0..db439a638 100644 --- a/gldcore/link/python/Makefile.mk +++ b/gldcore/link/python/Makefile.mk @@ -1,4 +1,4 @@ -python-install: +python-install: gldcore/build.h @echo "python3 $(top_srcdir)/gldcore/link/python/setup.py --quiet install" @( export SRCDIR=$(top_srcdir) ; python3 $(top_srcdir)/gldcore/link/python/setup.py --quiet install ) diff --git a/gldcore/scripts/gridlabd-version b/gldcore/scripts/gridlabd-version index b7cf662c6..9e3e5c6e1 100755 --- a/gldcore/scripts/gridlabd-version +++ b/gldcore/scripts/gridlabd-version @@ -1,11 +1,14 @@ #!/bin/bash EXE="$(basename $0)" +BIN=${0/-version/.bin} function error() { - echo "$EXE: ERROR $*" > /dev/stderr - exit $1 + RC=$1 + shift 1 + echo "ERROR [$EXE] $*" > /dev/stderr + exit $RC } case "$1" in @@ -27,46 +30,44 @@ function version-help() Syntax: gridlabd version [--dryrun] Commands: help get this list of commands - check [-v|-q] check for a newer version + check [-v|-q|-w] check for a newer version + -v enable verbose output + -q disable all output + -w only output warnings and errors and log check result list [] get a list of available versions show show the current active version set [] set the active version source open source code of the active version delete [-a|] delete versions + -a delete all version except current one END } function version-check() { - local=$(gridlabd --version=commit) - branch=$(gridlabd --version=branch) - origin=$(git remote) - remote=$(git rev-parse $origin/$branch 2>/dev/null) - if [ "$remote" == "$origin/$branch" ]; then - remote=none - fi - if [ "$1" == "-v" ]; then - echo "REMOTE $remote" - echo "LOCAL $local" - fi - if [ "$remote" == "none" ]; then - [ -z "$1" ] && error 2 "$(gridlabd --version) remote '$origin/$branch' not found" - elif [ "$local" != "$remote" ]; then - [ -z "$1" ] && error 1 "$(gridlabd --version) is outdated" - else - [ -z "$1" ] && error 0 "$(gridlabd --version) is ok" + version=$(${BIN} --version) + branch=$(${BIN} --version=git-branch) + remote=$( (curl -sL "https://raw.githubusercontent.com/slacgismo/gridlabd/$branch/gldcore/version.h" | grep '#define REV_' | cut -f3 -d' ' | tr '\n' . | cut -f-3 -d.) || echo "none" ) + if [ "$remote" == "none" -o -z "$remote" ]; then + [ "$1" != "-q" ] && error 2 "$version ($branch) remote not found" + exit 2 fi + [ "$1" == "-v" ] && echo "REMOTE/$branch $remote" + ${BIN} --version="-ge $remote" 2>/dev/null || ( ( [ "$1" != "-q" ] && error 1 "$version ($branch) is outdated" ) ; exit 1 ) + [ "$1" != "-q" -a "$1" != "-w" ] && echo "$version ($branch) is ok" + [ "$1" == "-w" ] && ( curl -sL "http://version.gridlabd.us/index.html?v=${version}&b=${branch}" >/dev/null & ) + exit 0 } function version-source() { - open $(gridlabd git commit HEAD html_url | sed -e 's:/commit/:/tree/:') + open $(${BIN} git commit HEAD html_url | sed -e 's:/commit/:/tree/:') } function version-save() { if [ -f /usr/local/bin/gridlabd -a ! -L /usr/local/bin/gridlabd ]; then - SAVED="$(/usr/local/bin/gridlabd --version | cut -f2 -d' ')-saved_$(date '+%Y%m%d')" + SAVED="$(${BIN} --version | cut -f2 -d' ')-saved_$(date '+%Y%m%d')" N=0 TRY="$SAVED" while [ -d /usr/local/opt/gridlabd/$TRY ]; do @@ -94,7 +95,7 @@ function version-set() L=$(cd /usr/local/opt/gridlabd ; ls -1d *$1* | grep -v current) fi if [ -z "$L" ]; then - L="$(${0/$EXE/gridlabd} --version=name | sed -e 's/^gridlabd-//')" + L="$(${BIN} --version=name | sed -e 's/^gridlabd-//')" elif [ "$(echo $L | wc -w)" -gt 1 ]; then error 2 "ambiguous version" fi