Skip to content

Instantly share code, notes, and snippets.

@smoser
Last active March 15, 2016 16:34
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 smoser/93ba44ed30481df12577 to your computer and use it in GitHub Desktop.
Save smoser/93ba44ed30481df12577 to your computer and use it in GitHub Desktop.
building of openblockchain/obc-peer on trusty

building openblockchain/obc-peer on Ubuntu Trusty 14.04

Intent of this gist is to show building of openblcokchain/obc-peer on 14.04

setup

To set up (download source, install packages and build necessary deps):

. config
./setup

build

To build:

. config
cd $GOPATH/src/github.com/openblockchain/obc-peer
go clean
go build

looping build

To 'clean', then 'build' in a loop with timings:

loop-commands 10
#!/bin/sh
#
# This just selects which kernel to boot on an ubuntu
# system and sets it to boot with 'grub-reboot'
#
# based on http://statusq.org/archives/2012/10/24/4584/ and
# http://statusq.org/archives/2012/10/24/4584/
kernel_in="$1"
kernel=""
fail() { [ $# -eq 0 ] || msg "$@"; exit 1; }
msg() { echo "$@" 1>&2; }
[ "$(id -u)" = "0" ] || fail "not root. sorry"
if [ -f "$kernel_in" ]; then
kernel=${kernel_in}
elif [ -f "/boot/$kernel_in" ]; then
kernel="/boot/${kernel_in}"
else
kmatch="$kernel_in"
if [ "${kmatch#*/}" = "$kmatch" ]; then
kmatch="/boot/vmlinu?-${kmatch#vmlinu?-}*"
else
kmatch="/boot/$kmatch"
fi
msg "kmatch=$kmatch"
for f in $kmatch; do
if [ -f "$f" ]; then
if [ -n "$kernel" ]; then
fail "multiple kernels match $kmatch"
fi
kernel="$f"
fi
done
fi
gdef=$(sh -c '. /etc/default/grub && echo $GRUB_DEFAULT')
if [ "$gdef" != "saved" ]; then
msg "enabling GRUB_DEFAULT=saved in /etc/default/grub"
sed -i.back 's,^GRUB_DEFAULT=.*,GRUB_DEFAULT=saved,' /etc/default/grub ||
fail "failed to enable GRUB_DEFAULT=saved"
update-grub ||
fail "failed update-grub to apply GRUB_DEFAULT=saved"
fi
[ -f "$kernel" ] || fail "did not find kernel"
submenu="Advanced options for Ubuntu"
prefix="Ubuntu, with Linux "
# VER-FLAV like '3.13.0-79-generic'
# /boot/vmlinuz-VER-FLAV -> vmlinuz-VER-FLAV
verflav=${kernel##*/}
# vmlinuz-VER-FLAV - VER-FLAV
verflav=${verflav#*-}
entry="${submenu:+${submenu}}>${prefix}$verflav"
if ! grep -q "$prefix$verflav" "/boot/grub/grub.cfg"; then
fail "no $prefix$verflav entry in /boot/grub/grub.cfg"
fi
msg "selected $kernel. entry: ${entry}"
#grub-set-default "$entry"
grub-reboot "$entry"
#!/bin/sh
# if you need a proxy set it here
export proxy=""
export GOPATH=${GOPATH:-$HOME}
#!/usr/bin/env python
import os
import sys
import time
from subprocess import Popen, STDOUT
DEVNULL = open(os.devnull, 'wb', 0)
def runcmd(cmd):
start = time.time()
p = Popen(cmd, stdout=DEVNULL, stderr=STDOUT)
ru = os.wait4(p.pid, 0)[2]
elapsed = time.time() - start
# real, user, system
return {'real': elapsed, 'user': ru.ru_utime, 'system': ru.ru_stime}
def printmsg(name, data):
ffmt = "8.3f"
fmt = ("%(name)-10s:" +
" real %(real)" + ffmt +
" user %(user)" + ffmt +
" system %(system) " + ffmt)
mydata = data.copy()
mydata['name'] = name
print(fmt % mydata)
def runloop(commands, count, data):
# first run not counted in results.
for name, cmd in commands:
curdata = runcmd(cmd)
printmsg("run0 %s" % name, curdata)
for n in range(count):
for name, cmd in commands:
curdata = runcmd(cmd)
if name not in data:
data[name] = curdata.copy()
else:
for k, v in curdata.items():
data[name][k] += v
printmsg(name, curdata)
for name, cmd in commands:
printmsg("tot %s" % name, data[name])
printmsg("avg %s" % name,
{k: v/count for k, v in data[name].items()})
commands = [
("clean", ['go', 'clean']),
("build", ['go', 'build']),
]
data = {}
count = int(sys.argv[1])
runloop(commands, count, data)
#!/bin/sh
# if you need a http proxy, set here.
if [ -n "$proxy" ]; then
export no_proxy="${no_proxy:+${no_proxy},}localhost,127.0.0.1,127.0.1.1,launchpad.net,ubuntu.com"
export https_proxy="$proxy" http_proxy="$proxy"
fi
[ $# -eq 0 ] && set -- ${SHELL:-/bin/bash}
exec "$@"
#!/bin/sh
fail() { echo "$@" 1>&2; exit 1; }
filter_installed_packages() {
# write to stdout, a list of packages not installed locally
local fmt='${Package} ${Version}\n'
LC_ALL=C dpkg-query --show "--showformat=${fmt}" "$@" 2>&1 | awk '
$0 ~ /[Nn]o packages/ {
sub("[.]$","",$NF);
pkgs[n]=$NF;
n=n+1;
}
$2 == "" {
pkgs[n]=$1;
n=n+1;
};
END { for(p in pkgs) {printf("%s ",pkgs[p])}; printf("\n"); }' n=0
}
[ -n "$GOPATH" ] || fail "must . config"
if command -v proxy >/dev/null; then
proxycmd="$proxy"
elif [ -x "${0%/*}/proxy" ]; then
proxycmd="$proxy"
fi
set -e
mkdir -p "$GOPATH/src"
deps="libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev golang-1.6 git make g++"
missing=$(filter_installed_packages $deps)
if [ -n "$missing" ]; then
echo "need $missing"
sudo apt-add-repository -y ppa:mwhudson/go16-trusty
sudo sh -c "apt-get update -q && apt-get install -qy $deps"
fi
## obc-peer depends on rocksdb.git (or one of its dependencies does)
## rockdb.git is a c++ project and is slow to watch build
## on one serverstack trusty vm took 8m32 seconds
cd "$GOPATH/src"
if [ ! -d rocksdb ]; then
$proxycmd git clone https://github.com/facebook/rocksdb.git rocksdb ||
fail "failed clone rocksdb.git"
fi
cd rocksdb
make static_lib
sudo make install
## download project
project="github.com/openblockchain/obc-peer"
cd "$GOPATH"
$proxycmd go get -v "$project"
cd "$GOPATH/src/$project"
$proxycmd go get -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment