############################################################################### # Copyright (c) 2014 Linaro # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html ############################################################################### export PATH=$PATH:~/bin/ set -o errtrace git config --global user.email "android-build-bot@fake-email.com" git config --global user.name "android-build-bot" if [ ! -n "$SOURCE_OVERLAY" ]; then echo "ERROR: Missing SOURCE_OVERLAY in the configuration." exit 1 fi if [ "$SOURCE_OVERLAY_OPTIONAL" == "1" -o -n "$SOURCE_OVERLAY_OPTIONAL" ]; then echo "ERROR: SOURCE_OVERLAY_OPTIONAL should not be set in official build configuration." echo " It is meant to be set only in local build scripts to bypass overlays." exit 1 fi source "${BUILD_SCRIPT_ROOT}"/helpers trap infrastructure_error ERR if [ -z "${TARGET_OUT_DIR}" ]; then # only set TARGET_OUT_DIR when it is not set # Set TARGET_OUT_DIR since few TARGET_PRODUCT include "full_" keyword as well export TARGET_OUT_DIR=`echo $TARGET_PRODUCT | sed 's/_/\n/;s/.*\n//'` fi if [ -n "$BUILD_COPYCAT" ]; then download_another_build "$BUILD_COPYCAT" else # Download overlays ASAP for fail-fast approach if [ -n "$SOURCE_OVERLAY" ]; then download_overlays "$SOURCE_OVERLAY" fi # Select JAVA version based on Android version. Android 4.4 < builds with JAVA6 # AOSP master and future build will use java 1.7 openjdk. # Step 1/2 (fail fast) if [ -n "$USE_JAVA_6" ]; then sudo update-java-alternatives --set java-6-sun || true elif [ -n "$USE_JAVA_7" ]; then sudo update-java-alternatives --set java-1.7.0-openjdk-amd64 || true fi java -version # Download toolchain, fail-fast if test -n "$TOOLCHAIN_URL"; then wget -nv --no-check-certificate $TOOLCHAIN_URL fi # Remove any old local manifest and manifest which can break repo init if # duplicate repository are found or forceful manifest update rm -rf .repo/local_manifests .repo/manifest* if [ -n "$REPO_SEED_URL" ]; then repo-sync-from-seed "${1}" else repo-sync-from-mirror "${1}" fi if [ -n "$GERRIT_PROJECT" ] && [ $GERRIT_PROJECT != "android-build-configs" ] && [ $GERRIT_EVENT_TYPE == "comment-added" ]; then if [ ${GERRIT_HOST} == "dev-private-review.linaro.org" ]; then GERRIT_URL="ssh://git@${GERRIT_HOST}/${GERRIT_PROJECT}" else GERRIT_URL="http://${GERRIT_HOST}/${GERRIT_PROJECT}" fi if [ "$GERRIT_PROJECT" == "platform/manifest" ] || [ "$GERRIT_PROJECT" == "linaro-art/platform/manifest" ]; then cd .repo/local_manifests; git pull ${GERRIT_URL} $GERRIT_REFSPEC cd - else cd `grep -rni $GERRIT_PROJECT\" .repo/local_manifests | grep -Po 'path="\K[^"]*'` if git pull ${GERRIT_URL} ${GERRIT_REFSPEC} | grep -q "Automatic merge failed"; then git reset --hard echo "Error: *** Error patch merge failed" exit 1 fi cd - fi fi if [ -n "$PATCHSETS" ]; then for i in $PATCHSETS; do sh ./android-patchsets/$i done fi if [ -n "$POST_CHECKOUT_HOOK" ]; then # if echo "$POST_CHECKOUT_HOOK" | grep -F / >/dev/null; then # echo "Invalid POST_CHECKOUT_HOOK: $POST_CHECKOUT_HOOK" # exit 1 # fi $BUILD_SCRIPT_ROOT/$POST_CHECKOUT_HOOK fi # Generate a Changelog describing additional patches applied to AOSP codebase export android_version=`grep -rni "refs/tags" .repo/manifest.xml | sed -e "s/.*tags\///" -e "s/\"//g"` repo forall -c 'if git rev-parse $android_version >/dev/null 2>&1 then patches=`git log --oneline --no-merges $android_version..HEAD | wc -l` if [ $patches -ne 0 ]; then git_remote=`git remote -v | grep "fetch" | cut -f2 | cut -d " " -f1` echo "=====================================================================" echo "Patchsets applied to $git_remote on top of $android_version" git diff --stat $android_version HEAD git log --oneline --no-merges $android_version..HEAD echo "" fi; fi' | cat > temp_changelog.txt files_changed=`add_changes \`grep -e "file changed" -e "files changed" temp_changelog.txt | cut -d " " -f2\`` insertions=`add_changes \`grep -e "file changed" -e "files changed" temp_changelog.txt | cut -d " " -f5\`` deletions=`add_changes \`grep -e "file changed" -e "files changed" temp_changelog.txt | cut -d " " -f7\`` echo "=====================================================================" > changelog.txt echo "=====================================================================" >> changelog.txt echo "$files_changed files changed, $insertions insertions(+), $deletions deletions(-)" >> changelog.txt echo "=====================================================================" >> changelog.txt echo "=====================================================================" >> changelog.txt echo "" >> changelog.txt cat temp_changelog.txt >> changelog.txt trap - ERR . build/envsetup.sh trap infrastructure_error ERR [ -n "$LUNCH" ] && lunch "$LUNCH" # We evaluate the configuration again because envsetup.sh might well # have stomped on some of the values in it. set -a eval $CONFIGURATION set +a # export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.22/ # export ANDROID_JAVA_HOME=$JAVA_HOME # Select JAVA version based on Android version. Android 4.4 < builds with JAVA6 # AOSP master and future build will use java 1.7 openjdk. # Step 2/2 # if [ -n "$USE_JAVA_6" ]; then # export JAVA_HOME=/usr/lib/jvm/java-6-sun/ # export ANDROID_JAVA_HOME=$JAVA_HOME # elif [ -n "$USE_JAVA_7" ]; then # export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64/ # export ANDROID_JAVA_HOME=$JAVA_HOME # fi MAKE_TARGETS="${MAKE_TARGETS-boottarball systemtarball userdatatarball}" calc_make_jobs if test -n "$TOOLCHAIN_URL"; then toolchain_filename=`echo $TOOLCHAIN_URL | sed -e 's/.*\/\([^/]*\)$/\1/'` mkdir toolchain tar -C toolchain --strip-components 1 -xf $toolchain_filename if test -z "$TOOLCHAIN_TRIPLET"; then # Android 2.x usually needs to be built with arm-eabi, # Android 4.x usually needs to be built with arm-linux-androideabi... if echo $MANIFEST_BRANCH |grep -qE 'android.2\.3'; then p=`find $PWD/toolchain/bin/arm-eabi-gcc 2>/dev/null |head -n1` else p=`find $PWD/toolchain/bin/arm-linux-androideabi-gcc 2>/dev/null |head -n1` fi [ -z "$p" ] && p=`find $PWD/toolchain/bin/*-gcc |head -n1` else p=`find $PWD/toolchain/bin/$TOOLCHAIN_TRIPLET-gcc |head -n1` fi export TARGET_TOOLS_PREFIX=`echo $p | sed -e 's/-gcc$/-/'` fi if [ "$TOOLCHAIN_FINGERPRINT" != "0" -a -n "$toolchain_filename" ]; then mkdir -p fingerprints cp $toolchain_filename fingerprints/ fi if test -z "$TARGET_ARCH_VARIANT" -a -z "$LUNCH"; then TARGET_ARCH_VARIANT=armv7-a-neon fi if test -z "$WITH_HOST_DALVIK"; then WITH_HOST_DALVIK=false fi SHOWCOMMANDS= if ! test -z "$QUIET" && test "$QUIET" = "1"; then SHOWCOMMANDS=showcommands fi if [ -n "$SOURCE_OVERLAY" ]; then unpack_overlays "$SOURCE_OVERLAY" fi if [ -n "$EXTERNAL_TARBALL" ]; then unpack_external_tarball "$EXTERNAL_TARBALL" fi if [ -n "$CLANG_TOOLCHAIN_URL" ]; then unpack_external_tarball "$CLANG_TOOLCHAIN_URL" # Adapt to the aosp toolchain directory hierarchy - compile error otherwise ANDROID_CLANGVER=$(gawk '{ if ($1 == "LLVM_PREBUILTS_VERSION") print $3 }' $PWD/build/core/clang/versions.mk) [ -z $ANDROID_CLANGVER ] && ANDROID_CLANGVER=clang-3217047 # aosp prebuilt build number at 2016/10/20 master mkdir -p upstream_clang/linux-x86/$ANDROID_CLANGVER/ cp -r $(basename ${CLANG_TOOLCHAIN_URL})/* upstream_clang/linux-x86/$ANDROID_CLANGVER/ export LLVM_PREBUILTS_BASE=${PWD}/upstream_clang/ fi if [ -x "${TARGET_TOOLS_PREFIX}gcc" ]; then ${TARGET_TOOLS_PREFIX}gcc -v fi if [ -z "$MAKE" ]; then MAKE=make fi if ! is_on_ec2; then export USE_CCACHE=1 export CCACHE_DIR=$PWD/.ccache if [ ! -e ".ccache" ]; then ./prebuilts/misc/linux-x86/ccache/ccache -M 25G fi fi trap - ERR export TIMEFORMAT="TIME: Compilation: %lR" time $MAKE $MAKE_OPTS -j$MAKE_JOBS $MAKE_TARGETS $SHOWCOMMANDS WITH_HOST_DALVIK="$WITH_HOST_DALVIK" USE_CLANG_PLATFORM_BUILD="$USE_CLANG_PLATFORM_BUILD" unset TIMEFORMAT trap infrastructure_error ERR # Show remaining disk space to catch early if # we're approaching ramdisk limit again echo "Remaining disk space after build:" df if [ -n "$BUILD_SYSROOT" ]; then git clone git://git.linaro.org/android/toolchain/build.git toolchain-build rm -rf /tmp/sysroot toolchain-build/build-sysroot.sh out/target/product/`ls -1 out/target/product | head -n1` /tmp/sysroot tar -cj -C /tmp/sysroot -f out/sysroot.tar.bz2 . fi fi # Create filesystem images if [ -n "$BUILD_FS_IMAGE" ]; then FS_IMAGE_SIZE=${FS_IMAGE_SIZE-2G} sudo linaro-android-media-create \ --dev `product2lamc_dev $TARGET_PRODUCT` \ --system $PWD/out/target/product/$TARGET_OUT_DIR/system.tar.bz2 \ --userdata $PWD/out/target/product/$TARGET_OUT_DIR/userdata.tar.bz2 \ --boot $PWD/out/target/product/$TARGET_OUT_DIR/boot.tar.bz2 \ --image-size "$FS_IMAGE_SIZE" \ --image-file out/target/product/$TARGET_OUT_DIR/$TARGET_PRODUCT.img bzip2 -9 out/target/product/$TARGET_PRODUCT/$TARGET_PRODUCT.img fi # Store kernel .config as a build artifact if [ -f kernel/.config ]; then cp kernel/.config out/kernel_config elif [ -f "out/target/product/$TARGET_OUT_DIR/obj/kernel/.config" ]; then cp "out/target/product/$TARGET_OUT_DIR/obj/kernel/.config" out/kernel_config fi # Create md5sums file for platform artifacts (cd out/target/product/${TARGET_OUT_DIR}/; md5sum *.tar.bz2 *.img *.img.bz2 >MD5SUMS) || true (cd out/; ${BUILD_SCRIPT_ROOT}/create-user-build-script) if [ -f out/kernel_config ]; then (cd out/; ${BUILD_SCRIPT_ROOT}/create-user-kernel-script) || true fi if [ ! -n "$SKIP_LICENSE_CHECK" ]; then ${BUILD_SCRIPT_ROOT}/license-verification.sh out/pinned-manifest.xml out/target/product/$TARGET_PRODUCT/BUILD-INFO.txt fi if [ -n "$PUBLISH_DESCRIPTIONS" ]; then ${BUILD_SCRIPT_ROOT}/../utils/manifest-descriptions/make.sh out/source-manifest.xml out/pinned-manifest.xml fi # Create build_config.json as a build artifact target_kernel_src=`grep '^TARGET_KERNEL_SOURCE' device/linaro/${TARGET_PRODUCT}/BoardConfig.mk|cut -d'=' -f2|tr -d '[[:space:]]'` if [ -n "${target_kernel_src}" ]; then kernel_proj_str=`grep "path=\"${target_kernel_src}\"" out/pinned-manifest.xml` kernel_rev=`echo ${kernel_proj_str} | grep -o "revision[^ ]*" | cut -d"\"" -f2` kernel_branch=`echo ${kernel_proj_str} | grep -o "upstream[^ ]*" | cut -d"\"" -f2` kernel_repo_path=`echo ${kernel_proj_str} | grep -o "path[^ ]*" | cut -d"\"" -f2` cd $kernel_repo_path kernel_repo=`git remote -v | grep "fetch" | cut -f2 | cut -d " " -f1` cd - fi android_ver=`grep "ro\.build\.version\.release" out/target/product/${TARGET_OUT_DIR}/system/build.prop|cut -d"=" -f2` toolchain=`echo ${ANDROID_TOOLCHAIN}|awk -F'/' '{print $(NF-1)}'` build_arch=`echo ${toolchain} | cut -d"-" -f1` compiler=`$(find ${ANDROID_TOOLCHAIN} -name "*-gcc"|head -n1) --version | head -n1` dtbs=`find out -iname *.dtb | rev | cut -d"/" -f1 | rev | sort | uniq` dtbfs="" for f in $dtbs; do dtbfs="\"$f\", $dtbfs" done dtb="[${dtbfs%,*}]" cat > out/build_config.json <