Skip to content

Instantly share code, notes, and snippets.

@oconnor663
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oconnor663/ed6c2b6e5a73d7d021cb to your computer and use it in GitHub Desktop.
Save oconnor663/ed6c2b6e5a73d7d021cb to your computer and use it in GitHub Desktop.
Build script comparison
#! /usr/bin/env python3
from pathlib import Path
from subprocess import run, PIPE
from sys import argv
from tempfile import mkdtemp
here = Path(__file__).parent
build_root = Path(argv[1] if len(argv) >= 2 else mkdtemp())
print("Building in:", build_root)
for goarch, debarch in (("386", "i386"), ("amd64", "amd64")):
print("building Go client for", goarch)
dest = build_root / debarch
(dest/"build/usr/bin").mkdir(exist_ok=True, parents=True)
(dest/"build/DEBIAN").mkdir(exist_ok=True, parents=True)
run("go build -o '{}' github.com/keybase/client/go/keybase".format(
dest/"build/usr/bin/keybase"),
shell=True, check=True)
full_version = run('{} --version'.format(dest/"build/usr/bin/keybase"),
shell=True, universal_newlines=True, stdout=PIPE,
stderr=PIPE)
version = full_version.stdout.split()[2]
template = (here/"control.template").read_text()
control = template.replace("@@VERSION@@", version)
control = control.replace("@@ARCHITECTURE@@", debarch)
(dest/"build/DEBIAN/control").write_text(control)
run("dpkg-deb --build '{}' '{}'".format(
dest/"build",
dest/"keybase.deb"),
shell=True)
(dest/"VERSION").write_text(version)
#! /bin/bash
# Builds the keybase binary and packages it into two ".deb" files, one for i386
# and one for amd64. Takes a build directory as an argument, or creates one in
# /tmp. The package files are created there, in their respective folders.
set -e -u -o pipefail
here="$(dirname "$BASH_SOURCE")"
# Take the first argument, or a tmp dir if there is no first argument.
build_root="${1:-$(mktemp -d)}"
echo Building in: "$build_root"
build_one_architecture() {
echo "building Go client for $GOARCH"
dest="$build_root/$debian_arch"
mkdir -p "$dest/build/usr/bin"
mkdir -p "$dest/build/DEBIAN"
# `go build` reads $GOARCH
go build -o "$dest/build/usr/bin/keybase" github.com/keybase/client/go/keybase
# TODO: Make `keybase --version` behave better.
version="$("$dest/build/usr/bin/keybase" --version 2> /dev/null | cut -d " " -f 3 || true)"
cat "$here/control.template" \
| sed "s/@@VERSION@@/$version/" \
| sed "s/@@ARCHITECTURE@@/$debian_arch/" \
> "$dest/build/DEBIAN/control"
cp "$here/postinst" "$dest/build/DEBIAN/"
dpkg-deb --build "$dest/build" "$dest/keybase.deb"
# Write the version number to a file for the caller's convenience.
echo -n "$version" > "$dest/VERSION"
}
# Note that Go names the x86 architecture differently than Debian does, which
# is why we need these two variables.
export GOARCH=386
export debian_arch=i386
build_one_architecture
export GOARCH=amd64
export debian_arch=amd64
build_one_architecture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment