Patchwork Add git support to the Makefile

login
register
about
Submitter David Hendricks
Date 2010-09-07 22:45:56
Message ID <AANLkTi=YgKg+B0YhKqgb6HQEJi86-2zfLH8ONu+1GaJ3@mail.gmail.com>
Download mbox | patch
Permalink /patch/1884/
State Superseded
Headers show

Comments

David Hendricks - 2010-09-07 22:45:56
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>

Patch

Index: flashrom-gitfriendly/Makefile
===================================================================
--- flashrom-gitfriendly.orig/Makefile
+++ flashrom-gitfriendly/Makefile
@@ -97,13 +97,17 @@  all: pciutils features $(PROGRAM)$(EXEC_
 # 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)
+UPSTREAMREV := $(shell ./util/getrevision.sh --upstream || echo unknown)
+LOCALREV := $(shell ./util/getrevision.sh --local)
+TIMESTAMP := $(shell ./util/getrevision.sh --timestamp)
+SCMURL := $(shell ./util/getrevision.sh --url || echo unknown )
 
 RELEASE := 0.9.2
-VERSION := $(RELEASE)-r$(SVNVERSION)
+VERSION := $(RELEASE)-r$(UPSTREAMREV)
 RELEASENAME ?= $(VERSION)
 
-SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"'
+SCMDEF := -D'FLASHROM_VERSION="$(VERSION)"' -D'FLASHROM_SCMURL="$(SCMURL)"' \
+          -D'FLASHROM_LOCALREV="$(LOCALREV)"' -D'FLASHROM_TIMESTAMP="$(TIMESTAMP)"'
 
 # Always enable internal/onboard support for now.
 CONFIG_INTERNAL ?= yes
@@ -323,7 +327,7 @@  $(PROGRAM)$(EXEC_SUFFIX): $(OBJS)
 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.
@@ -433,9 +437,12 @@  install: $(PROGRAM)$(EXEC_SUFFIX)
 
 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.orig/flashrom.c
+++ flashrom-gitfriendly/flashrom.c
@@ -1377,6 +1377,12 @@  void print_sysinfo(void)
 void print_version(void)
 {
 	msg_ginfo("flashrom v%s", flashrom_version);
+	msg_ginfo(" from %s", FLASHROM_SCMURL);
+	if (!strcmp(FLASHROM_LOCALREV, ""))
+		msg_ginfo(", no local revision");
+	else
+		msg_ginfo(", local revision %s", FLASHROM_LOCALREV);
+	msg_ginfo(", timestamp %s, ", FLASHROM_TIMESTAMP);
 	print_sysinfo();
 }