Repository: google/glome (language: python)

Issue:
Increase portability of GLOME build
The build process contains a couple of minor choices that prevent porting onto non-glibc systems. My use case is Alpine, but the situation is probably similar on MacOS or *BSD.

- Bash shell is assumed to be available, thus bashisms in scripts.
- Non-POSIX utilities used: `mktemp`,  `realpath`.
- glibc-only headers are used (unnecessarily :) ).


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2717c29e..7f83268b 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -12,19 +12,28 @@ jobs:
   # See https://github.com/actions/virtual-environments#available-environments
   pr_presubmit:
     runs-on: ubuntu-18.04
+    strategy:
+      matrix:
+        container:
+        - "python:3.5-buster"
+        - "alpine:3.12"
     container:
-      image: "python:3.5-buster"
+      image: ${{ matrix.container }}
 
     steps:
     - uses: actions/checkout@v2
-    - name: install dependencies
+    - name: install Debian dependencies
+      if: ${{ matrix.container == 'python:3.5-buster' }}
       run: ./kokoro/rodete/fetch_dependencies.sh
+    - name: install Alpine dependencies
+      if: ${{ matrix.container == 'alpine:3.12' }}
+      run: ./kokoro/alpine/fetch_dependencies.sh
     - name: setup build directory
       run: meson build
     - name: build
       run: ninja -C build
     - name: test
-      run: meson test -C build
+      run: meson test --print-errorlogs -C build
     - name: install
       run: |
         DESTDIR=out meson install -C build
@@ -34,6 +43,7 @@ jobs:
         test -f build/out/usr/local/etc/glome/config
         test -f build/out/usr/local/include/glome.h
         # Dereference the library and check that it points to a valid file.
+        test -f build/out/usr/local/lib/libglome.so || \
         test -f build/out/usr/local/lib/x86_64-linux-gnu/libglome.so
 
   pr_code_format:
@@ -112,3 +122,12 @@ jobs:
         golint -set_exit_status=1 ./...
     - name: run unit tests
       run: go test ./...
+
+  shell_presubmit:
+    runs-on: ubuntu-18.04
+    container:
+      image: "koalaman/shellcheck-alpine:v0.7.1"
+    steps:
+    - uses: actions/checkout@v2
+    - name: test POSIX conformance and lint
+      run: find . -name "*.sh" | xargs shellcheck --shell=sh
diff --git a/cli/commands.c b/cli/commands.c
index 32e89878..44210a1d 100644
--- a/cli/commands.c
+++ b/cli/commands.c
@@ -15,7 +15,6 @@
 #include "commands.h"
 
 #include <errno.h>
-#include <error.h>
 #include <fcntl.h>
 #include <getopt.h>
 #include <limits.h>
diff --git a/cli/main.c b/cli/main.c
index 268d7d8e..e1d7edc7 100644
--- a/cli/main.c
+++ b/cli/main.c
@@ -13,7 +13,6 @@
 // limitations under the License.
 
 #include <errno.h>
-#include <error.h>
 #include <fcntl.h>
 #include <getopt.h>
 #include <limits.h>
diff --git a/kokoro/alpine/fetch_dependencies.sh b/kokoro/alpine/fetch_dependencies.sh
new file mode 100755
index 00000000..6bc81030
--- /dev/null
+++ b/kokoro/alpine/fetch_dependencies.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+set -e
+
+apk add --no-cache \
+  alpine-sdk meson \
+  openssl-dev confuse-dev glib-dev linux-pam-dev
diff --git a/login/login.c b/login/login.c
index 0471d92e..a61d7169 100644
--- a/login/login.c
+++ b/login/login.c
@@ -15,7 +15,6 @@
 #include "login.h"
 
 #include <assert.h>
-#include <bits/local_lim.h>
 #include <glib.h>
 #include <glome.h>
 #include <netdb.h>


Test patch:
diff --git a/cli/test.sh b/cli/test.sh
index 1455383e..eeae6501 100755
--- a/cli/test.sh
+++ b/cli/test.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
 # Copyright 2020 Google LLC
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,39 +15,43 @@
 
 set -eu
 
-binary="$(realpath ${1?})"
+binary="$(dirname "$1")/$(basename "$1")"
 iterations="${2:-0}"
 
-if [[ ! -x "$binary" ]]; then
+if ! test -x "$binary"; then
   echo "ERROR: $binary is not an executable"
   exit 1
 fi
 
-if (( iterations < 0 || iterations > 255 )); then
+if [ "$iterations" -lt 0 ] || [ "$iterations" -gt 255 ]; then
   echo "ERROR: the number of iterations must be within 0..255 (was: $iterations)"
   exit 2
 fi
 
-errors=0
-t=$(mktemp -d glometest.XXX)
-trap "rm -rf -- '${t?}'" EXIT
+t=$(mktemp -d)
+cleanup() {
+  rm -rf -- "${t?}"
+}
+trap cleanup EXIT
 
 for side in 0 1; do
         "$binary" genkey | tee "${t}/${side}" | "$binary" pubkey >"${t}/${side}.pub"
 done
 
+errors=0
 for counter in $(seq 0 "$iterations"); do
-  msg="$RANDOM"
+  msg="Hello, world!"
   for side in 0 1; do
-    peer=$((1 - "$side"))
+    peer=$((1 - side))
     tag=$(printf %s "$msg" | "$binary" tag --key "${t}/${side}" --peer "${t}/${peer}.pub" --counter "$counter")
     for len in $(seq 2 2 64); do
-      if ! printf %s "$msg" | "$binary" verify -k "${t}/${peer}" -p "${t}/${side}.pub" -c "$counter" -t "${tag:0:$len}"; then
-        let errors++
+      shorttag=$(printf %s "$tag" | head -c "$len")
+      if ! printf %s "$msg" | "$binary" verify -k "${t}/${peer}" -p "${t}/${side}.pub" -c "$counter" -t "${shorttag}"; then
+        errors=$((errors + 1))
         echo "FAIL: side=${side} peer=${peer} msg=${msg} counter=${counter}"
       fi
-      if printf %s "wrong-$msg" | "$binary" verify -k "${t}/${peer}" -p "${t}/${side}.pub" -c "$counter" -t "${tag:0:$len}"; then
-        let errors++
+      if printf %s "wrong-$msg" | "$binary" verify -k "${t}/${peer}" -p "${t}/${side}.pub" -c "$counter" -t "${shorttag}"; then
+        errors=$((errors + 1))
         echo "FAIL: incorrectly verified! side=${side} peer=${peer} msg=${msg} counter=${counter}"
       fi
     done