From befcf159170f6dbb92a44afe88ec736450133105 Mon Sep 17 00:00:00 2001 From: Lawrence Teo Date: Wed, 26 Oct 2011 00:54:52 -0400 Subject: [PATCH] new release script and versioning scheme for scrotwm (adapted from xxxterm) ok marco --- Makefile | 4 ++ buildver.sh | 7 +++ release.sh | 151 +++++++++++++++++++++++++++++++++++++++++------------------ scrotwm.c | 21 +++++---- version.h | 32 +++++++++++++ 5 files changed, 160 insertions(+), 55 deletions(-) create mode 100644 buildver.sh create mode 100644 version.h diff --git a/Makefile b/Makefile index 42bccb5..ad27745 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,10 @@ CFLAGS+=-std=c89 -Wall -Wno-uninitialized -ggdb3 #CFLAGS+=-DSWM_DENY_CLOCK_FORMAT CPPFLAGS+= -I${X11BASE}/include LDADD+=-lutil -L${X11BASE}/lib -lX11 -lXrandr -lXtst +BUILDVERSION != sh "${.CURDIR}/buildver.sh" +.if !${BUILDVERSION} == "" +CPPFLAGS+= -DSCROTWM_BUILDSTR=\"$(BUILDVERSION)\" +.endif MANDIR= ${PREFIX}/man/man diff --git a/buildver.sh b/buildver.sh new file mode 100644 index 0000000..27dfd89 --- /dev/null +++ b/buildver.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +CURDIR=$(dirname $0) +if [ -d "$CURDIR/.git" ]; then + cd "$CURDIR" + git describe --tags | tr -d '\n' +fi diff --git a/release.sh b/release.sh index fc6ee92..3ac9b92 100644 --- a/release.sh +++ b/release.sh @@ -1,67 +1,126 @@ -#!/bin/ksh +#!/bin/sh # +# Prepares a release: +# - Bumps version according to specified level (major, minor, or patch) +# - Updates all necessary headers with new version +# - Commits the changes +# - Tags the release +# - Creates a release tarball -PREFIX=scrotwm- -DIRS="lib linux osx" -FILES="Makefile baraction.sh initscreen.sh screenshot.sh scrotwm.1 scrotwm_es.1 scrotwm_it.1 scrotwm_pt.1 scrotwm_ru.1 scrotwm.c scrotwm.conf linux/Makefile linux/linux.c linux/util.h linux/scrotwm.desktop lib/Makefile lib/shlib_version lib/swm_hack.c osx/Makefile osx/osx.h osx/osx.c" +PROJECT=scrotwm +PROJECT_UC=$(echo $PROJECT | tr '[:lower:]' '[:upper:]') +SCRIPT=$(basename $0) +HEADER=version.h -if [ -z "$1" ]; then - echo "usage: release.sh " +# verify params +if [ $# -lt 1 ]; then + echo "usage: $SCRIPT {major | minor | patch}" exit 1 fi -if [ -d "$PREFIX$1" ]; then - echo "$PREFIX$1 already exists" +report_err() +{ + echo "$SCRIPT: error: $1" 1>&2 exit 1 +} + + +cd "$(dirname $0)" + +# verify header exists +if [ ! -f "$HEADER" ]; then + report_err "$HEADER does not exist" fi -if [ -d "$PREFIX$1-port" ]; then - echo "$PREFIX$1 already exists" - exit 1 +# verify valid release type +RTYPE="$1" +if [ "$RTYPE" != "major" -a "$RTYPE" != "minor" -a "$RTYPE" != "patch" ]; then + report_err "release type must be major, minor, or patch" +fi + +# verify git is available +if ! type git >/dev/null 2>&1; then + report_err "unable to find 'git' in the system path" +fi + +# verify the git repository is on the master branch +BRANCH=$(git branch | grep '\*' | cut -c3-) +if [ "$BRANCH" != "master" ]; then + report_err "git repository must be on the master branch" fi -TARGET="$PREFIX$1" -mkdir $TARGET +# verify there are no uncommitted modifications prior to release modifications +NUM_MODIFIED=$(git diff 2>/dev/null | wc -l | sed 's/^[ \t]*//') +NUM_STAGED=$(git diff --cached 2>/dev/null | wc -l | sed 's/^[ \t]*//') +if [ "$NUM_MODIFIED" != "0" -o "$NUM_STAGED" != "0" ]; then + report_err "the working directory contains uncommitted modifications" +fi -for i in $DIRS; do - mkdir "$TARGET/$i" -done +# get version +PAT_PREFIX="(^#define[[:space:]]+${PROJECT_UC}" +PAT_SUFFIX='[[:space:]]+)[0-9]+$' +MAJOR=$(egrep "${PAT_PREFIX}_MAJOR${PAT_SUFFIX}" $HEADER | awk '{print $3}') +MINOR=$(egrep "${PAT_PREFIX}_MINOR${PAT_SUFFIX}" $HEADER | awk '{print $3}') +PATCH=$(egrep "${PAT_PREFIX}_PATCH${PAT_SUFFIX}" $HEADER | awk '{print $3}') +if [ -z "$MAJOR" -o -z "$MINOR" -o -z "$PATCH" ]; then + report_err "unable to get version from $HEADER" +fi -for i in $FILES; do - cp $i "$TARGET/$i" -done +# bump version according to level +if [ "$RTYPE" = "major" ]; then + MAJOR=$(expr $MAJOR + 1) + MINOR=0 + PATCH=0 +elif [ "$RTYPE" = "minor" ]; then + MINOR=$(expr $MINOR + 1) + PATCH=0 +elif [ "$RTYPE" = "patch" ]; then + PATCH=$(expr $PATCH + 1) +fi +PROJ_VER="$MAJOR.$MINOR.$PATCH" -tar zcf $TARGET.tgz $TARGET +# update header with new version +sed -E " + s/${PAT_PREFIX}_MAJOR${PAT_SUFFIX}/\1${MAJOR}/; + s/${PAT_PREFIX}_MINOR${PAT_SUFFIX}/\1${MINOR}/; + s/${PAT_PREFIX}_PATCH${PAT_SUFFIX}/\1${PATCH}/; +" <"$HEADER" >"${HEADER}.tmp" -# make port -sudo rm -rf ports -sudo cvs -d /cvs co ports/x11/scrotwm -PORT="$PREFIX$1-port" -mkdir $PORT +# apply changes +mv "${HEADER}.tmp" "$HEADER" -# Makefile -cat port/Makefile | sed "s/SCROTWMVERSION/$1/g" > $PORT/Makefile +# commit and tag +TAG="${PROJECT_UC}_${MAJOR}_${MINOR}_${PATCH}" +git commit -am "Prepare for release ${PROJ_VER}." || + report_err "unable to commit changes" +git tag -a "$TAG" -m "Release ${PROJ_VER}" || report_err "unable to create tag" -# distinfo -cksum -b -a md5 $TARGET.tgz > $PORT/distinfo -cksum -b -a rmd160 $TARGET.tgz >> $PORT/distinfo -cksum -b -a sha1 $TARGET.tgz >> $PORT/distinfo -cksum -b -a sha256 $TARGET.tgz >> $PORT/distinfo -wc -c $TARGET.tgz 2>/dev/null | awk '{print "SIZE (" $2 ") = " $1}' >> $PORT/distinfo +# create temp working space and copy repo over +TD=$(mktemp -d /tmp/release.XXXXXXXXXX) +if [ ! -d "$TD" ]; then + report_err "unable to create temp directory" +fi +RELEASE_DIR="$PROJECT-$PROJ_VER" +RELEASE_TAR="$PROJECT-$PROJ_VER.tgz" +git clone . "$TD/$RELEASE_DIR" || + report_err "unable to copy to $TD/$RELEASE_DIR" -# pkg -mkdir $PORT/pkg -cp port/pkg/DESCR $PORT/pkg/ -cp port/pkg/PFRAG.shared $PORT/pkg/ -cp port/pkg/PLIST $PORT/pkg/ +# cleanup repository files +cd "$TD" +if [ -d "$RELEASE_DIR" -a -d "$RELEASE_DIR/.git" ]; then + rm -rf "$RELEASE_DIR/.git" +fi +if [ -d "$RELEASE_DIR" -a -f "$RELEASE_DIR/.gitignore" ]; then + rm -f "$RELEASE_DIR/.gitignore" +fi -# patches -mkdir $PORT/patches -cp port/patches/patch-scrotwm_c $PORT/patches/ -cp port/patches/patch-scrotwm_conf $PORT/patches/ +# make snap +tar -zcf "$RELEASE_TAR" "$RELEASE_DIR" || + report_err "unable to create $RELEASE_TAR" -# make diff -diff -ruNp -x CVS ports/x11/scrotwm/ $PORT > $TARGET.diff -# kill ports dir or cvs will be angry -sudo rm -rf ports +echo "Release tarball:" +echo " $TD/$RELEASE_TAR" +echo "" +echo "If everything is accurate, use the following command to push the changes:" +echo " git push --tags origin master" diff --git a/scrotwm.c b/scrotwm.c index 47e7319..d15a6e6 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -51,11 +51,6 @@ * DEALINGS IN THE SOFTWARE. */ -static const char *cvstag = - "$scrotwm$"; - -#define SWM_VERSION "0.9.34" - #include #include #include @@ -92,6 +87,14 @@ static const char *cvstag = #include #endif +#include "version.h" + +#ifdef SCROTWM_BUILDSTR +static const char *buildstr = SCROTWM_BUILDSTR; +#else +static const char *buildstr = SCROTWM_VERSION; +#endif + #if RANDR_MAJOR < 1 # error XRandR versions less than 1.0 are not supported #endif @@ -1540,8 +1543,8 @@ version(struct swm_region *r, union arg *args) { bar_version = !bar_version; if (bar_version) - snprintf(bar_vertext, sizeof bar_vertext, "Version: %s CVS: %s", - SWM_VERSION, cvstag); + snprintf(bar_vertext, sizeof bar_vertext, "Version: %s Build: %s", + SCROTWM_VERSION, buildstr); else strlcpy(bar_vertext, "", sizeof bar_vertext); bar_update(); @@ -6321,8 +6324,8 @@ main(int argc, char *argv[]) struct sigaction sact; start_argv = argv; - fprintf(stderr, "Welcome to scrotwm V%s cvs tag: %s\n", - SWM_VERSION, cvstag); + fprintf(stderr, "Welcome to scrotwm V%s Build: %s\n", + SCROTWM_VERSION, buildstr); if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) warnx("no locale support"); diff --git a/version.h b/version.h new file mode 100644 index 0000000..d687fc9 --- /dev/null +++ b/version.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2011 Conformal Systems LLC + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + + +#ifndef SCROTWM_VERSION_H +#define SCROTWM_VERSION_H + +#define SCROTWM_STR(x) #x +#define SCROTWM_STRINGIZE(x) SCROTWM_STR(x) + +#define SCROTWM_MAJOR 0 +#define SCROTWM_MINOR 9 +#define SCROTWM_PATCH 34 +#define SCROTWM_VERSION SCROTWM_STRINGIZE(SCROTWM_MAJOR) "." \ + SCROTWM_STRINGIZE(SCROTWM_MINOR) "." \ + SCROTWM_STRINGIZE(SCROTWM_PATCH) + +#endif /* SCROTWM_VERSION_H */ + -- 1.7.10.4