From bad05cd2b641877829afea2756e26ef445baeba3 Mon Sep 17 00:00:00 2001
From: Eelco Visser <visser@acm.org>
Date: Tue, 30 Dec 2003 21:14:48 +0000
Subject: [PATCH] A first attempt at generic release management. The goal is to
 fully automate the building of distributions and their release for
 distribution through a web-site, ftp directory, etc. Inspired by nix-dist,
 but more generic in order to deal with StrategoXT and related packages.

The assumptions are the following:

  - package source is a subversion repository
  - the package is under autotool configuration
    (at least it has a configure.in with an AC_INIT)
  - standard autotools build interface:
    - bootstrap; configure; make install;
      make check; make dist
  - optionally the release status can be indicated by
    a status="..." definition in configure.in

Creation of distributions is a two-step process:

  urls-to-nix.sh  # nix expressions for most recent commits
  build+upload.sh # instantiate the expressions

svn-to-nix.sh

   Generates nix expression for head revision of the
   package; revision number, package name, and version
   are obtained from the source and do not have to
   be declared.

urls-to-nix.sh

   Contains a list of URLs to which svn-to-nix.sh is applied.

build+upload.sh

   Builds the packages and creates distributions in a www
   directory. Including the log of the build process (buildfarm)
   and files such as NEWS and README (for release management).
   (upload part of the script is currently turned off)

do-it.nix

   Top nix expression; collects pointers to required packages
   (e.g., stdenv, autotools, aterms, ...) and binds them
   to the parameters of the source-dist.nix packages.

package-source-dist.nix

   Generic Nix expression for a package parameterized with
   version info from svn and dependency info from do-it.nix.

package-dist.nix

   Generated; just imports

package-version-rev.nix

   Generated; instantiates package-source-dist.nix with version,
   name, packagename, rev.

build-from-svn.sh

   Generic build script; obtains configuration flags from
   with... and enable... attributes of the Nix expression.
   Creates logs of the various parts of the build process.
   Creates distribution

Generalizations:

- Currently some information about a package resides in
  this directory, e.g., the generic Nix expression for
  a package, and the composition of the overall do-it.nix
  This information should also be obtained from the source
  tree.

- Upload facility lacking.




svn path=/nixpkgs/trunk/; revision=605
---
 strategoxt-dist/build+upload.sh               | 25 ++----
 strategoxt-dist/build-from-svn.sh             | 85 +++++++++++++++++++
 strategoxt-dist/do-it.nix                     | 34 ++++----
 strategoxt-dist/nix-source-dist.nix           | 38 ---------
 strategoxt-dist/strategoxt-source-dist.nix    | 22 +++++
 ...urce-dist.sh => strategoxt-source-dist.sh} |  0
 ...st-build.nix => strategoxt-test-build.nix} |  4 +-
 ...test-build.sh => strategoxt-test-build.sh} |  0
 strategoxt-dist/svn-to-nix.sh                 | 71 ++++++++++++++++
 strategoxt-dist/tiger-source-dist.nix         | 27 ++++++
 strategoxt-dist/urls-to-nix.sh                | 10 +++
 11 files changed, 243 insertions(+), 73 deletions(-)
 create mode 100755 strategoxt-dist/build-from-svn.sh
 delete mode 100644 strategoxt-dist/nix-source-dist.nix
 create mode 100644 strategoxt-dist/strategoxt-source-dist.nix
 rename strategoxt-dist/{nix-source-dist.sh => strategoxt-source-dist.sh} (100%)
 mode change 100755 => 100644
 rename strategoxt-dist/{nix-test-build.nix => strategoxt-test-build.nix} (65%)
 rename strategoxt-dist/{nix-test-build.sh => strategoxt-test-build.sh} (100%)
 create mode 100755 strategoxt-dist/svn-to-nix.sh
 create mode 100644 strategoxt-dist/tiger-source-dist.nix
 create mode 100755 strategoxt-dist/urls-to-nix.sh

diff --git a/strategoxt-dist/build+upload.sh b/strategoxt-dist/build+upload.sh
index 22592ca570ae..8cf4d8b41273 100755
--- a/strategoxt-dist/build+upload.sh
+++ b/strategoxt-dist/build+upload.sh
@@ -1,29 +1,22 @@
-#! /bin/sh
+#! /bin/sh -v
 
-url="https://svn.cs.uu.nl:12443/repos/trace/nix/trunk/"
-
-if ! rev=$(curl --silent -k https://svn.cs.uu.nl:12443/repos/trace/nix/trunk/ \
- | grep '<h2>Revision' \
- | sed 's/.*Revision \(.*\):.*/\1/'); \
- then exit 1; fi
+# Build the distribution
 
 echo "building revision $rev of $url"
 
-echo $rev > head-revision.nix
-
-if ! storeexprs=($(nix-instantiate -vvv do-it.nix)); then exit 1; fi
+if ! storeexprs=($(nix-instantiate -vvvv do-it.nix)); then exit 1; fi
 
 srcexpr=${storeexprs[0]}
-testexpr=${storeexprs[1]}
+#testexpr=${storeexprs[1]}
 
 if ! nix-store -vvvv -r "$srcexpr" > /dev/null; then exit 1; fi
 
 if ! outpath=$(nix-store -qn "$srcexpr"); then exit 1; fi
 
-uploader="http://losser.st-lab.cs.uu.nl/~eelco/cgi-bin/upload.pl/"
+#uploader="http://losser.st-lab.cs.uu.nl/~eelco/cgi-bin/upload.pl/"
 
-curl --silent -T "$outpath/manual.html" "$uploader" || exit 1
-curl --silent -T "$outpath/style.css" "$uploader" || exit 1
-curl --silent -T "$outpath"/nix-*.tar.bz2 "$uploader" || exit 1
+#curl --silent -T "$outpath/manual.html" "$uploader" || exit 1
+#curl --silent -T "$outpath/style.css" "$uploader" || exit 1
+#curl --silent -T "$outpath"/nix-*.tar.bz2 "$uploader" || exit 1
 
-if ! nix-store -vvvv -r "$testexpr" > /dev/null; then exit 1; fi
+#if ! nix-store -vvvv -r "$testexpr" > /dev/null; then exit 1; fi
diff --git a/strategoxt-dist/build-from-svn.sh b/strategoxt-dist/build-from-svn.sh
new file mode 100755
index 000000000000..8d3c04649967
--- /dev/null
+++ b/strategoxt-dist/build-from-svn.sh
@@ -0,0 +1,85 @@
+#! /bin/sh -v
+
+buildinputs="$make $automake $autoconf $libtool $which $withsdf"
+. $stdenv/setup || exit 1
+
+echo "pwd = `pwd`"
+echo "PATH = $PATH"
+
+# configuration flags
+
+config_flags=""
+
+for pack in `env | grep with | sed "s/^with\([A-Za-z]*\)=.*/\1/"`
+do
+  config_flags="${config_flags} --with-${pack}=$(printenv with${pack})"
+done
+
+for feat in `env | grep enable | sed "s/^enable\([A-Za-z]*\)=.*/\1/"`
+do
+  config_flags="${config_flags} --enable-${feat}=$(printenv enable${feat})"
+done
+
+echo "config_flags : $config_flags"
+
+# keep a log
+
+distdir=$out/www/strategoxt/$version-$rev
+logdir=$distdir/log
+mkdir -p $distdir || exit 1
+mkdir -p $logdir || exit 1
+
+# get the source
+
+cp -r $src src || exit 1
+chmod -R +w src
+cd src || exit 1
+
+echo ${rev} > svn-revision
+
+# build it
+
+GO="true"
+
+./bootstrap                               2>&1 | tee $logdir/bootstrap.txt
+./configure --prefix=$out ${config_flags} 2>&1 | tee $logdir/configure.txt
+
+if ! make install                         2>&1 | tee $logdir/install.txt 
+then 
+  GO="false"
+fi
+
+if test $GO = "true"
+then
+  if ! make check                         2>&1 | tee $logdir/check.txt
+  then 
+    GO="false"
+  fi
+fi
+
+# make a distribution
+
+if test $GO = "true"
+then
+  if make dist                            2>&1 | tee $logdir/dist.txt
+  then
+    if test "x${status}" = "xrelease"
+    then
+      cp ${packagename}-${version}.tar.gz $distdir || exit 1
+    else
+      tar zxf ${packagename}-${version}.tar.gz
+      mv ${packagename}-${version} ${name}
+      tar zcf ${name}.tar.gz ${name}
+      cp ${name}.tar.gz $distdir || exit 1
+    fi
+  fi
+fi
+
+# distribute documentation data
+
+if test -f news/NEWS-$version
+then
+  cp news/NEWS-$version $distdir || exit 1
+fi
+
+cp NEWS ChangeLog AUTHORS README COPYING $distdir || exit 1
diff --git a/strategoxt-dist/do-it.nix b/strategoxt-dist/do-it.nix
index 81f04169bc93..5c6e6105f0b0 100644
--- a/strategoxt-dist/do-it.nix
+++ b/strategoxt-dist/do-it.nix
@@ -1,26 +1,26 @@
 let {
   system = "i686-linux";
-  pkgs = (import ../pkgs/system/all-packages.nix) {system = system;};
+  pkgs   = (import ../pkgs/system/all-packages.nix) {system = system;};
   stdenv = pkgs.stdenv_;
 
-  sourcedist = (import ./nix-source-dist.nix) {
-    stdenv = stdenv;
-    autoconf = pkgs.autoconf;
-    automake = pkgs.automake;
-    libxml2 = pkgs.libxml2;
-    libxslt = pkgs.libxslt;
-    docbook_dtd = pkgs.docbook_xml_dtd;
-    docbook_xslt = pkgs.docbook_xml_xslt;
-    fetchurl = pkgs.fetchurl;
-    fetchsvn = pkgs.fetchsvn;
-    rev = import ./head-revision.nix;
+  strategoxtdist = (import ./strategoxt-dist.nix) {
+    stdenv    = stdenv;
+    fetchsvn  = pkgs.fetchsvn;
+    autotools = pkgs.autotools;
+    which     = pkgs.which;
+    aterm     = pkgs.aterm;
+    sdf       = pkgs.sdf2;
   };
 
-  testbuild = (import ./nix-test-build.nix) {
-    stdenv = stdenv;
-    getopt = pkgs.getopt;
-    src = sourcedist;
+  tigerdist = (import ./tiger-dist.nix) {
+    stdenv     = stdenv;
+    fetchsvn   = pkgs.fetchsvn;
+    autotools  = pkgs.autotools;
+    which      = pkgs.which;
+    aterm      = pkgs.aterm;
+    sdf        = pkgs.sdf2;
+    strategoxt = strategoxtdist;
   };
 
-  body = [sourcedist testbuild];
+  body = [strategoxtdist tigerdist];
 }
diff --git a/strategoxt-dist/nix-source-dist.nix b/strategoxt-dist/nix-source-dist.nix
deleted file mode 100644
index b0747ea9f96b..000000000000
--- a/strategoxt-dist/nix-source-dist.nix
+++ /dev/null
@@ -1,38 +0,0 @@
-{ stdenv, autoconf, automake, libxml2, libxslt
-, docbook_dtd, docbook_xslt
-, fetchurl, fetchsvn, rev
-}:
-
-derivation {
-  name = "nix-source-dist";
-  system = stdenv.system;
-
-  builder = ./nix-source-dist.sh;
-  src = fetchsvn {
-    url = "https://svn.cs.uu.nl:12443/repos/trace/nix/trunk/";
-    rev = rev;
-  };
-
-  bdbSrc = fetchurl {
-    url = "http://www.sleepycat.com/update/snapshot/db-4.1.25.tar.gz";
-    md5 = "df71961002b552c0e72c6e4e358f27e1";
-  };
-
-  atermSrc = fetchurl {
-    url = http://www.cwi.nl/projects/MetaEnv/aterm/aterm-2.0.5.tar.gz;
-    md5 = "68aefb0c10b2ab876b8d3c0b2d0cdb1b";
-  };
-
-  sdfSrc = fetchurl {
-    url = ftp://ftp.stratego-language.org/pub/stratego/sdf2/sdf2-bundle-1.6.tar.gz;
-    md5 = "283be0b4c7c9575c1b5cc735316e6192";
-  };
-
-  stdenv = stdenv;
-  autoconf = autoconf;
-  automake = automake;
-  libxml2 = libxml2;
-  libxslt = libxslt;
-  docbook_dtd = docbook_dtd;
-  docbook_xslt = docbook_xslt;
-}
diff --git a/strategoxt-dist/strategoxt-source-dist.nix b/strategoxt-dist/strategoxt-source-dist.nix
new file mode 100644
index 000000000000..a274bc0d128c
--- /dev/null
+++ b/strategoxt-dist/strategoxt-source-dist.nix
@@ -0,0 +1,22 @@
+{name, packagename, version, rev, url} :
+{stdenv, fetchsvn, autotools, which, aterm, sdf}:
+derivation {
+  name        = name;
+  packagename = packagename;
+  rev         = rev;
+  version     = version;
+
+  system      = stdenv.system;
+  builder     = ./build-from-svn.sh;
+  src         = fetchsvn {url = url; rev = rev;};
+  stdenv      = stdenv;
+
+  make        = autotools.make;
+  automake    = autotools.automake;
+  autoconf    = autotools.autoconf;
+  libtool     = autotools.libtool;
+  which       = which;
+
+  withaterm   = aterm;
+  withsdf     = sdf;
+}
diff --git a/strategoxt-dist/nix-source-dist.sh b/strategoxt-dist/strategoxt-source-dist.sh
old mode 100755
new mode 100644
similarity index 100%
rename from strategoxt-dist/nix-source-dist.sh
rename to strategoxt-dist/strategoxt-source-dist.sh
diff --git a/strategoxt-dist/nix-test-build.nix b/strategoxt-dist/strategoxt-test-build.nix
similarity index 65%
rename from strategoxt-dist/nix-test-build.nix
rename to strategoxt-dist/strategoxt-test-build.nix
index 6fa7f271607a..26c82eba1f42 100644
--- a/strategoxt-dist/nix-test-build.nix
+++ b/strategoxt-dist/strategoxt-test-build.nix
@@ -1,10 +1,10 @@
 {stdenv, getopt, src}:
 
 derivation {
-  name = "nix-test-build";
+  name = "strategoxt-test-build";
   system = stdenv.system;
 
-  builder = ./nix-test-build.sh;
+  builder = ./strategoxt-test-build.sh;
   src = src;
 
   stdenv = stdenv;
diff --git a/strategoxt-dist/nix-test-build.sh b/strategoxt-dist/strategoxt-test-build.sh
similarity index 100%
rename from strategoxt-dist/nix-test-build.sh
rename to strategoxt-dist/strategoxt-test-build.sh
diff --git a/strategoxt-dist/svn-to-nix.sh b/strategoxt-dist/svn-to-nix.sh
new file mode 100755
index 000000000000..29ee6054074e
--- /dev/null
+++ b/strategoxt-dist/svn-to-nix.sh
@@ -0,0 +1,71 @@
+#! /bin/sh -v 
+
+# Generate a Nix expression for the head revision of a directory in
+# a subversion repository. The directory is assumed to contain
+# a package with a configure.in file.
+#
+# Usage :
+#
+#   svn-to-nix.sh url
+#
+# where url points to a subversion repository
+
+# Obtain version information from repository
+
+# Revision
+
+url=$1
+
+rev=`svn log ${url} \
+     | head -n 2 \
+     | grep rev \
+     | sed "s/rev \([0-9]*\):.*$/\1/"`
+
+# The configure.in file
+
+configure="/tmp/$$configure.in"
+svn cat -r ${rev} ${url}/configure.in > $configure
+
+# Version number from AC_INIT 
+
+version=`grep AC_INIT $configure \
+         | awk -F , -- "{print \\$2}" \
+         | sed "s/[[]//" \
+         | sed "s/[]]//"`
+
+# Package name from AC_INIT
+
+packagename=`grep AC_INIT $configure \
+             | awk -F , -- "{print \\$1}" \
+             | sed "s/AC_INIT([[]//" \
+             | sed "s/[]]//"`
+
+# Status 
+
+status=`grep status $configure \
+        | sed "s/^status=\(.*\)/\1/"`
+
+# The name of the distribution
+
+name="${packagename}-${version}-${rev}"
+
+rm $configure
+
+###########################
+
+# Generate Nix expressions
+
+cat > ${packagename}-dist.nix <<EOF
+import ./${name}.nix
+EOF
+
+cat > ${name}.nix <<EOF
+(import ./${packagename}-source-dist.nix) {
+  name        = "${name}";
+  packagename = "${packagename}";
+  version     = "${version}";
+  rev         = "${rev}"; 
+  url         = "${url}";
+}
+EOF
+
diff --git a/strategoxt-dist/tiger-source-dist.nix b/strategoxt-dist/tiger-source-dist.nix
new file mode 100644
index 000000000000..94b79652fa58
--- /dev/null
+++ b/strategoxt-dist/tiger-source-dist.nix
@@ -0,0 +1,27 @@
+{name, packagename, version, rev, url} :
+{stdenv, fetchsvn, autotools, which, aterm, sdf, strategoxt}:
+derivation {
+  name           = name;
+  packagename    = packagename;
+  rev            = rev;
+  version        = version;
+
+  system         = stdenv.system;
+  builder        = ./build-from-svn.sh;
+  src            = fetchsvn {url = url; rev = rev; };
+  stdenv         = stdenv;
+
+  make           = autotools.make;
+  automake       = autotools.automake;
+  autoconf       = autotools.autoconf;
+  libtool        = autotools.libtool;
+  which          = which;
+
+  withaterm      = aterm;
+  withsdf        = sdf;
+  withstrategoxt = strategoxt;
+ 
+  enabletiger    = "yes";
+  enableir       = "yes";
+  enableasm      = "yes";
+}
diff --git a/strategoxt-dist/urls-to-nix.sh b/strategoxt-dist/urls-to-nix.sh
new file mode 100755
index 000000000000..ed0d0a386090
--- /dev/null
+++ b/strategoxt-dist/urls-to-nix.sh
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+urls="https://svn.cs.uu.nl:12443/repos/StrategoXT/trunk/StrategoXT \
+      https://svn.cs.uu.nl:12443/repos/StrategoXT/trunk/tiger"
+
+for url in ${urls}
+do
+   echo ${url}
+   ./svn-to-nix.sh ${url}
+done
\ No newline at end of file