Chris Smart | 78efac7 | 2016-03-11 16:05:25 +1100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This build script is for running the Jenkins builds using docker. |
| 4 | # |
| 5 | # It expects a few variables which are part of Jenkins build job matrix: |
| 6 | # target = palmetto|qemu|habanero|firestone|garrison |
| 7 | # distro = ubuntu |
| 8 | # WORKSPACE = |
| 9 | |
| 10 | # Trace bash processing |
| 11 | set -x |
| 12 | |
| 13 | # Default variables |
| 14 | target=${target:-palmetto} |
| 15 | distro=${distro:-ubuntu} |
| 16 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
| 17 | http_proxy=${http_proxy:-} |
| 18 | |
| 19 | # Timestamp for job |
| 20 | echo "Build started, $(date)" |
| 21 | |
| 22 | # Configure docker build |
| 23 | |
| 24 | Dockerfile=$(cat << EOF |
| 25 | FROM fedora:23 |
| 26 | |
| 27 | RUN dnf --refresh repolist && dnf install -y \ |
| 28 | bison \ |
| 29 | ccache \ |
| 30 | file \ |
| 31 | flex \ |
| 32 | gcc \ |
| 33 | gcc-c++ \ |
| 34 | git \ |
| 35 | gmp-devel \ |
| 36 | libmpc-devel \ |
| 37 | make \ |
| 38 | mpfr-devel \ |
| 39 | tar \ |
| 40 | texinfo \ |
| 41 | xz |
| 42 | |
| 43 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 44 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 45 | |
| 46 | USER ${USER} |
| 47 | ENV HOME ${HOME} |
| 48 | RUN /bin/bash |
| 49 | EOF |
| 50 | ) |
| 51 | |
| 52 | # Build the docker container |
| 53 | docker build -t gcc/fedora - <<< "${Dockerfile}" |
| 54 | if [[ "$?" -ne 0 ]]; then |
| 55 | echo "Failed to build docker container." |
| 56 | exit 1 |
| 57 | fi |
| 58 | |
| 59 | mkdir -p ${WORKSPACE} |
| 60 | |
| 61 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 62 | #!/bin/bash |
| 63 | |
| 64 | set -x |
| 65 | |
| 66 | export CC="ccache gcc" |
| 67 | mkdir -p "${WORKSPACE}/gcc-build" |
| 68 | mkdir -p "${WORKSPACE}/cross" |
| 69 | |
| 70 | cd "${WORKSPACE}/toolchain-build-script" |
| 71 | ./build-gcc.sh --debug -v HEAD -t ppc -b ${WORKSPACE}/gcc-build -i ${WORKSPACE}/cross --gcc ${WORKSPACE}/gcc --binutils ${WORKSPACE}/binutils-gdb --clean --local |
| 72 | |
| 73 | EOF_SCRIPT |
| 74 | |
| 75 | chmod a+x ${WORKSPACE}/build.sh |
| 76 | |
| 77 | # Run the docker container, execute the build script we just built |
| 78 | docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 79 | -w "${HOME}" -v "${HOME}":"${HOME}":Z -t gcc/fedora ${WORKSPACE}/build.sh |
| 80 | |
| 81 | # Timestamp for build |
| 82 | echo "Build completed, $(date)" |