flashrom relies on svn to export tarballs and only prints the last svn revision in the version message even if flashrom is in a git tree.
Print extended version information (version, svn revision, git hash, repository URL). Allow exporting from git trees.
This should make git users first-class citizens like svn users.
Side note: If anyone has an idea how to make the export target more beautiful (80 column limit etc.), please tell me.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-gitfriendly/Makefile =================================================================== --- flashrom-gitfriendly/Makefile (Revision 1145) +++ flashrom-gitfriendly/Makefile (Arbeitskopie) @@ -97,13 +97,15 @@ # of the checked out flashrom files. # Note to packagers: Any tree exported with "make export" or "make tarball" # will not require subversion. The downloadable snapshots are already exported. -SVNVERSION := $(shell LC_ALL=C svnversion -cn . 2>/dev/null | sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | grep "[0-9]" || LC_ALL=C svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || LC_ALL=C git svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || echo unknown) +SCMVERSION := $(shell LC_ALL=C svnversion -cn . 2>/dev/null | sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | grep "[0-9]" || LC_ALL=C svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || LC_ALL=C git svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || echo unknown) +SCMEXTVERSION := $(shell LC_ALL=C git rev-parse HEAD 2>/dev/null | sed 's/^./-\0/') +SCMURL := $(shell LC_ALL=C svn info 2>/dev/null | grep URL: | sed 's/.*URL:[[:blank:]]*//' | grep ^. || LC_ALL=C git remote show origin 2>/dev/null |grep URL: | sed 's/.*URL:[[:blank:]]*//' | grep ^. || echo unknown )
RELEASE := 0.9.2 -VERSION := $(RELEASE)-r$(SVNVERSION) +VERSION := $(RELEASE)-r$(SCMVERSION)$(SCMEXTVERSION) RELEASENAME ?= $(VERSION)
-SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"' +SCMDEF := -D'FLASHROM_VERSION="$(VERSION)"' -D'FLASHROM_SCMURL="$(SCMURL)"'
# Always enable internal/onboard support for now. CONFIG_INTERNAL ?= yes @@ -310,7 +312,7 @@ TAROPTIONS = $(shell LC_ALL=C tar --version|grep -q GNU && echo "--owner=root --group=root")
%.o: %.c .features - $(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FEATURE_CFLAGS) $(SVNDEF) -o $@ -c $< + $(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FEATURE_CFLAGS) $(SCMDEF) -o $@ -c $<
# Make sure to add all names of generated binaries here. # This includes all frontends and libflashrom. @@ -420,9 +422,12 @@
export: @rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME) - @svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME) - @sed "s/^SVNVERSION.*/SVNVERSION := $(SVNVERSION)/" Makefile >$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile - @LC_ALL=C svn log >$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog + @svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME) 2>/dev/null || git checkout-index -a -f --prefix=$(EXPORTDIR)/flashrom-$(RELEASENAME)/ + @# If SCMVERSION or SCMEXTVERSION contain a slash or SCMURL contains a hash, this will explode + @sed "s/^SCMVERSION.*/SCMVERSION := $(SCMVERSION)/;s/^SCMEXTVERSION.*/SCMEXTVERSION := $(SCMEXTVERSION)/;s#^SCMURL.*#SCMURL := $(SCMURL)#" Makefile >$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile + @# ChangeLog should be in English, but we want UTF-8 for names. + @( LC_ALL=en_US.UTF-8 svn log 2>/dev/null || LC_ALL=en_US.UTF-8 git log 2>/dev/null || echo "Unable to extract log from SCM" ) >$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog + @rm -f $(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitignore $(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitattributes $(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitmodules @echo Exported $(EXPORTDIR)/flashrom-$(RELEASENAME)/
tarball: export Index: flashrom-gitfriendly/flashrom.c =================================================================== --- flashrom-gitfriendly/flashrom.c (Revision 1145) +++ flashrom-gitfriendly/flashrom.c (Arbeitskopie) @@ -1355,6 +1355,7 @@ void print_version(void) { msg_ginfo("flashrom v%s", flashrom_version); + msg_ginfo(" from " FLASHROM_SCMURL ","); print_sysinfo(); }
@@ -1362,7 +1363,6 @@ { msg_ginfo("flashrom is free software, get the source code at " "http://www.flashrom.org%5Cn"); - msg_ginfo("\n"); }
int selfcheck(void)
Looks pretty good so far!
For the benefit of everyone who missed the excitement on IRC, there is one major caveat to this patch: Those using a git repository probably have stale SVN metadata, which means the upstream Flashrom SVN information in the version string will be incorrect.
For example, if I clone the Chromium OS flashrom branch (git clone http://src.chromium.org/git/flashrom.git) and run "git svn info", I'll get a message saying "Unable to determine upstream SVN information from working tree history." After adding the upstream SVN repo as a remote repository and doing "git svn fetch", I'll get something like this: dhendrix@thegates:flashrom$ git svn info Path: . URL: svn://coreboot.org/flashrom/trunk Repository Root: svn://coreboot.org/flashrom Repository UUID: 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 Revision: 1011 Node Kind: directory Schedule: normal Last Changed Author: uwe Last Changed Rev: 1011 Last Changed Date: 2010-05-24 10:39:14 -0700 (Mon, 24 May 2010)
In this example, r1011 is incorrect.
Carl-Daniel root caused the issue and has a script that seems to workaround it. Here is his blogpost which summarizes the problem and workaround very well: http://blogs.coreboot.org/blog/2010/08/27/git-svn-info-unable-to-determine-u...
Using Carl-Daniel's script in the same repo, I get: dhendrix@thegates:flashrom$ sh /tmp/cdh.sh URL: svn://coreboot.org/flashrom/trunk Repository UUID: 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 Revision: 1145 Last Changed Author: hailfinger
which is (currently) correct.
Now to figure out how best to integrate this... Can we put the script in util/ and have the Makefile invoke it when it detects we're using a git repo?
On Sat, Aug 21, 2010 at 11:21 AM, Carl-Daniel Hailfinger < c-d.hailfinger.devel.2006@gmx.net> wrote:
flashrom relies on svn to export tarballs and only prints the last svn revision in the version message even if flashrom is in a git tree.
Print extended version information (version, svn revision, git hash, repository URL). Allow exporting from git trees.
This should make git users first-class citizens like svn users.
Side note: If anyone has an idea how to make the export target more beautiful (80 column limit etc.), please tell me.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-gitfriendly/Makefile
--- flashrom-gitfriendly/Makefile (Revision 1145) +++ flashrom-gitfriendly/Makefile (Arbeitskopie) @@ -97,13 +97,15 @@ # of the checked out flashrom files. # Note to packagers: Any tree exported with "make export" or "make tarball" # will not require subversion. The downloadable snapshots are already exported. -SVNVERSION := $(shell LC_ALL=C svnversion -cn . 2>/dev/null | sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | grep "[0-9]" || LC_ALL=C svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || LC_ALL=C git svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || echo unknown) +SCMVERSION := $(shell LC_ALL=C svnversion -cn . 2>/dev/null | sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | grep "[0-9]" || LC_ALL=C svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || LC_ALL=C git svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || echo unknown) +SCMEXTVERSION := $(shell LC_ALL=C git rev-parse HEAD 2>/dev/null | sed 's/^./-\0/') +SCMURL := $(shell LC_ALL=C svn info 2>/dev/null | grep URL: | sed 's/.*URL:[[:blank:]]*//' | grep ^. || LC_ALL=C git remote show origin 2>/dev/null |grep URL: | sed 's/.*URL:[[:blank:]]*//' | grep ^. || echo unknown )
RELEASE := 0.9.2 -VERSION := $(RELEASE)-r$(SVNVERSION) +VERSION := $(RELEASE)-r$(SCMVERSION)$(SCMEXTVERSION) RELEASENAME ?= $(VERSION)
-SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"' +SCMDEF := -D'FLASHROM_VERSION="$(VERSION)"' -D'FLASHROM_SCMURL="$(SCMURL)"'
# Always enable internal/onboard support for now. CONFIG_INTERNAL ?= yes @@ -310,7 +312,7 @@ TAROPTIONS = $(shell LC_ALL=C tar --version|grep -q GNU && echo "--owner=root --group=root")
%.o: %.c .features
$(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FEATURE_CFLAGS) $(SVNDEF) -o $@
-c $<
$(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FEATURE_CFLAGS) $(SCMDEF) -o $@
-c $<
# Make sure to add all names of generated binaries here. # This includes all frontends and libflashrom. @@ -420,9 +422,12 @@
export: @rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME)
@svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
@sed "s/^SVNVERSION.*/SVNVERSION := $(SVNVERSION)/" Makefile
$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
@LC_ALL=C svn log >$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
@svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
2>/dev/null || git checkout-index -a -f --prefix=$(EXPORTDIR)/flashrom-$(RELEASENAME)/
@# If SCMVERSION or SCMEXTVERSION contain a slash or SCMURL
contains a hash, this will explode
@sed "s/^SCMVERSION.*/SCMVERSION :=
$(SCMVERSION)/;s/^SCMEXTVERSION.*/SCMEXTVERSION := $(SCMEXTVERSION)/;s#^SCMURL.*#SCMURL := $(SCMURL)#" Makefile
$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
@# ChangeLog should be in English, but we want UTF-8 for names.
@( LC_ALL=en_US.UTF-8 svn log 2>/dev/null || LC_ALL=en_US.UTF-8 git
log 2>/dev/null || echo "Unable to extract log from SCM" )
$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
@rm -f $(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitignore
$(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitattributes $(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitmodules @echo Exported $(EXPORTDIR)/flashrom-$(RELEASENAME)/
tarball: export Index: flashrom-gitfriendly/flashrom.c =================================================================== --- flashrom-gitfriendly/flashrom.c (Revision 1145) +++ flashrom-gitfriendly/flashrom.c (Arbeitskopie) @@ -1355,6 +1355,7 @@ void print_version(void) { msg_ginfo("flashrom v%s", flashrom_version);
msg_ginfo(" from " FLASHROM_SCMURL ","); print_sysinfo();
}
@@ -1362,7 +1363,6 @@ { msg_ginfo("flashrom is free software, get the source code at " "http://www.flashrom.org%5Cn");
msg_ginfo("\n");
}
int selfcheck(void)
flashrom mailing list flashrom@flashrom.org http://www.flashrom.org/mailman/listinfo/flashrom
[+vadim]
On Fri, Aug 27, 2010 at 1:49 PM, David Hendricks dhendrix@google.comwrote:
Looks pretty good so far!
For the benefit of everyone who missed the excitement on IRC, there is one major caveat to this patch: Those using a git repository probably have stale SVN metadata, which means the upstream Flashrom SVN information in the version string will be incorrect.
For example, if I clone the Chromium OS flashrom branch (git clone http://src.chromium.org/git/flashrom.git) and run "git svn info", I'll get a message saying "Unable to determine upstream SVN information from working tree history." After adding the upstream SVN repo as a remote repository and doing "git svn fetch", I'll get something like this: dhendrix@thegates:flashrom$ git svn info Path: . URL: svn://coreboot.org/flashrom/trunk Repository Root: svn://coreboot.org/flashrom Repository UUID: 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 Revision: 1011 Node Kind: directory Schedule: normal Last Changed Author: uwe Last Changed Rev: 1011 Last Changed Date: 2010-05-24 10:39:14 -0700 (Mon, 24 May 2010)
In this example, r1011 is incorrect.
Carl-Daniel root caused the issue and has a script that seems to workaround it. Here is his blogpost which summarizes the problem and workaround very well: http://blogs.coreboot.org/blog/2010/08/27/git-svn-info-unable-to-determine-u...
Using Carl-Daniel's script in the same repo, I get: dhendrix@thegates:flashrom$ sh /tmp/cdh.sh URL: svn://coreboot.org/flashrom/trunk Repository UUID: 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 Revision: 1145 Last Changed Author: hailfinger
which is (currently) correct.
Now to figure out how best to integrate this... Can we put the script in util/ and have the Makefile invoke it when it detects we're using a git repo?
On Sat, Aug 21, 2010 at 11:21 AM, Carl-Daniel Hailfinger < c-d.hailfinger.devel.2006@gmx.net> wrote:
flashrom relies on svn to export tarballs and only prints the last svn revision in the version message even if flashrom is in a git tree.
Print extended version information (version, svn revision, git hash, repository URL). Allow exporting from git trees.
This should make git users first-class citizens like svn users.
Side note: If anyone has an idea how to make the export target more beautiful (80 column limit etc.), please tell me.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-gitfriendly/Makefile
--- flashrom-gitfriendly/Makefile (Revision 1145) +++ flashrom-gitfriendly/Makefile (Arbeitskopie) @@ -97,13 +97,15 @@ # of the checked out flashrom files. # Note to packagers: Any tree exported with "make export" or "make tarball" # will not require subversion. The downloadable snapshots are already exported. -SVNVERSION := $(shell LC_ALL=C svnversion -cn . 2>/dev/null | sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | grep "[0-9]" || LC_ALL=C svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || LC_ALL=C git svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || echo unknown) +SCMVERSION := $(shell LC_ALL=C svnversion -cn . 2>/dev/null | sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | grep "[0-9]" || LC_ALL=C svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || LC_ALL=C git svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || echo unknown) +SCMEXTVERSION := $(shell LC_ALL=C git rev-parse HEAD 2>/dev/null | sed 's/^./-\0/') +SCMURL := $(shell LC_ALL=C svn info 2>/dev/null | grep URL: | sed 's/.*URL:[[:blank:]]*//' | grep ^. || LC_ALL=C git remote show origin 2>/dev/null |grep URL: | sed 's/.*URL:[[:blank:]]*//' | grep ^. || echo unknown )
RELEASE := 0.9.2 -VERSION := $(RELEASE)-r$(SVNVERSION) +VERSION := $(RELEASE)-r$(SCMVERSION)$(SCMEXTVERSION) RELEASENAME ?= $(VERSION)
-SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"' +SCMDEF := -D'FLASHROM_VERSION="$(VERSION)"' -D'FLASHROM_SCMURL="$(SCMURL)"'
# Always enable internal/onboard support for now. CONFIG_INTERNAL ?= yes @@ -310,7 +312,7 @@ TAROPTIONS = $(shell LC_ALL=C tar --version|grep -q GNU && echo "--owner=root --group=root")
%.o: %.c .features
$(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FEATURE_CFLAGS) $(SVNDEF) -o $@
-c $<
$(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FEATURE_CFLAGS) $(SCMDEF) -o $@
-c $<
# Make sure to add all names of generated binaries here. # This includes all frontends and libflashrom. @@ -420,9 +422,12 @@
export: @rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME)
@svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
@sed "s/^SVNVERSION.*/SVNVERSION := $(SVNVERSION)/" Makefile
$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
@LC_ALL=C svn log >$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
@svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
2>/dev/null || git checkout-index -a -f --prefix=$(EXPORTDIR)/flashrom-$(RELEASENAME)/
@# If SCMVERSION or SCMEXTVERSION contain a slash or SCMURL
contains a hash, this will explode
@sed "s/^SCMVERSION.*/SCMVERSION :=
$(SCMVERSION)/;s/^SCMEXTVERSION.*/SCMEXTVERSION := $(SCMEXTVERSION)/;s#^SCMURL.*#SCMURL := $(SCMURL)#" Makefile
$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
@# ChangeLog should be in English, but we want UTF-8 for names.
@( LC_ALL=en_US.UTF-8 svn log 2>/dev/null || LC_ALL=en_US.UTF-8
git log 2>/dev/null || echo "Unable to extract log from SCM" )
$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
@rm -f $(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitignore
$(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitattributes $(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitmodules @echo Exported $(EXPORTDIR)/flashrom-$(RELEASENAME)/
tarball: export Index: flashrom-gitfriendly/flashrom.c =================================================================== --- flashrom-gitfriendly/flashrom.c (Revision 1145) +++ flashrom-gitfriendly/flashrom.c (Arbeitskopie) @@ -1355,6 +1355,7 @@ void print_version(void) { msg_ginfo("flashrom v%s", flashrom_version);
msg_ginfo(" from " FLASHROM_SCMURL ","); print_sysinfo();
}
@@ -1362,7 +1363,6 @@ { msg_ginfo("flashrom is free software, get the source code at " "http://www.flashrom.org%5Cn");
msg_ginfo("\n");
}
int selfcheck(void)
flashrom mailing list flashrom@flashrom.org http://www.flashrom.org/mailman/listinfo/flashrom
-- David Hendricks (dhendrix) Systems Software Engineer, Google Inc.
On Fri, Aug 27, 2010 at 1:52 PM, David Hendricks dhendrix@google.com wrote:
[+vadim]
On Fri, Aug 27, 2010 at 1:49 PM, David Hendricks dhendrix@google.com wrote:
Looks pretty good so far! For the benefit of everyone who missed the excitement on IRC, there is one major caveat to this patch: Those using a git repository probably have stale SVN metadata, which means the upstream Flashrom SVN information in the version string will be incorrect. For example, if I clone the Chromium OS flashrom branch (git clone http://src.chromium.org/git/flashrom.git) and run "git svn info", I'll get a message saying "Unable to determine upstream SVN information from working tree history." After adding the upstream SVN repo as a remote repository and doing "git svn fetch", I'll get something like this: dhendrix@thegates:flashrom$ git svn info Path: . URL: svn://coreboot.org/flashrom/trunk Repository Root: svn://coreboot.org/flashrom Repository UUID: 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 Revision: 1011 Node Kind: directory Schedule: normal Last Changed Author: uwe Last Changed Rev: 1011 Last Changed Date: 2010-05-24 10:39:14 -0700 (Mon, 24 May 2010) In this example, r1011 is incorrect. Carl-Daniel root caused the issue and has a script that seems to workaround it. Here is his blogpost which summarizes the problem and workaround very well: http://blogs.coreboot.org/blog/2010/08/27/git-svn-info-unable-to-determine-u... Using Carl-Daniel's script in the same repo, I get: dhendrix@thegates:flashrom$ sh /tmp/cdh.sh URL: svn://coreboot.org/flashrom/trunk Repository UUID: 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 Revision: 1145 Last Changed Author: hailfinger which is (currently) correct. Now to figure out how best to integrate this... Can we put the script in util/ and have the Makefile invoke it when it detects we're using a git repo?
guys, I am joining the party late so to speak, I have a couple of questions:
- why do you need to integrate shell scripts into the Makefile. It is perfectly valid to put the code in a file in ./util/
- when local git tree (or svn tree to that matter) has modified files - this should be reflected in the version string, to indicate that the code was built off modified source tree.
- the git hash on its own is not good enough: you can't tell looking at two hashes which one is more recent, this is why in case svn information is not available the date should be included. In case the source is built off pristine sources, the date should be the git log date, in case the tree was modified, the date should be the build date.
- *anything* isbetter than producing multiple different images with the same version string
I have a patch which achieves most of that, I'll share it with you in a bit later,
cheers, /vb
- it is much better to have a stale svn revision
On Sat, Aug 21, 2010 at 11:21 AM, Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net wrote:
flashrom relies on svn to export tarballs and only prints the last svn revision in the version message even if flashrom is in a git tree.
Print extended version information (version, svn revision, git hash, repository URL). Allow exporting from git trees.
This should make git users first-class citizens like svn users.
Side note: If anyone has an idea how to make the export target more beautiful (80 column limit etc.), please tell me.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-gitfriendly/Makefile
--- flashrom-gitfriendly/Makefile (Revision 1145) +++ flashrom-gitfriendly/Makefile (Arbeitskopie) @@ -97,13 +97,15 @@ # of the checked out flashrom files. # Note to packagers: Any tree exported with "make export" or "make tarball" # will not require subversion. The downloadable snapshots are already exported. -SVNVERSION := $(shell LC_ALL=C svnversion -cn . 2>/dev/null | sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | grep "[0-9]" || LC_ALL=C svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || LC_ALL=C git svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || echo unknown) +SCMVERSION := $(shell LC_ALL=C svnversion -cn . 2>/dev/null | sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | grep "[0-9]" || LC_ALL=C svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || LC_ALL=C git svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || echo unknown) +SCMEXTVERSION := $(shell LC_ALL=C git rev-parse HEAD 2>/dev/null | sed 's/^./-\0/') +SCMURL := $(shell LC_ALL=C svn info 2>/dev/null | grep URL: | sed 's/.*URL:[[:blank:]]*//' | grep ^. || LC_ALL=C git remote show origin 2>/dev/null |grep URL: | sed 's/.*URL:[[:blank:]]*//' | grep ^. || echo unknown )
RELEASE := 0.9.2 -VERSION := $(RELEASE)-r$(SVNVERSION) +VERSION := $(RELEASE)-r$(SCMVERSION)$(SCMEXTVERSION) RELEASENAME ?= $(VERSION)
-SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"' +SCMDEF := -D'FLASHROM_VERSION="$(VERSION)"' -D'FLASHROM_SCMURL="$(SCMURL)"'
# Always enable internal/onboard support for now. CONFIG_INTERNAL ?= yes @@ -310,7 +312,7 @@ TAROPTIONS = $(shell LC_ALL=C tar --version|grep -q GNU && echo "--owner=root --group=root")
%.o: %.c .features
- $(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FEATURE_CFLAGS) $(SVNDEF) -o
$@ -c $<
- $(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FEATURE_CFLAGS) $(SCMDEF) -o
$@ -c $<
# Make sure to add all names of generated binaries here. # This includes all frontends and libflashrom. @@ -420,9 +422,12 @@
export: @rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME)
- @svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
- @sed "s/^SVNVERSION.*/SVNVERSION := $(SVNVERSION)/" Makefile
$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
- @LC_ALL=C svn log >$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
- @svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
2>/dev/null || git checkout-index -a -f --prefix=$(EXPORTDIR)/flashrom-$(RELEASENAME)/
- @# If SCMVERSION or SCMEXTVERSION contain a slash or SCMURL
contains a hash, this will explode
- @sed "s/^SCMVERSION.*/SCMVERSION :=
$(SCMVERSION)/;s/^SCMEXTVERSION.*/SCMEXTVERSION := $(SCMEXTVERSION)/;s#^SCMURL.*#SCMURL := $(SCMURL)#" Makefile
$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
- @# ChangeLog should be in English, but we want UTF-8 for names.
- @( LC_ALL=en_US.UTF-8 svn log 2>/dev/null || LC_ALL=en_US.UTF-8
git log 2>/dev/null || echo "Unable to extract log from SCM" )
$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
- @rm -f $(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitignore
$(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitattributes $(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitmodules @echo Exported $(EXPORTDIR)/flashrom-$(RELEASENAME)/
tarball: export Index: flashrom-gitfriendly/flashrom.c =================================================================== --- flashrom-gitfriendly/flashrom.c (Revision 1145) +++ flashrom-gitfriendly/flashrom.c (Arbeitskopie) @@ -1355,6 +1355,7 @@ void print_version(void) { msg_ginfo("flashrom v%s", flashrom_version);
- msg_ginfo(" from " FLASHROM_SCMURL ",");
print_sysinfo(); }
@@ -1362,7 +1363,6 @@ { msg_ginfo("flashrom is free software, get the source code at " "http://www.flashrom.org%5Cn");
- msg_ginfo("\n");
}
int selfcheck(void)
flashrom mailing list flashrom@flashrom.org http://www.flashrom.org/mailman/listinfo/flashrom
-- David Hendricks (dhendrix) Systems Software Engineer, Google Inc.
-- David Hendricks (dhendrix) Systems Software Engineer, Google Inc.
guys, here is the change for your review:
http://codereview.chromium.org/3265003/show
It does not deal with the recent addition which retrieves SVN revision number, that part can be easily added, it mostly makes the git version display much more useful.
Ideally we get something like this into the tree.
cheers, /vb
On Fri, Aug 27, 2010 at 2:08 PM, Vadim Bendebury (вб) vbendeb@google.com wrote:
On Fri, Aug 27, 2010 at 1:52 PM, David Hendricks dhendrix@google.com wrote:
[+vadim]
On Fri, Aug 27, 2010 at 1:49 PM, David Hendricks dhendrix@google.com wrote:
Looks pretty good so far! For the benefit of everyone who missed the excitement on IRC, there is one major caveat to this patch: Those using a git repository probably have stale SVN metadata, which means the upstream Flashrom SVN information in the version string will be incorrect. For example, if I clone the Chromium OS flashrom branch (git clone http://src.chromium.org/git/flashrom.git) and run "git svn info", I'll get a message saying "Unable to determine upstream SVN information from working tree history." After adding the upstream SVN repo as a remote repository and doing "git svn fetch", I'll get something like this: dhendrix@thegates:flashrom$ git svn info Path: . URL: svn://coreboot.org/flashrom/trunk Repository Root: svn://coreboot.org/flashrom Repository UUID: 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 Revision: 1011 Node Kind: directory Schedule: normal Last Changed Author: uwe Last Changed Rev: 1011 Last Changed Date: 2010-05-24 10:39:14 -0700 (Mon, 24 May 2010) In this example, r1011 is incorrect. Carl-Daniel root caused the issue and has a script that seems to workaround it. Here is his blogpost which summarizes the problem and workaround very well: http://blogs.coreboot.org/blog/2010/08/27/git-svn-info-unable-to-determine-u... Using Carl-Daniel's script in the same repo, I get: dhendrix@thegates:flashrom$ sh /tmp/cdh.sh URL: svn://coreboot.org/flashrom/trunk Repository UUID: 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 Revision: 1145 Last Changed Author: hailfinger which is (currently) correct. Now to figure out how best to integrate this... Can we put the script in util/ and have the Makefile invoke it when it detects we're using a git repo?
guys, I am joining the party late so to speak, I have a couple of questions:
- why do you need to integrate shell scripts into the Makefile. It is
perfectly valid to put the code in a file in ./util/
- when local git tree (or svn tree to that matter) has modified files
- this should be reflected in the version string, to indicate that the
code was built off modified source tree.
- the git hash on its own is not good enough: you can't tell looking
at two hashes which one is more recent, this is why in case svn information is not available the date should be included. In case the source is built off pristine sources, the date should be the git log date, in case the tree was modified, the date should be the build date.
- *anything* isbetter than producing multiple different images with
the same version string
I have a patch which achieves most of that, I'll share it with you in a bit later,
cheers, /vb
- it is much better to have a stale svn revision
On Sat, Aug 21, 2010 at 11:21 AM, Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net wrote:
flashrom relies on svn to export tarballs and only prints the last svn revision in the version message even if flashrom is in a git tree.
Print extended version information (version, svn revision, git hash, repository URL). Allow exporting from git trees.
This should make git users first-class citizens like svn users.
Side note: If anyone has an idea how to make the export target more beautiful (80 column limit etc.), please tell me.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-gitfriendly/Makefile
--- flashrom-gitfriendly/Makefile (Revision 1145) +++ flashrom-gitfriendly/Makefile (Arbeitskopie) @@ -97,13 +97,15 @@ # of the checked out flashrom files. # Note to packagers: Any tree exported with "make export" or "make tarball" # will not require subversion. The downloadable snapshots are already exported. -SVNVERSION := $(shell LC_ALL=C svnversion -cn . 2>/dev/null | sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | grep "[0-9]" || LC_ALL=C svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || LC_ALL=C git svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || echo unknown) +SCMVERSION := $(shell LC_ALL=C svnversion -cn . 2>/dev/null | sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | grep "[0-9]" || LC_ALL=C svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || LC_ALL=C git svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || echo unknown) +SCMEXTVERSION := $(shell LC_ALL=C git rev-parse HEAD 2>/dev/null | sed 's/^./-\0/') +SCMURL := $(shell LC_ALL=C svn info 2>/dev/null | grep URL: | sed 's/.*URL:[[:blank:]]*//' | grep ^. || LC_ALL=C git remote show origin 2>/dev/null |grep URL: | sed 's/.*URL:[[:blank:]]*//' | grep ^. || echo unknown )
RELEASE := 0.9.2 -VERSION := $(RELEASE)-r$(SVNVERSION) +VERSION := $(RELEASE)-r$(SCMVERSION)$(SCMEXTVERSION) RELEASENAME ?= $(VERSION)
-SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"' +SCMDEF := -D'FLASHROM_VERSION="$(VERSION)"' -D'FLASHROM_SCMURL="$(SCMURL)"'
# Always enable internal/onboard support for now. CONFIG_INTERNAL ?= yes @@ -310,7 +312,7 @@ TAROPTIONS = $(shell LC_ALL=C tar --version|grep -q GNU && echo "--owner=root --group=root")
%.o: %.c .features
- $(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FEATURE_CFLAGS) $(SVNDEF) -o
$@ -c $<
- $(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FEATURE_CFLAGS) $(SCMDEF) -o
$@ -c $<
# Make sure to add all names of generated binaries here. # This includes all frontends and libflashrom. @@ -420,9 +422,12 @@
export: @rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME)
- @svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
- @sed "s/^SVNVERSION.*/SVNVERSION := $(SVNVERSION)/" Makefile
$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
- @LC_ALL=C svn log >$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
- @svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
2>/dev/null || git checkout-index -a -f --prefix=$(EXPORTDIR)/flashrom-$(RELEASENAME)/
- @# If SCMVERSION or SCMEXTVERSION contain a slash or SCMURL
contains a hash, this will explode
- @sed "s/^SCMVERSION.*/SCMVERSION :=
$(SCMVERSION)/;s/^SCMEXTVERSION.*/SCMEXTVERSION := $(SCMEXTVERSION)/;s#^SCMURL.*#SCMURL := $(SCMURL)#" Makefile
$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
- @# ChangeLog should be in English, but we want UTF-8 for names.
- @( LC_ALL=en_US.UTF-8 svn log 2>/dev/null || LC_ALL=en_US.UTF-8
git log 2>/dev/null || echo "Unable to extract log from SCM" )
$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
- @rm -f $(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitignore
$(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitattributes $(EXPORTDIR)/flashrom-$(RELEASENAME)/.gitmodules @echo Exported $(EXPORTDIR)/flashrom-$(RELEASENAME)/
tarball: export Index: flashrom-gitfriendly/flashrom.c =================================================================== --- flashrom-gitfriendly/flashrom.c (Revision 1145) +++ flashrom-gitfriendly/flashrom.c (Arbeitskopie) @@ -1355,6 +1355,7 @@ void print_version(void) { msg_ginfo("flashrom v%s", flashrom_version);
- msg_ginfo(" from " FLASHROM_SCMURL ",");
print_sysinfo(); }
@@ -1362,7 +1363,6 @@ { msg_ginfo("flashrom is free software, get the source code at " "http://www.flashrom.org%5Cn");
- msg_ginfo("\n");
}
int selfcheck(void)
flashrom mailing list flashrom@flashrom.org http://www.flashrom.org/mailman/listinfo/flashrom
-- David Hendricks (dhendrix) Systems Software Engineer, Google Inc.
-- David Hendricks (dhendrix) Systems Software Engineer, Google Inc.
On 28.08.2010 00:00, Vadim Bendebury wrote:
guys, here is the change for your review:
I have added my review there. The suggested code breaks for me.
It does not deal with the recent addition which retrieves SVN revision number, that part can be easily added, it mostly makes the git version display much more useful.
Ideally we get something like this into the tree.
What exactly was wrong with the patch I posted?
On Fri, Aug 27, 2010 at 2:08 PM, Vadim Bendebury (вб) vbendeb@google.com wrote:
On Fri, Aug 27, 2010 at 1:52 PM, David Hendricks dhendrix@google.com wrote:
[+vadim]
On Fri, Aug 27, 2010 at 1:49 PM, David Hendricks dhendrix@google.com wrote:
Looks pretty good so far! For the benefit of everyone who missed the excitement on IRC, there is one major caveat to this patch: Those using a git repository probably have stale SVN metadata, which means the upstream Flashrom SVN information in the
guys, I am joining the party late so to speak, I have a couple of questions:
- why do you need to integrate shell scripts into the Makefile. It is
perfectly valid to put the code in a file in ./util/
- when local git tree (or svn tree to that matter) has modified files
- this should be reflected in the version string, to indicate that the
code was built off modified source tree.
Debatable.
- the git hash on its own is not good enough: you can't tell looking
at two hashes which one is more recent, this is why in case svn information is not available the date should be included. In case the source is built off pristine sources, the date should be the git log date, in case the tree was modified, the date should be the build date.
If svn information is not available at all, the report is totally worthless anyway.
- *anything* isbetter than producing multiple different images with
the same version string
Of course images with the same version string will differ. Or do you really suggest to ship debug builds only, and print the version number of every used header file?
I have a patch which achieves most of that, I'll share it with you in a bit later,
I think we need a few more iterations to get this through review.
Regards, Carl-Daniel
On Mon, Aug 30, 2010 at 6:48 AM, Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net wrote:
On 28.08.2010 00:00, Vadim Bendebury wrote:
guys, here is the change for your review:
I have added my review there. The suggested code breaks for me.
Thank you for your comments, I will reply later on today PDT.
It does not deal with the recent addition which retrieves SVN revision number, that part can be easily added, it mostly makes the git version display much more useful.
Ideally we get something like this into the tree.
What exactly was wrong with the patch I posted?
mostly the fact that it did not provide time of the commit (or build, if built in a changed tree), which made it impossible to tell which version is newer.
On Fri, Aug 27, 2010 at 2:08 PM, Vadim Bendebury (вб) vbendeb@google.com wrote:
On Fri, Aug 27, 2010 at 1:52 PM, David Hendricks dhendrix@google.com wrote:
[+vadim]
On Fri, Aug 27, 2010 at 1:49 PM, David Hendricks dhendrix@google.com wrote:
Looks pretty good so far! For the benefit of everyone who missed the excitement on IRC, there is one major caveat to this patch: Those using a git repository probably have stale SVN metadata, which means the upstream Flashrom SVN information in the
guys, I am joining the party late so to speak, I have a couple of questions:
- why do you need to integrate shell scripts into the Makefile. It is
perfectly valid to put the code in a file in ./util/
- when local git tree (or svn tree to that matter) has modified files
- this should be reflected in the version string, to indicate that the
code was built off modified source tree.
Debatable.
well, we might be coming from different angles, I think it is absolutely clear in my situation: is a development environment with multiple copies quickly changing utility flying around, being able to tell that the two versions are not exactly the same would save us a lot of time and frustration.
It is less of a value in the model where the code is on the server and people just build the utility for themselves without changing it, but certainly does not hurt there either, does it?
- the git hash on its own is not good enough: you can't tell looking
at two hashes which one is more recent, this is why in case svn information is not available the date should be included. In case the source is built off pristine sources, the date should be the git log date, in case the tree was modified, the date should be the build date.
If svn information is not available at all, the report is totally worthless anyway.
It is of a less of a value, but certainly not worthless: it at least helps to tell that you are running something different or exactly the same as somebody else. It is especially helpful when people complaint about problems with flashrom on their systems.
- *anything* isbetter than producing multiple different images with
the same version string
Of course images with the same version string will differ. Or do you really suggest to ship debug builds only, and print the version number of every used header file?
This is one deep philosophical difference :). Where I come from one can always be sure that the same version string means the same code, anything else s not acceptable. In this case it is even easily achievable, we should have this benefit.
If the git tree is clean, the hash is fixed, there is no version string variations. If any file changes, we will have an indication of this fact (the + appended to the version) and a different build time each time we build. This could result in different version strings for the same code, but guarantees that different code will have different version string. Adding username of the build process would make it more robust, or we can calculate the hash of the current tree contents. This sure can and should be discussed further.
I have a patch which achieves most of that, I'll share it with you in a bit later,
I think we need a few more iterations to get this through review.
I committed it to the chromium.org tree after an LGTM just to be able to move ahead other parts of the project, but by no means is it done,
I'll fix the problem you highlighted in the review and will will reconcile with your suggested patch, stay tuned,
cheers, /vb
Regards, Carl-Daniel
I had some time to take another stab at this, make the shell script standalone (easier testing), and break the changes down much further. Much of it recycles bits and pieces which Vadim and Carl-Daniel wrote (Including the workaround from the blog post) and chops it into more digestible pieces.
I think this approach will be more maintainable and testable in the future than the huge series of shell commands in-lined in the Makefile. This also gives us the flexibility to punt disruptive changes until after the 0.9.3 release, rather than making all the changes at once.
The first patch only adds the script to util/ and is completely benign. The second patch non-disruptively changes the Makefile to utilize the script for SVNVERSION. The third patch disruptively changes the "flashrom --version" output to add the extra information. I expect we'll spend a while longer discussing the third one :-)
Here are the results after applying all three patches: dhendrix@thegates:flashrom$ ./util/getrevision.sh -h Usage: ./util/getrevision.sh <option>
Options -h or --help Display this message. -u or --upstream upstream flashrom revision -l or --local local revision (if different from upstream) -t or --timestamp timestamp of most recent modification -U or --url url associated with local copy of flashrom
*Test setup #1*: SVN repo with no local modifications Since this is an SVN repo in this case, there is no local revision to take into account. dhendrix@thegates:flashrom-head$ ./util/getrevision.sh -u -l -t -U 1155
2010-09-07 18:14:53 UTC svn://coreboot.org/flashrom/trunk
dhendrix@thegates:flashrom-head$ sudo ./flashrom --version flashrom v0.9.2-r1155 from svn://coreboot.org/flashrom/trunk, no local revision, timestamp 2010-09-07 15:03:38 +, on Linux 2.6.32-14-generic (x86_64), built with libpci 3.0.0, GCC 4.4.3, little endian flashrom is free software, get the source code at http://www.flashrom.org
*Test setup #2*: SVN repo with local modifications Since this is an SVN repo in this case, there is no local revision to take into account. However, I have changed files in this case, so the timestamp has been modified.
dhendrix@thegates:flashrom-gitfriendly$ ./util/getrevision.sh -u -l -t -U 1155
2010-09-07 14:48:24 + svn://coreboot.org/flashrom/trunk
flashrom v0.9.2-r1155 from svn://coreboot.org/flashrom/trunk, no local revision, timestamp 2010-09-07 15:03:39 +, on Linux 2.6.32-14-generic (x86_64), built with libpci 3.0.0, GCC 4.4.3, little endian flashrom is free software, get the source code at http://www.flashrom.org
*Test setup #3*: Git repo with no local modifications Since this is a git repo, we will use the hash (668198a) as the local revision.
dhendrix@thegates:flashrom-git-nomods$ ./util/getrevision.sh -u -l -t -U 1130 668198a Sep 07 2010 04:34:27 UTC http://src.chromium.org/git/flashrom.git
dhendrix@thegates:flashrom$ sudo ./flashrom --version flashrom v0.9.2-r1130 from http://src.chromium.org/git/flashrom.git, local revision 668198a, timestamp Sep 07 2010 15:21:00 +, on Linux 2.6.32-14-generic (x86_64), built with libpci 3.0.0, GCC 4.4.3, little endian flashrom is free software, get the source code at http://www.flashrom.org
*Test setup #4*: Git repo with modifications dhendrix@thegates:flashrom$ ./util/getrevision.sh -u -l -t -U 1130 b388227 Sep 07 2010 21:53:31 UTC ssh://git@gitrw.chromium.org/flashrom
dhendrix@thegates:flashrom$ sudo ./flashrom --version flashrom v0.9.2-r1130 from ssh://git@gitrw.chromium.org/flashrom, local revision b388227, timestamp Sep 07 2010 15:22:38 +, on Linux 2.6.32-14-generic (x86_64), built with libpci 3.0.0, GCC 4.4.3, little endian flashrom is free software, get the source code at http://www.flashrom.org
Signed-Off-By: David Hendricks dhendrix@google.com
...and of course I just realized that the whitespacing in the script (00_add_getrevision_script.patch) is horribly brain damaged. The attached patch is a re-hash of the script with less brain-damaged white spacing.
Signed-off-by: David Hendricks dhendrix@google.com
This allows to retrieve various data from SCM systems (git and svn) and use them in the build process to better indicate which source was used. For now only use it for the upstream (i.e. svn) revision number, which was previously only supported in native svn repositories. The new version works in svn, git-svn and even cloned git-svn repositories.
Signed-Off-By: David Hendricks dhendrix@google.com Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at --- Makefile | 2 +- util/getrevision.sh | 228 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 229 insertions(+), 1 deletion(-) create mode 100755 util/getrevision.sh
diff --git a/Makefile b/Makefile index c165ef9..da0d0da 100644 --- a/Makefile +++ b/Makefile @@ -326,7 +326,7 @@ CLI_OBJS = cli_classic.o cli_output.o print.o # of the checked out flashrom files. # Note to packagers: Any tree exported with "make export" or "make tarball" # will not require subversion. The downloadable snapshots are already exported. -SVNVERSION := $(shell LC_ALL=C svnversion -cn . 2>/dev/null | sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | grep "[0-9]" || LC_ALL=C svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || LC_ALL=C git svn info . 2>/dev/null | awk '/^Revision:/ {print $$2 }' | grep "[0-9]" || echo unknown) +SVNVERSION := $(shell ./util/getrevision.sh -u)
RELEASE := 0.9.6.1 VERSION := $(RELEASE)-r$(SVNVERSION) diff --git a/util/getrevision.sh b/util/getrevision.sh new file mode 100755 index 0000000..678d66b --- /dev/null +++ b/util/getrevision.sh @@ -0,0 +1,228 @@ +#!/bin/sh +# +# This file is part of the flashrom project. +# +# Copyright (C) 2005 coresystems GmbH stepan@coresystems.de +# Copyright (C) 2009,2010 Carl-Daniel Hailfinger +# Copyright (C) 2010 Chromium OS Authors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +EXIT_SUCCESS=0 +EXIT_FAILURE=1 + +svn_revision() { + LC_ALL=C svnversion -cn . 2>/dev/null | \ + sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | \ + grep "[0-9]" || + LC_ALL=C svn info . 2>/dev/null | \ + awk '/^Revision:/ {print $$2 }' | \ + grep "[0-9]" || + LC_ALL=C git svn info . 2>/dev/null | \ + awk '/^Revision:/ {print $$2 }' | \ + grep "[0-9]" || + echo '' +} + +svn_url() { + echo $(LC_ALL=C svn info 2>/dev/null | + grep URL: | + sed 's/.*URL:[[:blank:]]*//' | + grep ^. + ) +} + +svn_timestamp() { + local date_format="+%Y-%m-%d %H:%M:%S" + local timestamp + + # are there local changes in the client? + if svn status | egrep '^ *[ADMR] *' > /dev/null ; then + timestamp=$(date "${date_format} +") + else + # No local changes, get date of the last log record. + local last_commit_date=$(svn info | grep '^Last Changed Date:' | \ + awk '{print $4" "$5" "$6}') + timestamp=$(date --utc --date "${last_commit_date}" \ + "${date_format} UTC") + fi + + echo "${timestamp}" +} + +git_revision() { + echo $(git log --oneline | head -1 | awk '{print $1}') +} + +# Retrieve svn revision using git log data (for git mirrors) +gitsvn_revision() { + local r + + git log| + grep git-svn-id| + sed 's/.*git-svn-id:[[:blank:]]*([^@]+)@[0-9]+[[:blank:]]+([^[:blank:]]+)/\1 \2/'| + sort| + uniq| + read url uuid + + r=$(git log --grep="git-svn-id.*$uuid"| grep git-svn-id | \ + sed 's/.*@//;s/[[:blank:]].*//'| \ + sort -n | \ + tail -1) + + echo "${r}" +} + +git_timestamp() { + local date_format="+%b %d %Y %H:%M:%S" + local timestamp + + # are there local changes in the client? + if git status | \ + egrep '^# Change(s to be committed|d but not updated):$' > /dev/null + then + timestamp=$(date "${date_format} +") + else + # No local changes, get date of the last log record. + local last_commit_date=$(git log | head -3 | grep '^Date:' | \ + awk '{print $3" "$4" "$6" "$5" "$7}') + timestamp=$(date --utc --date "${last_commit_date}" \ + "${date_format} UTC") + fi + + echo "${timestamp}" +} + +git_url() { + # Only the first line of `git remote' is considered. + echo $(LC_ALL=C git remote show origin 2>/dev/null | + grep 'Fetch URL:' | + sed 's/.*URL:[[:blank:]]*//' | + grep ^. + ) +} + +scm_url() { + local url + + if [ -d ".svn" ] ; then + url=$(svn_url) + elif [ -d ".git" ] ; then + url=$(git_url) + fi + + echo "${url}" +} + +# Retrieve timestamp since last modification. If the sources are pristine, +# then the timestamp will match that of the SCM's more recent modification +# date. +timestamp() { + local t + + if [ -d ".svn" ] ; then + t=$(svn_timestamp) + elif [ -d ".git" ] ; then + t=$(git_timestamp) + fi + + echo ${t} +} + +# Retrieve local SCM revision info. This is useful if we're working in +# a even different SCM than upstream. +# +# If local copy is svn, then there is nothing to do here. +# If local copy is git, then retrieve useful git revision info +local_revision() { + local r + + if [ -d ".git" ] ; then + r=$(git_revision) + fi + + echo ${r} +} + +# Get the upstream flashrom revision stored in SVN metadata. +# +# If the local copy is svn, then use svnversion +# If the local copy is git, then scrape upstream revision from git logs +upstream_revision() { + local r + + if [ -d ".svn" ] ; then + r=$(svn_revision) + elif [ -d ".git" ] ; then + r=$(gitsvn_revision) + fi + + echo "${r}" +} + +show_help() { + echo "Usage: + ${0} <option> + +Options + -h or --help + Display this message. + -u or --upstream + upstream flashrom revision + -l or --local + local revision (if different from upstream) + -t or --timestamp + timestamp of most recent modification + -U or --url + url associated with local copy of flashrom + " + return +} + +if [ ! -n "${1}" ] +then + show_help; + echo "No options specified"; + exit ${EXIT_SUCCESS} +fi + +# The is the main loop +while [[ ${1} = -* ]]; +do + case ${1} in + -h|--help) + show_help; + shift;; + -u|--upstream) + echo "$(upstream_revision)"; + shift;; + -l|--local) + echo "$(local_revision)"; + shift;; + -t|--timestamp) + echo "$(timestamp)"; + shift;; + -U|--url) + echo "$(scm_url)"; + shift;; + *) + show_help; + echo "invalid option: ${1}" + exit ${EXIT_FAILURE} + esac; +done + +exit ${EXIT_SUCCESS}
On Tue, 7 Sep 2010 15:53:13 -0700 dhendrix at google.com (David Hendricks) wrote:
Signed-off-by: David Hendricks <dhendrix at google.com>
There is more to be done, but this is an excellent first step into the right direction IMHO.
Acked-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at and committed in r1713.
- remove bashism. - simplify some git-related code. - improved parameter and error handling. - additional -d/--date action which is similar to the timestamp action. - support for an optional path parameter. - there is only one sane time format. - and only one sane date format too. - vastly improve git_url() to print the correct remote url and "nearest" branch. - remove username from repository URLs. - add "-dirty" to local revisions if there are uncommitted changes. - indicate in local revisions how many git-only commits were done since branching from upstream svn. - fix svn_revision() fallback to svn info and remove git-svn. - print leading r in script instead of hardcode it in the makefile; no more "0.9.7-runknown". - make retrieving the upstream revision work even in cloned git-svn repositories. - more abstractions and helper functions. - less fragmentation of actual functionality.
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at --- Makefile | 5 +- util/getrevision.sh | 341 +++++++++++++++++++++++++++++----------------------- 2 files changed, 195 insertions(+), 151 deletions(-)
diff --git a/Makefile b/Makefile index 023c41d..540e5da 100644 --- a/Makefile +++ b/Makefile @@ -322,14 +322,13 @@ LIB_OBJS = layout.o flashrom.o udelay.o programmer.o
CLI_OBJS = cli_classic.o cli_output.o print.o
-# Set the flashrom version string from the highest revision number -# of the checked out flashrom files. +# Set the flashrom version string from the highest revision number of the checked out flashrom files. # Note to packagers: Any tree exported with "make export" or "make tarball" # will not require subversion. The downloadable snapshots are already exported. SVNVERSION := $(shell ./util/getrevision.sh -u)
RELEASE := 0.9.7 -VERSION := $(RELEASE)-r$(SVNVERSION) +VERSION := $(RELEASE)-$(SVNVERSION) RELEASENAME ?= $(VERSION)
SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"' diff --git a/util/getrevision.sh b/util/getrevision.sh index 098f63e..3246b74 100755 --- a/util/getrevision.sh +++ b/util/getrevision.sh @@ -1,10 +1,11 @@ -#!/bin/bash +#!/bin/sh # # This file is part of the flashrom project. # # Copyright (C) 2005 coresystems GmbH stepan@coresystems.de # Copyright (C) 2009,2010 Carl-Daniel Hailfinger # Copyright (C) 2010 Chromium OS Authors +# Copyright (C) 2013 Stefan Tauner # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,204 +28,248 @@ EXIT_FAILURE=1 # Make sure we don't get translated output export LC_ALL=C
-svn_revision() { - svnversion -cn . 2>/dev/null | \ - sed -e "s/.*://" -e "s/([0-9]*).*/\1/" | \ - grep "[0-9]" || - svn info . 2>/dev/null | \ - awk '/^Revision:/ {print $$2 }' | \ - grep "[0-9]" || - git svn info . 2>/dev/null | \ - awk '/^Revision:/ {print $$2 }' | \ - grep "[0-9]" || - echo '' +# helper functions +# first argument is the path to inspect +svn_has_local_changes() { + svn status "$1" | egrep '^ *[ADMR] *' >/dev/null }
-svn_url() { - echo $(svn info 2>/dev/null | - grep URL: | - sed 's/.*URL:[[:blank:]]*//' | - grep ^. - ) +git_has_local_changes() { + git update-index -q --refresh >/dev/null + ! git diff-index --quiet HEAD -- "$1" }
-svn_timestamp() { - local date_format="+%Y-%m-%d %H:%M:%S" - local timestamp - - # are there local changes in the client? - if svn status | egrep '^ *[ADMR] *' > /dev/null ; then - timestamp=$(date "${date_format} +") - else - # No local changes, get date of the last log record. - local last_commit_date=$(svn info | grep '^Last Changed Date:' | awk '{print $4" "$5" "$6}') - timestamp=$(date --utc --date "${last_commit_date}" \ - "${date_format} UTC") - fi - - echo "${timestamp}" +git_last_commit() { + git log --pretty=format:"%h" -1 -- "$1" }
-git_revision() { - echo $(git log --oneline | head -1 | awk '{print $1}') +svn_is_file_tracked() { + svn info "$1" >/dev/null 2>&1 }
-# Retrieve svn revision using git log data (for git mirrors) -gitsvn_revision() { - local r - - git log| - grep git-svn-id| - sed 's/.*git-svn-id:[[:blank:]]*([^@]+)@[0-9]+[[:blank:]]+([^[:blank:]]+)/\1 \2/'| - sort| - uniq| - read url uuid - - r=$(git log --grep="git-svn-id.*$uuid"| grep git-svn-id | \ - sed 's/.*@//;s/[[:blank:]].*//'| \ - sort -n | \ - tail -1) - - echo "${r}" +git_is_file_tracked() { + git ls-files --error-unmatch -- "$1" >/dev/null 2>&1 }
-git_timestamp() { - local date_format="+%b %d %Y %H:%M:%S" - local timestamp - - # are there local changes in the client? - if git status | \ - egrep '^# Change(s to be committed|d but not updated):$' > /dev/null - then - timestamp=$(date "${date_format} +") - else - # No local changes, get date of the last log record. - local last_commit_date=$(git log | head -3 | grep '^Date:' | \ - awk '{print $3" "$4" "$6" "$5" "$7}') - timestamp=$(date --utc --date "${last_commit_date}" \ - "${date_format} UTC") - fi - - echo "${timestamp}" +is_file_tracked() { + svn_is_file_tracked "$1" || git_is_file_tracked "$1" }
git_url() { - # Only the first line of `git remote' is considered. - echo $(git remote show origin 2>/dev/null | - grep 'Fetch URL:' | - sed 's/.*URL:[[:blank:]]*//' | - grep ^. - ) + last_commit=$(git_last_commit "$1") + # get all remote branches containing the last commit (excluding origin/HEAD and git-svn branches/tags) + branches=$(git branch -r --contains $last_commit | sed '///!d;/.*->.*/d;s/[\t ]*//') + if [ -z "$branches" ] ; then + echo "No remote branch contains a suitable commit">&2 + return + fi + + # find "nearest" branch + local mindiff=9000 + local target= + for branch in $branches ; do + curdiff=$(git rev-list --count $last_commit..$branch) + if [ $curdiff -ge $mindiff ] ; then + continue + fi + mindiff=$curdiff + target=$branch + done + + echo "$(git ls-remote --exit-code --get-url ${target%/*}) ${target#*/}" }
scm_url() { - local url - - if [ -d ".svn" ] ; then - url=$(svn_url) - elif [ -d ".git" ] ; then - url=$(git_url) + local url= + + if svn_is_file_tracked "$1" ; then + url="$(svn info "$1" 2>/dev/null | + grep URL: | + sed 's/.*URL:[[:blank:]]*//;s/://.*@/:///' | + grep ^.)" + elif git_is_file_tracked "$1" ; then + url="$(git_url "$1")" + else + return ${EXIT_FAILURE} fi
echo "${url}" }
# Retrieve timestamp since last modification. If the sources are pristine, -# then the timestamp will match that of the SCM's more recent modification +# then the timestamp will match that of the SCM's most recent modification # date. timestamp() { local t
- if [ -d ".svn" ] ; then - t=$(svn_timestamp) - elif [ -d ".git" ] ; then - t=$(git_timestamp) + if svn_is_file_tracked "$2" ; then + if svn_has_local_changes "$2"; then + t=$(date "$1") + else + # No local changes, get date of the last log record. + local last_commit_date="$(svn info "$2" | \ + grep '^Last Changed Date:' | \ + awk '{print $4" "$5" "$6}')" + t=$(date -d "${last_commit_date}" "$1") + fi + elif git_is_file_tracked "$2" ; then + # are there local changes? + if git_has_local_changes "$2" ; then + t=$(date "${1}") + else + # No local changes, get date of the last commit + t=$(date -d "$(git log --pretty=format:"%cD" -1 -- "$2")" "$1") + fi + else + t=$(date "$1") fi
- echo ${t} + echo "${t}" }
-# Retrieve local SCM revision info. This is useful if we're working in -# a even different SCM than upstream. -# -# If local copy is svn, then there is nothing to do here. -# If local copy is git, then retrieve useful git revision info +# Retrieve local SCM revision info. This is useful if we're working in a different SCM than upstream and/or +# have local changes. local_revision() { - local r - - if [ -d ".git" ] ; then - r=$(git_revision) + local r= + + if svn_is_file_tracked "$1" ; then + r=$(svn_has_local_changes "$1" && echo "dirty") + elif git_is_file_tracked "$1" ; then + r=$(git_last_commit "$1") + + local svn_base=$(git log --grep git-svn-id -1 --format='%h') + if [ "$svn_base" != "" ] ; then + local diff_to_svn=$(git rev-list --count ${svn_base}..${r}) + if [ "$diff_to_svn" -gt 0 ] ; then + r="$r-$diff_to_svn" + fi + fi + + if git_has_local_changes "$1" ; then + r="$r-dirty" + fi + else + return ${EXIT_FAILURE} fi
- echo ${r} + echo "${r}" }
# Get the upstream flashrom revision stored in SVN metadata. -# -# If the local copy is svn, then use svnversion -# If the local copy is git, then scrape upstream revision from git logs upstream_revision() { - local r - - if [ -d ".svn" ] ; then - r=$(svn_revision) - elif [ -d ".git" ] ; then - r=$(gitsvn_revision) + local r= + + if svn_is_file_tracked "$1" ; then + r=$(svn info "$1" 2>/dev/null | \ + grep "Last Changed Rev:" | \ + sed -e "s/^Last Changed Rev: *//" -e "s/([0-9]*).*/r\1/" | \ + grep "r[0-9]") + elif git_is_file_tracked "$1" ; then + # If this is a "native" git-svn clone we could use git svn log: + # git svn log --oneline -1 | sed 's/^r//;s/[[:blank:]].*//' or even git svn find-rev + # but it is easier to just grep for the git-svn-id unconditionally + r=$(git log --grep git-svn-id -1 -- "$1" | \ + grep git-svn-id | \ + sed 's/.*@/r/;s/[[:blank:]].*//') fi
+ if [ -z "$r" ]; then + r="unknown" # default to unknown + fi echo "${r}" }
show_help() { echo "Usage: - ${0} <option> + ${0} <command> [path]
-Options +Commands -h or --help - Display this message. - -u or --upstream - upstream flashrom revision + this message -l or --local - local revision (if different from upstream) + local revision information including an indicator for uncommitted changes + -u or --upstream + upstream revision + -U or --url + URL associated with the latest commit + -d or --date + date of most recent modification -t or --timestamp timestamp of most recent modification - -U or --url - url associated with local copy of flashrom - " +" return }
-if [ ! -n "${1}" ] -then - show_help; - echo "No options specified"; - exit ${EXIT_SUCCESS} -fi - -# The is the main loop -while [[ ${1} = -* ]]; -do - case ${1} in - -h|--help) - show_help; - shift;; - -u|--upstream) - echo "$(upstream_revision)"; - shift;; - -l|--local) - echo "$(local_revision)"; - shift;; - -t|--timestamp) - echo "$(timestamp)"; - shift;; - -U|--url) - echo "$(scm_url)"; - shift;; - *) - show_help; - echo "invalid option: ${1}" +check_action() { + if [ -n "$action" ]; then + echo "Error: Multiple actions given.">&2 exit ${EXIT_FAILURE} - esac; -done + fi +} + +main() { + local query_path= + local action= + + # The is the main loop + while [ $# -gt 0 ]; + do + case ${1} in + -h|--help) + action=show_help; + shift;; + -l|--local) + check_action $1 + action=local_revision + shift;; + -u|--upstream) + check_action $1 + action=upstream_revision + shift;; + -U|--url) + check_action $1 + action=scm_url + shift;; + -d|--date) + check_action $1 + action="timestamp +%Y-%m-%d" + shift;; + -t|--timestamp) + check_action $1 + action="timestamp +%Y-%m-%dT%H:%M:%S%z" # There is only one valid time format! ISO 8601 + shift;; + -*) + show_help; + echo "Error: Invalid option: ${1}" + exit ${EXIT_FAILURE};; + *) + if [ -z "$query_path" ] ; then + if [ ! -e "$1" ] ; then + echo "Error: Path "${1}" does not exist.">&2 + exit ${EXIT_FAILURE} + fi + query_path=$1 + else + echo "Warning: Ignoring over-abundant paramter: "${1}"">&2 + fi + shift;; + esac; + done + + # default to current directory (usually equals the whole repository) + if [ -z "$query_path" ] ; then + query_path=. + fi + if ! is_file_tracked "$query_path" ; then + echo "Warning: Path "${query_path}" is not under version control.">&2 + fi + if [ -z "$action" ] ; then + show_help + echo "Error: No actions specified" + exit ${EXIT_FAILURE} + fi + + $action "$query_path" +}
-exit ${EXIT_SUCCESS} +main $@