~ chicken-core (chicken-5) 3177a4daa58d518e074a06de728dcf88fe8750a2
commit 3177a4daa58d518e074a06de728dcf88fe8750a2 Author: Jim Ursetto <zbigniewsz@gmail.com> AuthorDate: Fri Jul 1 18:15:25 2011 -0500 Commit: felix <felix@call-with-current-continuation.org> CommitDate: Sun Jul 17 23:35:41 2011 +0200 Add unit build-version with build branch, tag and ID variables Generate new files buildtag and buildbranch during the make process, as well as buildid (containing the git hash of HEAD, via identify-revision.sh). Make their contents available via ##sys variables in new Unit build-version, and pull this unit into Unit library. diff --git a/Makefile.mingw b/Makefile.mingw index c5c82828..b153b583 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -32,6 +32,7 @@ endif SEP = $(strip \) SRCDIR =.$(SEP) BRANCHNAME = +BUILD_ID = # platform configuration diff --git a/build-version.scm b/build-version.scm new file mode 100644 index 00000000..933dffab --- /dev/null +++ b/build-version.scm @@ -0,0 +1,45 @@ +;;;; build-version.scm +; +; Copyright (c) 2008-2011, The Chicken Team +; Copyright (c) 2000-2007, Felix L. Winkelmann +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following +; conditions are met: +; +; Redistributions of source code must retain the above copyright notice, this list of conditions and the following +; disclaimer. +; Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +; disclaimer in the documentation and/or other materials provided with the distribution. +; Neither the name of the author nor the names of its contributors may be used to endorse or promote +; products derived from this software without specific prior written permission. +; +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS +; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR +; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +; POSSIBILITY OF SUCH DAMAGE. + + +(declare + (unit build-version)) + +;; (read-version filename): Read line from FILENAME and return +;; as a string; return #f if non-existent file or blank line. +(define-syntax read-version + (lambda (x r c) + (let ((fn (cadr x))) + (and (file-exists? fn) + (let ((ver (with-input-from-file (cadr x) read-line))) + (if (string=? ver "") + #f + ver)))))) + +(define ##sys#build-version (read-version "buildversion")) +(define ##sys#build-tag (read-version "buildtag")) +(define ##sys#build-id (read-version "buildid")) +(define ##sys#build-branch (read-version "buildbranch")) diff --git a/defaults.make b/defaults.make index 95a069db..01f7c165 100644 --- a/defaults.make +++ b/defaults.make @@ -43,7 +43,7 @@ SEP ?= / SRCDIR ?= .$(SEP) DESTDIR ?= PREFIX ?= /usr/local -BRANCHNAME ?= $(shell sh identify-branch.sh $(SRCDIR)) +BRANCHNAME ?= $(shell sh $(SRCDIR)identify-branch.sh $(SRCDIR)) BINDIR = $(PREFIX)/bin LIBDIR = $(PREFIX)/lib @@ -237,6 +237,7 @@ UNAME_SYS ?= $(shell uname) COPY_COMMAND = cp endif BUILD_TAG ?= compiled $(BUILD_TIME) on $(HOSTNAME) ($(UNAME_SYS)) +BUILD_ID ?= $(shell sh $(SRCDIR)identify-revision.sh $(SRCDIR)) COPYMANY = diff --git a/distribution/manifest b/distribution/manifest index e81ead8a..0d48b71b 100644 --- a/distribution/manifest +++ b/distribution/manifest @@ -7,6 +7,7 @@ NEWS README config-arch.sh identify-branch.sh +identify-revision.sh banner.scm batch-driver.scm batch-driver.c @@ -95,6 +96,7 @@ srfi-4.scm stub.scm support.scm tcp.scm +build-version.scm tests/thread-list.scm tests/gobble.scm tests/test-optional.scm diff --git a/identify-revision.sh b/identify-revision.sh new file mode 100755 index 00000000..a7980ea3 --- /dev/null +++ b/identify-revision.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# +# identify-revision.sh - check for .git directory and obtain checked out revision +# +# usage: identify-revision.sh SOURCEDIR + +if test -d "$1/.git"; then + GIT_DIR="$1/.git" git rev-parse --short HEAD 2>/dev/null +fi diff --git a/library.scm b/library.scm index c08a43a1..e7a1db8c 100644 --- a/library.scm +++ b/library.scm @@ -27,6 +27,7 @@ (declare (unit library) + (uses build-version) (disable-interrupts) (hide ##sys#dynamic-unwind ##sys#find-symbol ##sys#grow-vector ##sys#default-parameter-vector diff --git a/rules.make b/rules.make index 8ad51102..bca0358f 100644 --- a/rules.make +++ b/rules.make @@ -38,7 +38,7 @@ SETUP_API_OBJECTS_1 = setup-api setup-download LIBCHICKEN_OBJECTS_1 = \ library eval data-structures ports files extras lolevel utils tcp srfi-1 srfi-4 srfi-13 \ srfi-14 srfi-18 srfi-69 $(POSIXFILE) irregex scheduler \ - profiler stub expand modules chicken-syntax chicken-ffi-syntax runtime + profiler stub expand modules chicken-syntax chicken-ffi-syntax runtime build-version LIBCHICKEN_SHARED_OBJECTS = $(LIBCHICKEN_OBJECTS_1:=$(O)) LIBCHICKEN_STATIC_OBJECTS = $(LIBCHICKEN_OBJECTS_1:=-static$(O)) @@ -461,6 +461,26 @@ ifdef WINDOWS_SHELL $(REMOVE_COMMAND) $(REMOVE_COMMAND_OPTIONS) "$(DESTDIR)$(IBINDIR)$(SEP)csibatch.bat" endif +# build versioning + +.PHONY: buildtag buildbranch buildid + +ifdef WINDOWS_SHELL +buildtag: + echo.$(BUILD_TAG)>buildtag +buildbranch: + echo.$(BRANCHNAME)>buildbranch +buildid: + echo.$(BUILD_ID)>buildid +else +buildtag: + echo "$(BUILD_TAG)" > buildtag +buildbranch: + echo "$(BRANCHNAME)" > buildbranch +buildid: + echo "$(BUILD_ID)" > buildid +endif + # bootstrapping c sources define declare-emitted-import-lib-dependency @@ -526,6 +546,8 @@ profiler.c: $(SRCDIR)profiler.scm $(SRCDIR)common-declarations.scm $(bootstrap-lib) stub.c: $(SRCDIR)stub.scm $(SRCDIR)common-declarations.scm $(bootstrap-lib) +build-version.c: $(SRCDIR)build-version.scm buildtag buildbranch buildid $(SRCDIR)buildversion + $(bootstrap-lib) define declare-bootstrap-import-lib $(1).import.c: $$(SRCDIR)$(1).import.scmTrap