coccinelle: add localversion information
cover coccinelle: add localversion information
From: "Luis R. Rodriguez" <[email protected]>
When working with pycocci I noticed that 1) the git tree version of coccinelle at Inria has different tags than the git tree at github, and 2) that I was not able to easily get Coccinelle's own tools to determine if we had some sort of dirty tree or tree with changes beyond a tagged official release. As an example even though --jobs is now fixed on the inria git tree, this code is not yet on github.
The issue with 1) prevents me to build custom versions of coccinelle and get pycocci to work with my goal to support the future 1.0.2 release or a release beyond 1.0.1. The issues with 1) may hopefully be fixed by streamlining how the releases are made with development but discussion is ongoing with this.
Provided 1) was fixed, and say the inria git tree had the proper 1.0.1 tag as well, I'd then be able to modify pycocci to say: hey, use --jobs if you detect you are on a release which is > 1.0.1. I can't do this though as the version information on coccinelle does not take into consideration local deltas. I've decided to borrow the Linux kernel mechanism for determining this and allowing Coccinelle to make use of it. With these changes we will keep the version string clean if no tree modifications are on your tree and your tags are synced up.
If you have modifications you can end up either with a -dirty postfixed tree, or a tree that shows the delta of commits on top of a blessed release. For instance, if you have changes not commited you'll now get on spatch --version:
1.0.2-dirty
Likewise if your tree has some commits not upstream these will be reflected. For instance, say you had one extra commit, you'd end up with something like:
1.0.2-00001-g8870d8b0cf33
Provided we address 1) then tools can infer local hacks and let you move on with life as the coccinelle development train moves forward.
Luis R. Rodriguez (2):
autotools: unify the way to determine version information
autotools: add localversion information
Makefile | 2 +- configure.ac | 2 +- scripts/setlocalversion | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ version.sh | 4 +++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100755 scripts/setlocalversion create mode 100755 version.sh
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 1/2 autotools: unify the way to determine version information
From: "Luis R. Rodriguez" <[email protected]>
The version information you get when you run: spatch --version comes from what ./confgure.ac ends up figuring out for you. The top level Makefile uses the same mechanism to tell you and use the version information at build time, but if the strategy is updated in one place it would need to be updated in both places.
Avoid this duplicatin of work and instead just make version information come from ./version.sh script. Then if we update how we get the version information it just needs to be done in one place.
We make the version.sh script use old shell mechanisms to be able to work on any supported unix system.
--- Makefile | 2 +- configure.ac | 2 +- version.sh | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100755 version.sh
Makefile +1 -1
@@ -19,7 +19,7 @@ endif -include /etc/Makefile.coccinelle # local customizations, if any -VERSION=$(shell cat ./version | tr -d '\n') +VERSION=$(shell ./version.sh | tr -d '\n') CCVERSION=$(shell cat scripts/coccicheck/README | egrep -o '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' | head -n1) PKGVERSION=$(shell dpkg-parsechangelog -ldebian/changelog.$(DISTRIB_CODENAME) 2> /dev/null \ | sed -n 's/^Version: \(.*\)/\1/p' )
configure.ac +1 -1
@@ -3,7 +3,7 @@ dnl run 'automake -acf' to update setup/{install-sh,missing} dnl standard initialization (we only use autoconf not automake) AC_PREREQ([2.68]) -AC_INIT([coccinelle], m4_esyscmd([cat ./version | tr -d '\n']), [cocci at systeme.lip6.fr], [], [http://coccinelle.lip6.fr/]) +AC_INIT([coccinelle], m4_esyscmd([./version.sh | tr -d '\n']), [cocci at systeme.lip6.fr], [], [http://coccinelle.lip6.fr/]) AC_CONFIG_MACRO_DIR([setup]) AC_CONFIG_AUX_DIR([setup]) AC_SUBST([CONFIGURE_FLAGS], ["$*"])
version.sh new file +3 -0
@@ -0,0 +1,3 @@ +#!/bin/sh +VERSION=`cat ./version | tr -d '\n'` +printf '%s' $VERSION
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 2/2 autotools: add localversion information
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
When someone is building Coccinelle from source on a git tree with some modifications we currently cannot tell what type of modifications were, if any, were done. Add a localversion info postix which will be pegged onto the version string *iff* the git tree used has either a change non-commited yet or if the git tree has some commits beyond what was officially released and tagged.
So if you have a dirty tree with some uncommited changes the version will be postfixed with -dirty. For example if 1.0.2 was blessed and released and you had a series of uncommited changes you'd end yup with:
1.0.2-dirty
Likewise if your tree has some commits not upstream these will be reflected. For instance, say you had one extra commit, you'd end up with:
1.0.2-00001-g8870d8b0cf33
The purpose of this is to enable developers and tools within Coccinelle to be able to tell when folks have modified upstream code.
The setlocalversion file was take and modified from the Linux kernel, it was repurposed for Coccinelle by just simplifying it by hardcoding it to use the long version string if there is any delta.
--- scripts/setlocalversion | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ version.sh | 3 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100755 scripts/setlocalversion
scripts/setlocalversion new file +77 -0
@@ -0,0 +1,77 @@ +#!/bin/sh +# +# This scripts adds local version information from the version +# control systems. It was taken from the Linux kernel as of v4.2-rc2 +# and simplified for use on Coccinelle by mcgrof. The version info +# was hard coded to use long version. The svn postfix details were +# also removed. + +srctree=. + +scm_version() +{ + local short + short=false + + + # Check for git and a git repo. + if test -z "$(git rev-parse --show-cdup 2>/dev/null)" && + head=`git rev-parse --verify --short HEAD 2>/dev/null`; then + + # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore + # it, because this version is defined in the top level Makefile. + if [ -z "`git describe --exact-match 2>/dev/null`" ]; then + + # If only the short version is requested, don't bother + # running further git commands + if $short; then + echo "+" + return + fi + # If we are past a tagged commit (like + # "v2.6.30-rc5-302-g72357d5"), we pretty print it. + if atag="`git describe 2>/dev/null`"; then + echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}' + + # If we don't have a tag at all we print -g{commitish}. + else + printf '%s%s' -g $head + fi + fi + + # Check for uncommitted changes + if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then + printf '%s' -dirty + fi + + # All done with git + return + fi + + # Check for mercurial and a mercurial repo. + if test -d .hg && hgid=`hg id 2>/dev/null`; then + # Do we have an tagged version? If so, latesttagdistance == 1 + if [ "`hg log -r . --template '{latesttagdistance}'`" == "1" ]; then + id=`hg log -r . --template '{latesttag}'` + printf '%s%s' -hg "$id" + else + tag=`printf '%s' "$hgid" | cut -d' ' -f2` + if [ -z "$tag" -o "$tag" = tip ]; then + id=`printf '%s' "$hgid" | sed 's/[+ ].*//'` + printf '%s%s' -hg "$id" + fi + fi + + # Are there uncommitted changes? + # These are represented by + after the changeset id. + case "$hgid" in + *+|*+\ *) printf '%s' -dirty ;; + esac + + # All done with mercurial + return + fi +} + +res="$res$(scm_version)" +echo "$res"
version.sh +2 -1
@@ -1,3 +1,4 @@ #!/bin/sh VERSION=`cat ./version | tr -d '\n'` -printf '%s' $VERSION +LOCALVERSION=`./scripts/setlocalversion | tr -d '\n'` +printf '%s%s' $VERSION $LOCALVERSION
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 1/2 autotools: unify the way to determine version information
In reply to Luis R. RodriguezDo we still need VERSION=$(shell ./version.sh | tr -d '\n') ? I'm pretty sure that VERSION=$(shell ./version.sh) will be enough. Same for configure.ac.
Moreover why script version.sh can't be simply?
#!/bin/sh
Quoted 2 lines
tr -d '\n' < ./version
Other option would be to introduce subst. variable in configure.ac and use it in configurable Makefile. This approach might be more widespread.
2015-07-21 23:51 GMT+03:00 Luis R. Rodriguez <[email protected]>:
Quoted 70 lines
From: "Luis R. Rodriguez" <[email protected]>
The version information you get when you run: spatch --version comes from what ./confgure.ac ends up figuring out for you. The top level
Makefileuses the same mechanism to tell you and use the version information at build time, but if the strategy is updated in one place it would need to be updated in both places.Avoid this duplicatin of work and instead just make version information come from ./version.sh script. Then if we update how we get the version information it just needs to be done in one place.
We make the
version.shscript use old shell mechanisms to be able to work on any supported unix system.Cc Peter Senna Tschudin <[email protected]>Cc Nikolay Orlyuk <[email protected]>Cc S?bastien Hinderer <[email protected]>Cc Quentin Lambert <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- Makefile | 2 +- configure.ac | 2 +- version.sh | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100755 version.shMakefile +1
-2@@ -19,7 +19,7 @@ endif -include /etc/Makefile.coccinelle # local customizations, if any -VERSION=$(shell cat ./version | tr -d '\n') +VERSION=$(shell ./version.sh | tr -d '\n') CCVERSION=$(shell cat scripts/coccicheck/README | egrep -o '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' | head -n1) PKGVERSION=$(shell dpkg-parsechangelog -ldebian/changelog.$(DISTRIB_CODENAME) 2> /dev/null \ | sed -n 's/^Version: \(.*\)/\1/p' )configure.ac +1
-1@@ -3,7 +3,7 @@ dnl run 'automake -acf' to update setup/{install-sh,missing} dnl standard initialization (we only use autoconf not automake) AC_PREREQ([2.68]) -AC_INIT([coccinelle], m4_esyscmd([cat ./version | tr -d '\n']), [ cocci at systeme.lip6.fr], [], [http://coccinelle.lip6.fr/]) +AC_INIT([coccinelle], m4_esyscmd([./version.sh | tr -d '\n']), [ cocci at systeme.lip6.fr], [], [http://coccinelle.lip6.fr/])
AC_CONFIG_MACRO_DIR([setup])
AC_CONFIG_AUX_DIR([setup])
AC_SUBST([CONFIGURE_FLAGS], ["$*"])version.sh new file +3
-1@@ -0,0 +1,3 @@ +#!/bin/sh +VERSION=`cat ./version | tr -d '\n'` +printf '%s' $VERSION --
Quoted 3 lines
2.3.2.209.gd67f9d5.dirty
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20150723/e3cd44fc/attachment-0001.html>
PATCH 1/2 autotools: unify the way to determine version information
Hi,
Nikolay Orlyuk (2015/07/23 07:18 +0300):
Quoted 11 lines
Do we still need VERSION=$(shell ./version.sh | tr -d '\n') ? I'm pretty sure that VERSION=$(shell ./version.sh) will be enough. Same for configure.ac.
Moreover why scriptversion.shcan't be simply?#!/bin/sh
Quoted 2 lines
tr -d '\n' < ./version
Other option would be to introduce subst. variable in configure.ac and use it in configurable
Makefile. This approach might be more widespread.
Yes, I believe this second approach would be better.
S?bastien.
PATCH 1/2 autotools: unify the way to determine version information
In reply to Nikolay OrlyukOn Thu, Jul 23, 2015 at 07:18:34AM +0300, Nikolay Orlyuk wrote: > Do we still need VERSION=$(shell ./version.sh | tr -d '\n') ? I'm pretty
Quoted 7 lines
sure that VERSION=$(shell ./version.sh) will be enough. Same for configure.ac.
Moreover why scriptversion.shcan't be simply?#!/bin/sh
Quoted 2 lines
tr -d '\n' < ./version
These are identical:
VERSION=cat ./version | tr -d '\n'
VERSION=tr -d '\n' < ./version
I'll give you calling cat can be avoided so lets go with that. Either way we want to stash it into a variable so we can later expand on it with something not in the version file which is instead taken from the script we are adding.
Quoted 2 lines
Other option would be to introduce subst. variable in configure.ac and use it in configurable
Makefile. This approach might be more widespread.
We don't use automake, I think its best to keep it that way. I'll just remove the double tr -d calls on both configure.ac and the top level Makefile.
Luis
PATCH 1/2 autotools: unify the way to determine version information
In reply to Sébastien HindererQuoted 8 lines · S?bastien Hinderer
Hi,
Nikolay Orlyuk (2015/07/23 07:18 +0300):
Quoted 5 lines
Do we still need VERSION=$(shell ./version.sh | tr -d '\n') ? I'm pretty sure that VERSION=$(shell ./version.sh) will be enough. Same for configure.ac.
Moreover why scriptversion.shcan't be simply?
Quoted 8 lines
Quoted 6 lines
#!/bin/sh
Quoted 2 lines
tr -d '\n' < ./version
Other option would be to introduce subst. variable in configure.ac and use it in configurable
Makefile. This approach might be more widespread.Yes, I believe this second approach would be better.
Do you mean AC_SUBST()? Using AC_SUBST() is overkill and we don't use automake. But up to you folks. I try to avoid using autotools at all costs so if you would like that instead a replacement patch by you might be more suitable.
Luis
PATCH 1/2 autotools: unify the way to determine version information
In reply to Luis R. Rodriguez2015-07-24 20:12 GMT+03:00 Luis R. Rodriguez <[email protected]>:
Quoted 12 lines
On Thu, Jul 23, 2015 at 07:18:34AM +0300, Nikolay Orlyuk wrote: > Do we still need VERSION=$(shell ./version.sh | tr -d '\n') ? I'm pretty
Quoted 7 lines
sure that VERSION=$(shell ./version.sh) will be enough. Same for configure.ac.
Moreover why scriptversion.shcan't be simply?#!/bin/sh
Quoted 2 lines
tr -d '\n' < ./version
These are identical:
Quoted 8 lines
VERSION=
cat ./version | tr -d '\n'
VERSION=tr -d '\n' < ./versionI'll give you calling cat can be avoided so lets go with that. Either way we want to stash it into a variable so we can later expand on it with something not in the version file which is instead taken from the script we are adding.
That script is equivalent to:
#!/bin/sh
Quoted 3 lines
tr -d '\n' < version
./scripts/setlocalversion| tr -d '\n'
Storing variables just to expand it isn't required. I'd agree if there would be something like "${VERSION}-dirty${LOCALVERSION}" or printf "%s.%s" "${VERSION}" "${LOCALVERSION}"
Just collecting output to print it again as-is seems redundant for me. That's all I wanted to say regarding that script.
Note that expansion of variable as argument without double-quotes for printf "%s" will results in removing spaces. If that's normal behavior it can be achieved more explicitly with "tr -d ' \n'" (include space in set of deleted chars alongside with '\n')
Quoted 8 lines
Quoted 1 line
Other option would be to introduce subst. variable in configure.ac and
use
Quoted 1 line
it in configurable
Makefile. This approach might be more widespread.We don't use automake, I think its best to keep it that way. I'll just remove the double tr -d calls on both configure.ac and the top level
Makefile.
I do not refer to automake.
But we definitely use AC_INIT in configure.ac (autoconf) and according to
http://www.gnu.org/software/autoconf/manual/autoconf.html#Initializing-configure
we already can write:
Makefile +0 -1
@@ -43,7 +43,6 @@ endif -include /etc/Makefile.coccinelle # local customizations, if any -VERSION=$(shell cat ./version | tr -d '\n') CCVERSION=$(shell cat scripts/coccicheck/README | egrep -o
'[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' | head -n1)
PKGVERSION=$(shell dpkg-parsechangelog
-ldebian/changelog.$(DISTRIB_CODENAME) 2> /dev/null \
| sed -n 's/^Version: \(.*\)/\1/p' )Makefile.config.in +2 -0
@@ -1,3 +1,5 @@ +VERSION=@PACKAGE_VERSION@ + # * for each library $1, add another entry in the same manner MAKELIBS=@MAKE_dynlink@ @MAKE_menhirLib@ @MAKE_pycaml@ @MAKE_pcre@ \ @MAKE_parmap@
== cut ==
Quoted 3 lines
Luis
Cheers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20150726/30b0df5c/attachment.html>
PATCH 1/2 autotools: unify the way to determine version information
Quoted 30 lines · Nikolay Orlyuk
2015-07-24 20:12 GMT+03:00 Luis R. Rodriguez <[email protected]>:
Quoted 12 lines
On Thu, Jul 23, 2015 at 07:18:34AM +0300, Nikolay Orlyuk wrote: > Do we still need VERSION=$(shell ./version.sh | tr -d '\n') ? I'm pretty
Quoted 7 lines
sure that VERSION=$(shell ./version.sh) will be enough. Same for configure.ac.
Moreover why scriptversion.shcan't be simply?#!/bin/sh
Quoted 2 lines
tr -d '\n' < ./version
These are identical:
Quoted 8 lines
VERSION=
cat ./version | tr -d '\n'
VERSION=tr -d '\n' < ./versionI'll give you calling cat can be avoided so lets go with that. Either way we want to stash it into a variable so we can later expand on it with something not in the version file which is instead taken from the script we are adding.
That script is equivalent to:
#!/bin/sh
Quoted 3 lines
tr -d '\n' < version
./scripts/setlocalversion| tr -d '\n'
Quoted 5 lines
Storing variables just to expand it isn't required. I'd agree if there would be something like "${VERSION}-dirty${LOCALVERSION}" or printf "%s.%s" "${VERSION}" "${LOCALVERSION}"
Just collecting output to print it again as-is seems redundant for me. That's all I wanted to say regarding that script.
Its a small optimization you seek for, the tradefoff IMHO is readibility and since this code does not run often I don't think the optimization of not using a variable helps much, and would easily allow extensions and customizations as you note.
Quoted 4 lines
Note that expansion of variable as argument without double-quotes for printf "%s" will results in removing spaces. If that's normal behavior it can be achieved more explicitly with "tr -d ' \n'" (include space in set of deleted chars alongside with '\n')
Not sure if that printf behaviour is POSIX compliant, in fact I hate /bin/sh complaince confusion for the ambiguity here and in other places. I'll go with what you propose.
Quoted 33 lines
Quoted 8 lines
Quoted 1 line
Other option would be to introduce subst. variable in configure.ac and
use
Quoted 1 line
it in configurable
Makefile. This approach might be more widespread.We don't use automake, I think its best to keep it that way. I'll just remove the double tr -d calls on both configure.ac and the top level
Makefile.I do not refer to automake.
But we definitely useAC_INITin configure.ac (autoconf) and according to
http://www.gnu.org/software/autoconf/manual/autoconf.html#Initializing-configure
we already can write:Makefile +0
-2@@ -43,7 +43,6 @@ endif -include /etc/Makefile.coccinelle # local customizations, if any -VERSION=$(shell cat ./version | tr -d '\n') CCVERSION=$(shell cat scripts/coccicheck/README | egrep -o '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' | head -n1) PKGVERSION=$(shell dpkg-parsechangelog -ldebian/changelog.$(DISTRIB_CODENAME) 2> /dev/null \ | sed -n 's/^Version: \(.*\)/\1/p' )Makefile.config.in +0
-0
Makefile.config.in line 5
Quoted 5 lines
Makefile.config.in +2
-0@@ -1,3 +1,5 @@ +VERSION=@PACKAGE_VERSION@ + # * for each library $1, add another entry in the same manner MAKELIBS=@MAKE_dynlink@ @MAKE_menhirLib@ @MAKE_pycaml@ @MAKE_pcre@ \ @MAKE_parmap@
Ah very nice, yes. OK I'll respin and try to use this. I also I think found a way to not require removing a git tag for a release, I'll add that too. I'll also highlight that my this respin I addressed not requiring PGP tags, instead these are optional.
Luis
[Cocci] autotools: unify the way to determine version information
In reply to Luis R. RodriguezQuoted 1 line
Using
AC_SUBST()is overkill and we don't use automake.
How do you think about the consequences from a call of the macro "AM_INIT_AUTOMAKE" then?
https://github.com/coccinelle/coccinelle/blob/e7dd46783d6addd7efad735144d85ed8fde841ce/configure.ac#L13
http://www.gnu.org/software/automake/manual/html_node/Requirements.html
Quoted 2 lines
I try to avoid using autotools at all costs so if you would like that instead a replacement patch by you might be more suitable.
Do you fiddle also with other software build specifications occasionally?
Regards,
Markus
[Cocci] autotools: unify the way to determine version information
Quoted 5 lines · SF Markus Elfring
Quoted 1 line
Using
AC_SUBST()is overkill and we don't use automake.How do you think about the consequences from a call of the macro "
AM_INIT_AUTOMAKE" then?
https://github.com/coccinelle/coccinelle/blob/e7dd46783d6addd7efad735144d85ed8fde841ce/configure.ac#L13
http://www.gnu.org/software/automake/manual/html_node/Requirements.html
Can't say I care.
Quoted 4 lines
Quoted 2 lines
I try to avoid using autotools at all costs so if you would like that instead a replacement patch by you might be more suitable.
Do you fiddle also with other software build specifications occasionally?
I've only looked enough at autotools to pationately hate it.
Its year 2015 and the requirements for designing autotools should now be superceded with simple mechanisms and modern helpers.
Luis