summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfiles/turris_checkout_repo_branch.sh103
-rwxr-xr-xtemplates/turris.run43
2 files changed, 127 insertions, 19 deletions
diff --git a/files/turris_checkout_repo_branch.sh b/files/turris_checkout_repo_branch.sh
new file mode 100755
index 0000000..486c0b1
--- /dev/null
+++ b/files/turris_checkout_repo_branch.sh
@@ -0,0 +1,103 @@
+#!/bin/bash
+set -o errexit -o nounset
+
+helpers_dir="$(dirname "$(readlink -f "$0")")"
+. "$helpers_dir/common.sh"
+
+print_usage() {
+ cat >&2 <<-EOF
+ Usage: ${0##*/} [-h] BRANCH [BOARD]
+ EOF
+}
+
+print_help() {
+ print_usage
+ cat >&2 <<-EOF
+ Use this script to checkout turris-build repository relative to branch on
+ repo.turris.cz. It not only checkouts exact commit in turris-build
+ repository, but it also modifies feeds.conf file so exactly same feeds are
+ used as they were used to build files on server.
+
+ BRANCH argument is required and is target publish branch (Do not mix this
+ with git branch of same name).
+ BOARD is optional argument used to specify different board. In default
+ 'omnia' is used. This is available because sometimes versions for boards
+ are not in sync and can differ. It should be in most cases safe to use
+ default but if you encounter problems you can try setting appropriate
+ board.
+
+ Options:
+ -h, --help Print this help text
+ EOF
+}
+
+target=""
+board=""
+
+declare -A long2short=( ["help"]="h" )
+dashdash="n"
+while [ "$OPTIND" -le "$#" ]; do
+ argument="${!OPTIND}"
+ if [ "$dashdash" = "n" ] && getopts ":h" opt; then
+ if [ "${argument:0:2}" = "--" ]; then
+ longopt="${argument:2}"
+ if [ -v long2short["$longopt"] ]; then
+ opt="${long2short[$longopt]}"
+ else
+ OPTARG="$argument"
+ fi
+ fi
+ case "$opt" in
+ h)
+ print_help
+ exit 0
+ ;;
+ \?)
+ echo "Illegal option: $OPTARG"
+ exit 1
+ ;;
+ esac
+ continue
+ elif [ "$argument" == "--" -a "$dashdash" = "n" ]; then
+ dashdash="y"
+ continue
+ elif [ -z "$target" ]; then
+ target="$argument"
+ elif [ -z "$board" ]; then
+ board="$argument"
+ else
+ echo "Unexpected argument: $argument"
+ exit 1
+ fi
+ ((OPTIND = OPTIND + 1))
+done
+
+[ -z "$target" ] && {
+ print_usage
+ exit 1
+}
+[ -z "$board" ] && board="omnia"
+
+[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true" ] && \
+ die "Current working directory is not in git repository"
+
+toplevel="$(git rev-parse --show-toplevel)"
+
+hashes="$(curl "https://repo.turris.cz/$target/$board/packages/git-hash" | \
+ tail -n +2 | grep -v '^$' | sed 's/^ \* //;s/: /:/')"
+
+get_hash() {
+ awk -F: -vname="$1" '$1 == name { print $2 }' <<<"$hashes"
+}
+
+# Initaly checkout turris-build
+git checkout "$(get_hash turris-build)"
+
+# And secondly modify feeds so we are modifying appropriate version
+while read -r tp name url vars; do
+ [ "$tp" = "#" ] && fullname="$name" || fullname="feeds/$name"
+ githash="$(get_hash "$fullname")"
+ [ -n "$githash" ] && url="$(sed "s/[;^].*$//;s/$/\^$githash/" <<<"$url")"
+ echo "$tp" "$name" "$url" "$vars"
+done < "$toplevel/feeds.conf" >feeds.conf.new
+mv feeds.conf.new feeds.conf
diff --git a/templates/turris.run b/templates/turris.run
index eb481fa..fe19330 100755
--- a/templates/turris.run
+++ b/templates/turris.run
@@ -2,40 +2,45 @@
# vim: ft=sh
. "$(dirname "$(readlink -f "$0")")/../job.common"
###################################################
-parallel=-j$(($(nproc) * 2)) -l$(nproc)
-make="make $paralel IS_TTY=1 BUILD_LOG=1"
+parallel="-j$(($(nproc) * 2)) -l$(nproc)"
+make="make $parallel BUILD_LOG=1"
if [ "$V" -ge 1 ]; then
parallel=-j1
- make="make -j1 IS_TTY=1 BUILD_LOG=1 V=99"
+ make="make -j1 BUILD_LOG=1 V=99"
fi
###################################################
-
-curl "https://repo.turris.cz/$ANIMAL/$BOARD/packages/git-hash" > git-hash
-cat git-hash
+export IS_TTY=1
# TODO take lock so we won't run multiple instances of new builds
+
if [ -z "$CLEAN" ] && [ -f "$WORKSPACE/openwrt-git-hash" ] && cmp -s git-hash "$WORKSPACE/openwrt-git-hash"; then
echo_info "Using previous version of SDK"
tar -xzf "$WORKSPACE/openwrt.tar.gz"
else
echo_info "Building new version of SDK"
echo_stage "Get turris-build"
- TB_HASH="$(awk '/ \* turris-build: / {print $3}' git-hash)"
- git_fetch_t "https://gitlab.labs.nic.cz/turris/turris-build.git" turris-build "$TB_HASH"
+ git_fetch_t "https://gitlab.labs.nic.cz/turris/turris-build.git" turris-build "$ANIMAL"
+
+ echo_stage "Checkout appropriate branch"
+ (
+ cd turris-build
+ "$FILES/turris_checkout_repo_branch.sh" "$ANIMAL"
+ cat feeds.conf
+ )
echo_stage "Prepare SDK"
mkdir openwrt
(
- cd openwrt
- cat > .turris-build.conf <<EOF
-GIT_MIRROR="$TWORKSPACE/openwrt-git-mirror"
-DL_MIRROR="$TWORKSPACE/openwrt-dl-mirror"
-CCACHE_HOST_DIR="$TWORKSPACE/ccache-host"
-CCACHE_TARGET_DIR="$WORKSPACE/ccache-target"
-EOF
- sed -i 's/^PUBLISH_BRANCH="hbs"$/PUBLISH_BRANCH="hbk"/' defaults.sh # Tweak target to point to HBK
- ../turris-build/compile_pkgs -t "$BOARD" -p "$ANIMAL" $parallel \
- repo_prepare compile_tools compile_target autopkg
- $make package/usign/host/compile
+ cd openwrt
+ cat > .turris-build.conf <<-EOF
+ GIT_MIRROR="$TWORKSPACE/openwrt-git-mirror"
+ DL_MIRROR="$TWORKSPACE/openwrt-dl-mirror"
+ CCACHE_HOST_DIR="$TWORKSPACE/ccache-host"
+ CCACHE_TARGET_DIR="$WORKSPACE/ccache-target"
+ EOF
+ sed -i 's/^PUBLISH_BRANCH="hbs"$/PUBLISH_BRANCH="hbk"/' defaults.sh # Tweak target to point to HBK
+ ../turris-build/compile_pkgs -t "$BOARD" -p "$ANIMAL" $parallel \
+ prepare_tools autopkg
+ $make package/usign/host/compile
)
tar -czf openwrt.tar.gz openwrt
mv openwrt.tar.gz "$WORKSPACE/openwrt.tar.gz"