allow scheduling builds via webapp
[~helmut/crossqa.git] / build.sh
1 #!/bin/sh
2 set -u
3 set -e
4 die() {
5         echo "error: $*" 1>&2
6         exit 254
7 }
8 test "$#" = 2 || die "usage: $0 <architecture> <package>"
9 HOST_ARCH="$1"
10 PACKAGE="$2"
11 if ! dpkg-architecture "-a$HOST_ARCH" >/dev/null 2>&1; then
12         die "$HOST_ARCH is not a valid architecture"
13 fi
14 BUILDTMP=$(mktemp -d) || die "failed to create temporary directory"
15 cleanup() {
16         rm -R -f "$BUILDTMP"
17 }
18 trap cleanup EXIT
19 cd "$BUILDTMP" || die "failed to cd to tmpdir"
20 export SBUILD_CONFIG="$BUILDTMP/sbuild.conf"
21 cat >"$SBUILD_CONFIG" <<'EOF'
22 $build_arch_any = 1;
23 $build_arch_all = 0;
24 $build_source = 0;
25 $distribution = "unstable";
26 $build_profiles = "cross nocheck";
27 $manual_depends = ["libc-dev", "libstdc++-dev"];
28 $dpkg_buildpackage_user_options = ["--jobs-try=1"];
29 $bd_uninstallable_explainer = "apt";
30 $source_only_changes = 0;
31 $apt_update = 1;
32 $apt_distupgrade = 1;
33 $lintian_opts = ["-T", "binary-from-other-architecture,triplet-dir-and-architecture-mismatch"];
34 #$lintian_require_success = 1;
35 $run_lintian = 1;
36 $run_autopkgtest = 0;
37 $run_piuparts = 0;
38 $sbuild_mode = "user";
39 1;
40 EOF
41 RET=0
42 sbuild "--host=$HOST_ARCH" "$PACKAGE" >/dev/null || RET=$?
43 for f in *.build; do
44         test -L "$f" && continue
45         test -f "$f" || continue
46         # poor substitute for missing $lintian_require_success.
47         if tail -n20 "$f" | grep -q "^Lintian: fail$"; then
48                 RET=1
49         fi
50         xz -9c "$f"
51 done
52 exit "$RET"