summary refs log tree commit diff
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2021-04-18 14:38:06 +0200
committersternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2021-04-18 14:38:06 +0200
commit8aad18bea5a2f528f301a4521539a24f4f4932c2 (patch)
treeeb5f5cfab772e30d0a240599773859c7d6a6d5fa
parenteb7494636928a7cacf26ef1ac4bfb20eb738ef01 (diff)
chore(warteraum): port build system to GNU make
make is what people already use and it integrates better with nix, so
lets just use it as well. I haven't yet figured out how to do cleanly
implement a build system with redo without a thousand annoying little
shell scripts.

The downside of this is that GNU make is sometimes too lazy when
incrementally building and doesn't rebuild stuff when it really should.
-rw-r--r--.gitignore13
-rw-r--r--default.nix15
-rw-r--r--nix/warteraum.nix26
-rw-r--r--warteraum/GNUmakefile61
-rw-r--r--warteraum/all.do1
-rw-r--r--warteraum/build_config24
-rw-r--r--warteraum/default.o.do29
-rw-r--r--warteraum/hashtoken.do8
-rw-r--r--warteraum/test/all.do1
-rw-r--r--warteraum/test/default.exe.do25
-rwxr-xr-xwarteraum/test/integration (renamed from warteraum/test/run)33
-rw-r--r--warteraum/warteraum.do7
12 files changed, 77 insertions, 166 deletions
diff --git a/.gitignore b/.gitignore
index e65597d..606083f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,22 +2,11 @@
 
 *.o
 vgcore.*
-/warteraum/all
-/warteraum/test/all
 /warteraum/warteraum
 /warteraum/hashtoken
-/warteraum/test/*.exe
+/warteraum/test/*.test
 /warteraum/test/valgrind-log.txt
 
-# redo-sh
-.redo
-*.tmp2
-# redo-c
-.dep.*
-.depend.*
-.target.*
-.lock.*
-
 /bahnhofshalle/node_modules
 /bahnhofshalle/.cache
 /bahnhofshalle/yarn-error.log
diff --git a/default.nix b/default.nix
index b8d63d0..201b9ec 100644
--- a/default.nix
+++ b/default.nix
@@ -20,23 +20,14 @@ let
 in
 
 rec {
-  warteraum-static = (pkgs.pkgsStatic.callPackage ./nix/warteraum.nix {
-    # todo clang?
-    redo = pkgs.pkgsStatic.redo-c;
+  warteraum-static = pkgs.pkgsStatic.callPackage ./nix/warteraum.nix {
+    # TODO(sterni) clang
     inherit scryptSalt apiTokens rootSrc sourceName;
     inherit (python3.pkgs) pytest pytest-randomly requests flipdot-gschichtler;
-  }).overrideAttrs (old: {
-    # musl, static linking
-    postPatch = ''
-      cat >> ./build_config << EOF
-      CFLAGS="\$CFLAGS -static"
-      EOF
-    '';
-  });
+  };
 
   warteraum = pkgs.callPackage ./nix/warteraum.nix {
     stdenv = pkgs.clangStdenv;
-    redo = pkgs.redo-c;
     inherit scryptSalt apiTokens rootSrc sourceName;
     inherit (python3.pkgs) pytest pytest-randomly requests flipdot-gschichtler;
   };
diff --git a/nix/warteraum.nix b/nix/warteraum.nix
index 992f67d..9c175f1 100644
--- a/nix/warteraum.nix
+++ b/nix/warteraum.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, redo, scrypt
+{ stdenv, lib, scrypt
 , jq, requests, pytest, pytest-randomly, flipdot-gschichtler, valgrind
 , scryptSalt ? null, apiTokens ? null
 , rootSrc, sourceName
@@ -26,7 +26,6 @@ let
   '';
 
   tokensReplace = lib.optionalString (apiTokens != null) ''
-    redo hashtoken
     sed -i '/^  {/d' tokens.h
     sed -i '/^};/d' tokens.h
     ${lib.concatMapStringsSep "\n"
@@ -44,35 +43,28 @@ stdenv.mkDerivation rec {
 
   src = rootSrc;
 
-  # make whole source tree writeable for redo
-  postUnpack = ''
-    chmod -R u+w "$sourceRoot/.."
-  '';
+  makeFlags = [
+    "PREFIX=${placeholder "out"}"
+  ];
+
+  #postUnpack = ''
+  #  chmod -R u+w "$sourceRoot/.."
+  #'';
 
   patchPhase = ''
     runHook prePatch
 
-    patchShebangs test/run
+    patchShebangs test/integration
     ${saltReplace}
     ${tokensReplace}
 
     runHook postPatch
   '';
 
-  buildPhase = "redo";
-
   doCheck = true;
-  checkPhase = "./test/run";
   checkInputs = [
     jq valgrind pytest pytest-randomly requests flipdot-gschichtler
   ];
 
-  installPhase = ''
-    install -Dm755 warteraum -t $out/bin
-    install -Dm755 hashtoken -t $out/bin
-  '';
-
-  nativeBuildInputs = [ redo ];
-
   buildInputs = [ scrypt ];
 }
diff --git a/warteraum/GNUmakefile b/warteraum/GNUmakefile
new file mode 100644
index 0000000..39842e7
--- /dev/null
+++ b/warteraum/GNUmakefile
@@ -0,0 +1,61 @@
+CC ?= clang
+
+PREFIX ?= ./out
+BINDIR ?= $(PREFIX)/bin
+
+# baseline settings
+CFLAGS += -W -Wall -Wextra -pedantic -std=c99
+CFLAGS += -D_DEFAULT_SOURCE # make httpserver.h work with NixOS glibc
+
+# ignore some warnings
+CFLAGS += -Wno-gnu-empty-initializer  # httpserver.h
+
+LDFLAGS = -lscrypt-kdf
+
+HTTPSERVER = ../third_party/httpserver.h/httpserver.h
+
+TEST_BINS = test/emitjson.test test/queue.test test/form.test test/routing.test
+
+.PHONY: install clean check
+
+all: warteraum hashtoken
+
+warteraum: emitjson.o queue.o routing.o form.o main.o
+	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
+
+hashtoken: hashtoken.o
+	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
+
+main.o: main.c queue.h routing.h form.h v1_static.h emitjson.h \
+	scrypt.h tokens.h http_string.h $(HTTPSERVER)
+
+form.o: form.c http_string.h $(HTTPSERVER)
+
+routing.o: routing.c $(HTTPSERVER)
+
+hashtoken.o: hashtoken.c scrypt.h
+
+install: all
+	install -Dm755 hashtoken -t $(BINDIR)
+	install -Dm755 warteraum -t $(BINDIR)
+
+clean:
+	rm -f warteraum hashtoken
+	rm -f *.o
+	rm -f test/*.o
+	rm -f $(TEST_BINS)
+
+test/%.o: http_string.h
+
+test/%.test: %.o test/test_%.o
+	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
+
+check: warteraum $(TEST_BINS)
+	@echo == Running unit tests
+	for t in $(TEST_BINS); do ./$$t; done
+	
+	@echo == Checking emitjson with jq
+	./test/emitjson.test -o | jq
+	
+	@echo == Running integration tests
+	./test/integration
diff --git a/warteraum/all.do b/warteraum/all.do
deleted file mode 100644
index 709e512..0000000
--- a/warteraum/all.do
+++ /dev/null
@@ -1 +0,0 @@
-redo-ifchange warteraum hashtoken test/all
diff --git a/warteraum/build_config b/warteraum/build_config
deleted file mode 100644
index 3881462..0000000
--- a/warteraum/build_config
+++ /dev/null
@@ -1,24 +0,0 @@
-if [[ -z "$CC" ]]; then
-  CC=clang
-fi
-
-CFLAGS="-W -Wall -Wextra -pedantic"
-CFLAGS="$CFLAGS -std=gnu99"
-#CFLAGS="$CFLAGS -Weverything"    # too verbose
-
-# disable some warnings not caused by us
-CFLAGS="$CFLAGS -Wno-unused-command-line-argument"   # nix musl-clang
-CFLAGS="$CFLAGS -Wno-gnu-empty-initializer"          # httpserver.h
-
-# fix build issue with glibc 2.31 on NixOS
-# https://github.com/jeremycw/httpserver.h/pull/43
-CFLAGS="$CFLAGS -D_DEFAULT_SOURCE"
-
-# debugging
-CFLAGS="$CFLAGS -g -Og"
-
-# future work
-#CFLAGS="$CFLAGS -fsanitize=address -fno-omit-frame-pointer"
-#CFLAGS="$CFLAGS -static"
-
-# vim: set ft=sh:
diff --git a/warteraum/default.o.do b/warteraum/default.o.do
deleted file mode 100644
index f91bd8f..0000000
--- a/warteraum/default.o.do
+++ /dev/null
@@ -1,29 +0,0 @@
-conf="$(dirname "$0")/build_config"
-source "$conf"
-redo-ifchange "$conf"
-
-redo-ifchange "$2.c"
-
-if [[ -e "$2.h" ]]; then
-  redo-ifchange "$2.h"
-fi
-
-case "$2" in
-  main)
-    redo-ifchange queue.h routing.h form.h v1_static.h emitjson.h
-    redo-ifchange scrypt.h tokens.h http_string.h
-    redo-ifchange ../third_party/httpserver.h/httpserver.h
-    ;;
-  form)
-    redo-ifchange http_string.h
-    redo-ifchange ../third_party/httpserver.h/httpserver.h
-    ;;
-  routing)
-    redo-ifchange ../third_party/httpserver.h/httpserver.h
-    ;;
-  hashtoken)
-    redo-ifchange scrypt.h
-    ;;
-esac
-
-$CC $CFLAGS -o "$3" -c "$2.c"
diff --git a/warteraum/hashtoken.do b/warteraum/hashtoken.do
deleted file mode 100644
index 75e5db9..0000000
--- a/warteraum/hashtoken.do
+++ /dev/null
@@ -1,8 +0,0 @@
-conf="./build_config"
-redo-ifchange "$conf"
-source "$conf"
-
-OBJS="hashtoken.o"
-redo-ifchange $OBJS
-
-$CC $CFLAGS -o "$3" $OBJS -lscrypt-kdf
diff --git a/warteraum/test/all.do b/warteraum/test/all.do
deleted file mode 100644
index 9fac8ba..0000000
--- a/warteraum/test/all.do
+++ /dev/null
@@ -1 +0,0 @@
-redo-ifchange test_queue.exe test_form.exe test_routing.exe test_emitjson.exe
diff --git a/warteraum/test/default.exe.do b/warteraum/test/default.exe.do
deleted file mode 100644
index 8e32f6f..0000000
--- a/warteraum/test/default.exe.do
+++ /dev/null
@@ -1,25 +0,0 @@
-source ../build_config
-redo-ifchange ../build_config
-redo-ifchange test.h
-redo-ifchange "$2.c"
-
-case "$2" in
-  test_queue)
-    OBJS="../queue.o"
-    ;;
-  test_form)
-    OBJS="../form.o"
-    redo-ifchange ../http_string.h
-    ;;
-  test_routing)
-    OBJS="../routing.o"
-    redo-ifchange ../http_string.h
-    ;;
-  test_emitjson)
-    OBJS="../emitjson.o"
-    ;;
-esac
-
-redo-ifchange $OBJS
-
-$CC $CFLAGS -o "$3" $OBJS "$2.c"
diff --git a/warteraum/test/run b/warteraum/test/integration
index 5b4a428..a24ca3f 100755
--- a/warteraum/test/run
+++ b/warteraum/test/integration
@@ -3,34 +3,7 @@
 set -e
 cd "$(dirname "$0")"
 
-redo all
-
-TESTS="queue form routing emitjson"
-
-for t in $TESTS; do
-
-  echo -e "\n# $t tests\n"
-  "./test_$t.exe"
-done
-
-echo -e "\n# test emitjson validity\n"
-
-if command -v jq > /dev/null; then
-  if ./test_emitjson.exe -o | jq; then
-    echo -e "\njson validity\tok"
-  else
-    echo -e "\njson validity\tFAIL"
-    exit 1
-  fi
-else
-  echo -e "json validity\tskipped (missing jq)"
-fi
-
-echo -e "\n# warteraum integration tests\n"
-
 if command -v pytest > /dev/null; then
-  redo ../warteraum
-
   rm -f valgrind-log.txt
 
   valgrind \
@@ -56,10 +29,10 @@ if command -v pytest > /dev/null; then
   grep "All heap blocks were freed" valgrind-log.txt || all_freed=$?
   grep "ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)" valgrind-log.txt || no_errors=$?
 
-  if ! (( $all_freed && $no_errors )); then
-    echo -e "\nvalgrind test\tokay"
+  if [[ $all_freed -eq 0 && $no_errors -eq 0 ]]; then
+    echo -e "\nvalgrind test: okay"
   else
-    echo -e "\nvalgrind test\tfail\n"
+    echo -e "\nvalgrind test: fail\n"
     cat valgrind-log.txt
     exit 1
   fi
diff --git a/warteraum/warteraum.do b/warteraum/warteraum.do
deleted file mode 100644
index 1e6bda2..0000000
--- a/warteraum/warteraum.do
+++ /dev/null
@@ -1,7 +0,0 @@
-source ./build_config
-redo-ifchange ./build_config
-OBJS="emitjson.o queue.o routing.o form.o main.o"
-DEPS="$OBJS ../third_party/httpserver.h/httpserver.h"
-redo-ifchange $DEPS
-
-"$CC" $CFLAGS -o "$3" $OBJS -lscrypt-kdf