bin/mdw-build: Abolish (direct) use of `mdw-conf'.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 10 Feb 2016 02:24:32 +0000 (02:24 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 10 Feb 2016 02:25:23 +0000 (02:25 +0000)
Values are now configured from the command line or the configuration
file.  Since the configuration file is a shell fragment, it can invoke
`mdw-conf' itself for compatibility, and, indeed, I now have such a
configuration file.  The default `mdw.conf' file now has the necessary
extra keys in it.

This involves a little new machinery in `mdw-build' itself.  Some new
flags are introduced, to control whether the outputs should be
signed (and if so, which key should be used); and whether a Debian
upload should be performed (and if so, which target to use).
Correspondingly, the existing `upload' option has grown a configurable
remote path to control where the files should be written.

bin/mdw-build
dot/mdw-build.conf [new file with mode: 0644]
mdw.conf
setup

index 650f0c1..572aa75 100755 (executable)
@@ -58,8 +58,10 @@ set -e
 
 unset checkout checkoutrev
 unset setup setupcmd
+unset sign signkey
+unset upload uploadpath
 unset dput dputtarget
-unset build distcheck debian upload clean vpath native
+unset build distcheck debian clean vpath native
 for i in \
   "/etc/mdw-build.conf" \
   "${XDG_CONFIG_HOME-$HOME/.config}/mdw-build.conf" \
@@ -67,15 +69,22 @@ for i in \
 do
   if [ -f "$i" ]; then . "$i"; fi
 done
+default_depends () {
+  var=$1 want=$2
+  eval "p=\${$var+t} q=\${$want+t}"
+  case $p,$q in t,*) ;; *,t) eval "$var=yes" ;; *) eval "$var=no" ;; esac
+}
 : ${checkout=yes} ${checkoutrev=HEAD}
 : ${build=test}
 : ${setup=yes} ${setupcmd=mdw-setup}
 : ${distcheck=yes}
 : ${debian=yes}
-: ${upload=yes}
 : ${clean=yes}
 : ${vpath=yes}
 : ${native=yes}
+default_depends sign signkey
+default_depends upload uploadpath
+default_depends dput dputtarget
 : ${DEB_BUILD_OPTIONS=parallel=4}; export DEB_BUILD_OPTIONS
 
 ###--------------------------------------------------------------------------
@@ -94,9 +103,11 @@ Build options:
   [no]setup[=RUNE]
   [no]distcheck
   [no]debian
-  [no]upload
+  [no]upload[=SERVER:PATH]
+  [no]dput[=TARGET]
   [no]clean
   [no]vpath
+  [no]sign[=KEYID]
   [no]native
 EOF
 }
@@ -113,6 +124,14 @@ done
 shift $((OPTIND - 1))
 
 ## Parse the build options.
+maybe_set () {
+  var=$1 want=$2
+  eval "p=\${$want+t}\${$want-nil}"
+  case $p in
+    t) eval $var=yes ;;
+    nil) echo >&2 "$prog: $want not set"; exit 1 ;;
+  esac
+}
 for opt; do
   case "$opt" in
     checkout)  checkout=yes checkoutrev=HEAD ;;
@@ -121,12 +140,18 @@ for opt; do
     norelease) build=test ;;
     setup)     setup=yes setupcmd=mdw-setup ;;
     setup=*)   setup=yes setupcmd=${opt#*=} ;;
-
-    distcheck | debian | upload | clean | vpath | native)
+    upload)    maybe_set upload uploadpath ;;
+    upload=*)  upload=yes uploadpath=${opt#*=} ;;
+    sign)      maybe_set sign signkey ;;
+    sign=*)    sign=yes signkey=${opt#*=} ;;
+    dput)      maybe_set dput dputtarget ;;
+    dput=*)    dput=yes dputtarget=${opt#*=} ;;
+
+    distcheck | debian | clean | vpath | native)
       eval "$opt=yes"
       ;;
     nocheckout | nosetup | nodistcheck | nodebian | \
-    noupload | noclean | novpath | nonative)
+    noupload | nodput | noclean | novpath | nonative | nosign)
       eval "${opt#no}=no"
       ;;
     *)
@@ -349,10 +374,9 @@ case $native in
 esac
 
 run mv $buildpath/$distdir.tar.gz .
-case $build in
-  release)
-    run gpg -u$(mdw-conf releasekey) -ab -o$distdir.tar.gz.gpg \
-      $distdir.tar.gz
+case $build,$sign in
+  release,yes)
+    run gpg -u$signkey -ab -o$distdir.tar.gz.gpg $distdir.tar.gz
     ;;
 esac
 
@@ -376,24 +400,21 @@ EOF
        mv debian/changelog.new debian/changelog
        ;;
     esac
-    run dpkg-buildpackage -k$(mdw-conf releasekey)
+    case $build,$sign in
+      release,yes) run dpkg-buildpackage -k$signkey ;;
+      no,*) run dpkg-buildpackage -us -uc ;;
+    esac
     ;;
 esac
 
 ## Maybe upload Debian packages.
 cd $releasepath
 case "$upload,$build" in
-  yes,test)
-    info "Test build: not uploading."
-    ;;
-  yes,release)
-    run rsync $distdir.tar.gz $distdir.tar.gz.gpg \
-      $(mdw-conf upload-target ftp.distorted.org.uk:~ftp/pub/mdw/)
-    case "$debian" in
-      yes)
-       run dput -f $(mdw-conf dput-target distorted) *.changes
-       ;;
-    esac
+  yes,test) info "Test build: not uploading." ;;
+  yes,release) run rsync $distdir.tar.gz $distdir.tar.gz.gpg $uploadpath ;;
+esac
+case "$debian,$upload,$dput,$build" in
+  yes,yes,yes,release) run dput -f $dputtarget *.changes ;;
 esac
 
 ## Tidy up.
diff --git a/dot/mdw-build.conf b/dot/mdw-build.conf
new file mode 100644 (file)
index 0000000..9c3dd64
--- /dev/null
@@ -0,0 +1,19 @@
+### -*-sh-*-
+
+set_from_mdw_conf () {
+  var=$1 key=$2; shift 2
+  case $# in 0) defaultp=nil ;; *) defaultp=t default=$1; shift ;; esac
+  if value=$(mdw-conf $key 2>/dev/null); then
+    eval "$var=\$value"
+  else
+    case $defaultp in t) eval "$var=\$default" ;; esac
+  fi
+}
+
+setup=yes setupcmd=mdw-setup
+
+set_from_mdw_conf uploadpath upload-target
+set_from_mdw_conf dputtarget dput-target
+set_from_mdw_conf signkey releasekey
+
+DEB_BUILD_OPTIONS=parallel=4
index 58f868a..439b83c 100644 (file)
--- a/mdw.conf
+++ b/mdw.conf
@@ -12,3 +12,5 @@ hyperspec-url = https://www.distorted.org.uk/doc/hyperspec/
 console-ctype = en_GB.utf8
 x-ctype = en_GB.utf8
 releasekey = E359CA55
+upload-target = ftp.distorted.org.uk:~ftp/pub/mdw/
+dput-target = distorted
diff --git a/setup b/setup
index 004b9fd..514a4cb 100755 (executable)
--- a/setup
+++ b/setup
@@ -150,6 +150,7 @@ dotfiles="
     lisp-init.lisp:.clisprc.lisp
     lisp-init.lisp:.eclrc
   swank.lisp
+  mdw-build.conf:.config/mdw-build.conf
   w3m-config:.w3m/config elinks.conf:.elinks/elinks.conf
   dircolors colordiffrc screenrc cvsrc indent.pro"
 [ "$xstuff" ] && dotfiles="$dotfiles