aboutsummaryrefslogtreecommitdiff
path: root/build-scripts/build-android-lcr
blob: 9d8b5880ca0da7d197fa5ebc043926ef6781bbb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
###############################################################################
# Copyright (c) 2019 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"

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

calc_make_jobs

java -version

# Download overlays ASAP for fail-fast approach
if [ -n "$SOURCE_OVERLAY" ]; then
    download_overlays "$SOURCE_OVERLAY"
    unpack_overlays "$SOURCE_OVERLAY"
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 -
        repo sync -j16
    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

# 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
export TIMEFORMAT="TIME: Compilation: %lR"
if [ -f ./android-build-configs/linaro-build.sh ]; then
    time ./android-build-configs/linaro-build.sh -c "${BUILD_CONFIG_FILENAME}" -ss
else
    source build/envsetup.sh
    [ -n "$LUNCH" ] && lunch "$LUNCH"
    time $MAKE $MAKE_OPTS -j$MAKE_JOBS $MAKE_TARGETS
fi
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

# 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

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

cp changelog.txt out/

flatten_artifacts