[M3devel] moving versions into simple text file (sh?)

Jay jayk123 at hotmail.com
Sun Apr 20 05:56:15 CEST 2008


I'd like to (finally) move the default versions out into a simple file.

Given:

jbook15:/dev2/cm3/scripts jay$ cat version 
CM3VERSION d5.7.0
CM3VERSIONNUM 050700
CM3LASTCHANGED 2008-03-16

Is there any chance this is Posix/Solaris compliant?

get_version() {
  if [ -n "$(eval echo \$$1)" ] ; then
    return
  fi
  eval "$1=\"$(echo $(grep "$1 " $root/scripts/version | awk '{print $2}'))\""
}

get_version CM3VERSION
get_version CM3VERSIONNUM
get_version CM3LASTCHANGED
echo "CM3VERSION is $CM3VERSION"
echo "CM3VERSIONNUM is $CM3VERSIONNUM"
echo "CM3LASTCHANGED is $CM3LASTCHANGED"

It works on my Mac.
This is not what I would have expected, in particular the need
for eval and echo seems strange.
The quoting is all unfortunate as usual too.

If this isn't standard, then how about just the last line:
get_version() {
  eval "$1=\"$(echo $(grep "$1 " $root/scripts/version | awk '{print $2}'))\""

}

?

Otherwise, I guess dumb it down and be repetitive, like:
CM3VERSION=${CM3VERSION-`grep "CM3VERSION " $root/scripts/version | awk '{print $2}'))`}


? I didn't want to repeat the variable names three times each.

What I really want is to append version to PKGS and regenerate PKGS whenever its lines aren't all there,
so as to trigger an automatic rebuild of PKGS when the version changes.
One more application of the version numbers, and I was pushed to fix them.

Full diff:

Index: sysinfo.sh
===================================================================
RCS file: /usr/cvs/cm3/scripts/sysinfo.sh,v
retrieving revision 1.61
diff -c -r1.61 sysinfo.sh
*** sysinfo.sh    15 Apr 2008 06:51:31 -0000    1.61
--- sysinfo.sh    20 Apr 2008 03:48:13 -0000
***************
*** 10,38 ****
  
  PRJ_ROOT=${PRJ_ROOT:-${HOME}/work}
  
- #-----------------------------------------------------------------------------
- # set some defaults
  #
! # These three lines must be carefully formed as they are parsed by other code.
  #
! # For cmd:
! #  They must start with a name and an equals sign.
! #  They must contain one and only one colon.
! #  They must contain one and only one equals sign.
! #  The content to the right of the colon, minus the first two
! #  and last two characters, is the value.
  #
! # For Python, we have much more flexibility. Currently the code
! # looks for fairly precisely A=${A:-"value"}, but this can be easily
! # relaxed or changed.
  #
! # Refer to scripts/win/sysinfo.cmd and scripts/python/lib.py.
! # Specifically look for "DefaultsFromSh".
  #
  CM3VERSION=${CM3VERSION:-"d5.7.0"}
  CM3VERSIONNUM=${CM3VERSIONNUM:-"050700"}
  CM3LASTCHANGED=${CM3LASTCHANGED:-"2008-03-16"}
  
  CM3_GCC_BACKEND=yes
  CM3_GDB=no
  #
--- 10,49 ----
  
  PRJ_ROOT=${PRJ_ROOT:-${HOME}/work}
  
  #
! # Allow direct invocation of sysinfo.sh for testing purposes.
  #
! if [ -z "$root" -o ! -d "$root" ] ; then
!   root=`pwd`
!   while [ -n "$root" -a ! -f "$root/scripts/sysinfo.sh" ] ; do
!     root=`dirname $root`
!   done
! fi
! 
! #-----------------------------------------------------------------------------
! # set some defaults
  #
! 
! get_version() {
!   if [ -n "$(eval echo \$$1)" ] ; then
!     return
!   fi
!   eval "$1=\"$(echo $(grep "$1 " $root/scripts/version | awk '{print $2}'))\""
! }
! 
! get_version CM3VERSION
! get_version CM3VERSIONNUM
! get_version CM3LASTCHANGED
! 
  #
! # Leave these lines in TEMPORARILY for compat with cmd, Python, Quake.
  #
  CM3VERSION=${CM3VERSION:-"d5.7.0"}
  CM3VERSIONNUM=${CM3VERSIONNUM:-"050700"}
  CM3LASTCHANGED=${CM3LASTCHANGED:-"2008-03-16"}
  
+ CM3_INSTALL=${CM3_INSTALL:-`dirname \`find_exe cm3 /usr/local/cm3/\ \``}
+ 
  CM3_GCC_BACKEND=yes
  CM3_GDB=no
  #

 - Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20080420/af0c33ec/attachment-0001.html>


More information about the M3devel mailing list