summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRenato Golin <renato.golin@linaro.org>2017-03-15 19:25:19 +0000
committerRenato Golin <renato.golin@linaro.org>2017-03-16 09:47:05 +0000
commit103daab6c3679cbdee4e8ffd7c9b9cc78ae35ace (patch)
treeea5a056d624f5c948f1594f9949c093b9c66e2e8
parent8d8140a8ef115e04e33b371164da0a6181d9ac69 (diff)
[LLVM] Adds barebones for building LLVM on Jenkins
This is a simple wrapper copied from another TCWG script that should, in theory, build LLVM and check whatever is built. We don't plan on adding all logic to this script, but use this wrapper to call our existing build scripts that know how to do everything aroung LLVM. But first, we need to run a build from Jenkins and see that we can. This is that step. Change-Id: I88aa7d7571eaec1b30b4e99b0a516f5a08b561e8
-rwxr-xr-xtcwg-llvm-build.sh186
1 files changed, 186 insertions, 0 deletions
diff --git a/tcwg-llvm-build.sh b/tcwg-llvm-build.sh
new file mode 100755
index 00000000..4c758b37
--- /dev/null
+++ b/tcwg-llvm-build.sh
@@ -0,0 +1,186 @@
+#!/usr/bin/env bash
+
+# This script is an experiment on how to build LLVM in Jenkins.
+# The steps here are based on the scripts currently in:
+# https://git.linaro.org/toolchain/llvm/linaro-scripts.git
+
+set -e
+
+# Syntax
+SYN_BUILD="--build={ninja|make} (def. make)"
+SYN_BUILDTYPE="--buildtype={Release|Debug} (def. Release)"
+SYN_ASSERTS="--asserts={True|False} (def. True)"
+SYN_SRCDIR="--srcdir=path/to/source"
+SYN_BUILDDIR="--builddir=path/to/build"
+SYN_INSTDIR="--instdir=path/to/install"
+SYN_BUILDJOBS="--buildjobs=N (def. CPUS)"
+SYN_LINKJOBS="--linkjobs=N (def. RAM+1)"
+SYNTAX="$0 $SYN_BUILD $SYN_ASSERTS $SYN_RELEASETYPE $SYN_SRCDIR $SYN_BUILDDIR $SYN_INSTDIR $SYN_LINKJOBS $SYN_BUILDJOBS"
+
+# Environment Variables and default values
+GEN="Unix Makefiles"
+BUILD="make"
+BUILDTYPE="Release"
+ASSERTS="True"
+CPUS=$(nproc --all)
+SRCDIR=""
+BUILDDIR=""
+INSTDIR=""
+BUILDJOBS=$CPUS
+LINKJOBS=$(free -g | awk '/Mem/ {print $2}')
+# We don't want more link jobs than CPUs, even if there's plenty of RAM
+if [ "$LINKJOBS" -ge "$CPUS" ]; then
+ LINKJOBS=$CPUS
+# We may use between 500MB and 1GB per link job, though
+else
+ LINKJOBS=$((LINKJOBS+1))
+fi
+
+# Command line parsing
+while [ "$#" -gt 0 ]; do
+ ARG=$(echo "$1" | cut -d "=" -f 1)
+ VAL=$(echo "$1" | cut -d "=" -f 2)
+ case "$ARG" in
+ --build)
+ if [ "$VAL" = "ninja" ]; then
+ GEN="Ninja"
+ BUILD="ninja"
+ elif [ "$VAL" != "make" ]; then
+ echo "ERROR: $1"
+ echo "Syntax: $SYN_BUILD"
+ exit 1
+ fi
+ shift ;;
+ --buildtype)
+ if [ "$VAL" = "Debug" ]; then
+ BUILDTYPE="$VAL"
+ elif [ "$VAL" != "Release" ]; then
+ echo "ERROR: $1"
+ echo "Syntax: $SYN_BUILDTYPE"
+ exit 1
+ fi
+ shift ;;
+ --asserts)
+ if [ "$VAL" = "False" ]; then
+ ASSERTS="$VAL"
+ elif [ "$VAL" != "True" ]; then
+ echo "ERROR: $1"
+ echo "Syntax: $SYN_ASSERTS"
+ exit 1
+ fi
+ shift ;;
+ --srcdir)
+ if [ -d "$VAL" ]; then
+ SRCDIR="$VAL"
+ else
+ echo "ERROR: Source dir '$VAL' doesn't exist"
+ echo "Syntax: $SYN_SRCDIR"
+ exit 1
+ fi
+ shift ;;
+ --builddir)
+ if [ ! -d "$VAL" ] && ! mkdir -p "$VAL"; then
+ echo "ERROR: Build dir '$VAL' doesn't exist and can't be created"
+ echo "Syntax: $SYN_BUILDDIR"
+ exit 1
+ fi
+ BUILDDIR="$VAL"
+ shift ;;
+ --instdir)
+ if [ ! -d "$VAL" ] && ! mkdir -p "$VAL"; then
+ echo "ERROR: Install dir '$VAL' doesn't exist and can't be created"
+ echo "Syntax: $SYN_INSTDIR"
+ exit 1
+ fi
+ INSTDIR="$VAL"
+ shift ;;
+ --buildjobs)
+ if [ "$VAL" -gt 0 ]; then
+ BUILDJOBS="$VAL"
+ else
+ echo "ERROR: Build jobs '$VAL' not valid"
+ echo "Syntax: $SYN_BUILDJOBS"
+ exit 1
+ fi
+ shift ;;
+ --linkjobs)
+ if [ "$VAL" -gt 0 ]; then
+ LINKJOBS="$VAL"
+ else
+ echo "ERROR: Link jobs '$VAL' not valid"
+ echo "Syntax: $SYN_LINKJOBS"
+ exit 1
+ fi
+ shift ;;
+ *)
+ echo "ERROR: Invalid argument '$1'"
+ echo "Syntax: $SYNTAX"
+ exit 1
+ ;;
+ esac
+done
+
+# Validate options
+if [ "$GEN" = "" ] || [ "$BUILD" = "" ]; then
+ echo "ERROR: Missing Generator / Builder"
+ echo "$SYNTAX"
+ exit 1
+fi
+if [ "$BUILDTYPE" = "" ] || [ "$ASSERTS" = "" ]; then
+ echo "ERROR: Missing build type / asserts option"
+ echo "$SYNTAX"
+ exit 1
+fi
+if [ "$BUILDDIR" = "" ] && [ "$SRCDIR" != "" ]; then
+ BUILDDIR="$SRCDIR/../build"
+ if [ ! -d "BUILDDIR" ] && ! mkdir -p "$BUILDDIR"; then
+ echo "ERROR: Forced build dir '$BUILDDIR' can't be created"
+ echo "Syntax: $SYN_BUILDDIR"
+ exit 1
+ fi
+fi
+if [ "$INSTDIR" = "" ] && [ "$BUILDDIR" != "" ]; then
+ INSTDIR="$BUILDDIR/../install"
+ if [ ! -d "INSTDIR" ] && ! mkdir -p "$INSTDIR"; then
+ echo "ERROR: Forced install dir '$INSTDIR' can't be created"
+ echo "Syntax: $SYN_INSTDIR"
+ exit 1
+ fi
+fi
+if [ "$SRCDIR" = "" ] || [ "$BUILDDIR" = "" ] || [ "$INSTDIR" = "" ]; then
+ echo "ERROR: Missing source / build / install directories"
+ echo "$SYNTAX"
+ exit 1
+fi
+if [ "$LINKJOBS" = "" ] || [ "$BUILDJOBS" = "" ]; then
+ echo "ERROR: Missing number of build / link jobs"
+ echo "$SYNTAX"
+ exit 1
+fi
+
+# Dump
+echo "GEN = $GEN"
+echo "BUILD = $BUILD"
+echo "BUILDTYPE = $BUILDTYPE"
+echo "ASSERTS = $ASSERTS"
+echo "SRCDIR = $SRCDIR"
+echo "BUILDDIR = $BUILDDIR"
+echo "INSTDIR = $INSTDIR"
+echo "BUILDJOBS = $BUILDJOBS"
+echo "LINKJOBS = $LINKJOBS"
+
+# Checkout
+cd "$SRCDIR" && git clone http://llvm.org/git/llvm.git
+cd "$SRCDIR/llvm/tools" && git clone http://llvm.org/git/clang.git
+
+# CMake
+OPTIONS="-DLLVM_BUILD_TESTS=True "
+OPTIONS+="-DCMAKE_BUILD_TYPE='$BUILDTYPE' "
+OPTIONS+="-DLLVM_ENABLE_ASSERTIONS='$ASSERTS' "
+OPTIONS+="-DCMAKE_INSTALL_PREFIX='$INSTDIR' "
+OPTIONS+="-DLLVM_PARALLEL_COMPILE_JOBS='$BUILDJOBS' "
+OPTIONS+="-DLLVM_PARALLEL_LINK_JOBS='$LINKJOBS' "
+cd "$BUILDDIR" && cmake -G "$GEN" "$SRCDIR" "$OPTIONS" -DLLVM_LIT_ARGS="-sv -j$CPUS"
+
+# Build + check
+cd "$BUILDDIR" && ninja "-j$CPUS" check-all