Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Develop fix version check (#1006)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
David P. Chassin authored Sep 24, 2021
1 parent 185986c commit c224db3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion gldcore/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions gldcore/gridlabd.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command>"
Expand All @@ -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 :
Expand Down Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions gldcore/gridlabd.m4sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command>"
Expand All @@ -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 :
Expand Down Expand Up @@ -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
Expand All @@ -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])
2 changes: 1 addition & 1 deletion gldcore/link/python/Makefile.mk
Original file line number Diff line number Diff line change
@@ -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 )

Expand Down
47 changes: 24 additions & 23 deletions gldcore/scripts/gridlabd-version
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,46 +30,44 @@ function version-help()
Syntax: gridlabd version [--dryrun] <command> <options...>
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 [<pattern>] get a list of available versions
show show the current active version
set [<pattern>] set the active version
source open source code of the active version
delete [-a|<pattern>] 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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c224db3

Please sign in to comment.