diff options
author | Renato Golin <renato.golin@linaro.org> | 2017-05-04 15:03:17 +0100 |
---|---|---|
committer | Renato Golin <renato.golin@linaro.org> | 2017-05-04 19:17:43 +0100 |
commit | a9d187520a5af7b67e607b9b1dbb7ab527a567e8 (patch) | |
tree | 14f3da8bd363b1b688c8bf1639768dfb9d5703b2 /tcwg-llvm-common.sh | |
parent | d044b6ce8fae1184e7b554ab39ef76601b569b95 (diff) |
tcwg-llvm-*: Moving common stuff out
This is an NFC patch that just common things up. I'm making sure that we
only handle URLs and toolchain downloads in a single place, which will
later be very useful when we get Jenkins to ask these scripts to create
the trigger files.
This is the first part of TCWG-1117. Adding the trigger files will be
the second.
I have tested on my box by sourcing the common file and calling the
functions with the right parameters as well as running the scripts
(build/release/test) with the appropriate arguments but with the core
logic actually commented out.
I have some empty tar balls with the right names on dev-01. :)
Change-Id: Ice435ad9d5e20152e295413075c32a396ffc5e2a
Diffstat (limited to 'tcwg-llvm-common.sh')
-rwxr-xr-x | tcwg-llvm-common.sh | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/tcwg-llvm-common.sh b/tcwg-llvm-common.sh new file mode 100755 index 00000000..16619673 --- /dev/null +++ b/tcwg-llvm-common.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env bash + +# This script is a common repository for TCWG LLVM Jenkins logic, mainly: +# - Creating tarball names, URLs +# - Downloading toolchains, recognising compilers +# - Generic board attributes (cores, memory, etc) + +# Verify and download the toolchain, if any +download_toolchain() { + local WORKSPACE="$1" + local TOOLCHAIN="$2" + if [ -z "$TOOLCHAIN" ]; then + echo "WARNING: No toolchain specified, using the system one" + return 0 + fi + # Basename/dir + FILE=$(basename "$TOOLCHAIN") + DIR=${FILE//\.tar.*//} + # Download the toolchain + if [ ! -d "$WORKSPACE/$DIR" ]; then + echo "No dir '$WORKSPACE/$DIR'..." + if [ ! -f "$WORKSPACE/$FILE" ]; then + echo "No file '$WORKSPACE/$FILE'..." + echo "Downloading from '$TOOLCHAIN'" + wget --progress=dot:giga "$TOOLCHAIN" -O "$WORKSPACE/$FILE" + fi + if [ ! -s "$WORKSPACE/$FILE" ]; then + echo "ERROR: Failed to retrieve toolchain '$TOOLCHAIN'" + rm -f "$WORKSPACE/$FILE" + exit 1 + fi + echo "Unpacking '$WORKSPACE/$FILE'" + tar xf "$WORKSPACE/$FILE" -C "$WORKSPACE" + fi + if [ ! -d "$WORKSPACE/$DIR/bin" ]; then + echo "ERROR: Toolchain '$TOOLCHAIN' has no 'bin' directory" + exit 1 + fi + # Clang or GCC? + if [ -f "$WORKSPACE/$DIR/bin/clang" ]; then + export CC="$WORKSPACE/$DIR/bin/clang" + export CXX="$WORKSPACE/$DIR/bin/clang++" + elif [ -f "$WORKSPACE/$DIR/bin/gcc" ]; then + export CC="$WORKSPACE/$DIR/bin/gcc" + export CXX="$WORKSPACE/$DIR/bin/g++" + else + echo "ERROR: Toolchain '$TOOLCHAIN' has no known compiler in $DIR/bin" + exit 1 + fi +} + +# Find the closest git hash for the SVN revision +update_git() { + local BASE=$1 + local REV=$2 + + pushd "$BASE" + hash=$("$BASEDIR/svn-git-hash.pl" "$REV" | awk '{print $2}') + + # We don't need to create a branch with the commit, as the clones are new + # Should be ok to stay in a detached head state for this purpose + git checkout "$hash" + popd +} + +# Environment Variables and default values +BASEDIR=$(dirname "$(readlink -f "$0")") +CPUS=$(nproc --all) +# We may use between 500MB and 1GB per link job +LINKJOBS=$(($(free -g | awk '/Mem/ {print $2}')+1)) +if [ "$LINKJOBS" -gt "$CPUS" ]; then + LINKJOBS=$CPUS +fi +# Temporary location for toolchains produced (pushed) +PUSHPREFIX=clang+llvm +PUSHSUFFIX=tar.xz +PUSHSERVER=dev-01.tcwglab +PUSHUSER=tcwg-buildslave + +push_binary_name() { + local TAG="$1" # ex: ci12, 4.0.0-rc1, r300293 + local TRIPLE="$2" # ex: aarch64-linux-gnu + echo "$PUSHPREFIX-$TAG-$TRIPLE" +} + +push_binary_dir() { + local TYPE="$1" # ex: releases/binaries + echo "public_html/builds/$TYPE/llvm" +} + +push_scp_url() { + local TYPE="$1" # ex: releases/binaries + local PUSHDIR="$(push_binary_dir "$TYPE")" + echo "$PUSHSERVER:$PUSHDIR" +} + +push_wget_url() { + local TAG="$1" # ex: ci12, 4.0.0-rc1, r300293 + local TRIPLE="$2" # ex: aarch64-linux-gnu + local TYPE="$3" # ex: releases/binaries + local BINARY="$(push_binary_name "$TAG" "$TRIPLE")" + local PUSHDIR="$(push_binary_dir "$TYPE")" + echo "http://$PUSHSERVER/~$PUSHUSER/$PUSHDIR/$BINARY.$PUSHSUFFIX" +} |