aboutsummaryrefslogtreecommitdiffstats
path: root/docker/build-project.sh
blob: 86170bd8b66ccd345c8ad829ef277879d53847bd (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash -xeu
# build-project.sh: Build images for specific layer project
# Copyright (c) 2016, Intel Corporation.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.

. $(dirname $0)/build-common-util.sh

# Catch errors in pipelines
set -o pipefail

BUILD_TARGET="$@"

# bitbake started to depend on a locale with UTF-8 support
# when migrating to Python3.
export LC_ALL=en_US.UTF-8

cd $WORKSPACE

# use +u to avoid exit caused by unbound variables use in init scripts
set +u
# BUILD_DIR is undef in CI case, but is set in local-build case.
source oe-init-build-env ${BUILD_DIR}
set -u

if [ ! -z ${JOB_NAME+x} ]; then
  # in CI run only:
  # get commit ID for using in buildhistory tagging
  CI_GIT_COMMIT=$(git rev-parse HEAD)

  # Prepare for buildhistory generation in BH branch, name of which
  # is composed from JOB_NAME and TARGET_MACHINE
  _BUILDHISTORY_DIR="${PUBLISH_DIR}/buildhistory"
  BUILDHISTORY_TMP=${WORKSPACE}/buildhistory
  BUILDHISTORY_BRANCH="${JOB_NAME}/${TARGET_MACHINE}"

  # Clone master buildhistory, checkout this build speficic branch
  rm -fr ${BUILDHISTORY_TMP}
  git clone ${_BUILDHISTORY_DIR} ${BUILDHISTORY_TMP}
  pushd ${BUILDHISTORY_TMP}
  if ! git checkout ${BUILDHISTORY_BRANCH} --; then
    git checkout --orphan ${BUILDHISTORY_BRANCH} --;
    git reset
    git clean -fdx
  fi
  git rm --ignore-unmatch -rf . >/dev/null
  popd
fi

# create auto.conf using functions in build-common-util.sh
auto_conf_common
auto_conf_archiver
if [ ! -z ${JOB_NAME+x} ]; then
    # in CI run only:
    auto_conf_buildhistory
fi

export BUILD_ID=${CI_BUILD_ID}
export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE BUILD_ID"

if [ -z "$BUILD_TARGET" ]; then
  # Try to read build targets from configured CI specific settings.
  # refkit_ci_vars is made in pre-build script in CI run, but
  # may need to be created in local-build run.
  if [ ! -f ${WORKSPACE}/refkit_ci_vars ]; then
    # use bitbake -e for variables parsing, then pick REFKIT_CI part
    bitbake -e >bb_e_out 2>bb_e_err || (cat bb_e_err && false)
    grep -E "^REFKIT_CI" bb_e_out > ${WORKSPACE}/refkit_ci_vars || true
  fi
  _bitbake_targets=""
  for ci_var in `perl -pe "s/^([A-Z_]+)=.+/\1/g" ${WORKSPACE}/refkit_ci_vars`; do
    case "$ci_var" in
    (REFKIT_CI_BUILD_TARGETS) _sufx="" ;;
    (REFKIT_CI_SDK_TARGETS) _sufx=":do_populate_sdk" ;;
    (REFKIT_CI_ESDK_TARGETS) _sufx=":do_populate_sdk_ext" ;;
    (REFKIT_CI_TEST_EXPORT_TARGETS) _sufx=":do_test_iot_export" ;;
    (*) continue;;
    esac
    for img in `grep ${ci_var} ${WORKSPACE}/refkit_ci_vars | perl -pe 's/.+="(.*)"/\1/g; s/[^ a-zA-Z0-9_-]//g'`; do
      _bitbake_targets="$_bitbake_targets ${img}${_sufx}"
    done
  done
  if [ -z "$_bitbake_targets" ]; then
    # Autodetection failed.
    echo "ERROR: can't detect build targets. Check that REFKIT_CI_*_TARGETS defined in your configs."
    exit 1
  fi
else
  _bitbake_targets="$BUILD_TARGET"
fi

bitbake_build () {
  local targets="$@"
  if [ ! -z ${JOB_NAME+x} ]; then
    # CI run: save output to log file
    bitbake $targets 2>&1 | tee -a $WORKSPACE/$CI_LOG
  else
    bitbake $targets
  fi
}

# Main build.
bitbake_build ${_bitbake_targets}

# Now that the main build phase is done, also build some variants.
# We can do that in parallel, but we have to use different TMPDIRs,
# because otherwise files that need to be different because of
# the different distro features would overwrite each other.
multiconfig_features="x11 wayland"
for feature in $multiconfig_features; do
    mkdir -p conf/multiconfig
    cat >conf/multiconfig/$feature.conf <<EOF
require conf/distro/include/refkit-core-$feature.inc
REFKIT_BUILD_CONFIG = "$feature"
# We cannot un-inherit buildhistory at this point?
# Use a different directory because of https://bugzilla.yoctoproject.org/show_bug.cgi?id=11839
BUILDHISTORY_DIR_append = "-$feature"
BUILDHISTORY_COMMIT = "0"
EOF
done
echo "BBMULTICONFIG = '$multiconfig_features'" >>conf/auto.conf

# For each of these images there has to be a recipe in
# meta-refkit-core/recipes-selftest/images. We could also
# export tests for DAFT here.
multiconfig_targets="multiconfig:x11:refkit-image-common-x11 multiconfig:wayland:refkit-image-common-wayland"
bitbake_build $multiconfig_targets

# TODO: publish-project.sh needs to be adapted. For example, it only
# rsyncs detailed logs from tmp-glibc, but not tmp-glibc-11 or tmp-glibc-wayland.

if [ ! -z ${JOB_NAME+x} ]; then
  # in CI run only:
  # #############
  # Push buildhistory into job-machine-specific branch in the master buildhistory
  pushd ${BUILDHISTORY_TMP}
  BUILDHISTORY_TAG="${JOB_NAME}/${CI_BUILD_ID}/${CI_GIT_COMMIT}/${TARGET_MACHINE}"
  git tag -a -m "Build #${BUILD_NUMBER} (${BUILD_TIMESTAMP}) of ${JOB_NAME} for ${TARGET_MACHINE}" -m "Built from Git revision ${CI_GIT_COMMIT}" ${BUILDHISTORY_TAG} refs/heads/${BUILDHISTORY_BRANCH}

  git push origin refs/tags/${BUILDHISTORY_TAG}:refs/tags/${BUILDHISTORY_TAG}
  # push branch might fail if multiple concurent jobs running for this branch.
  # That's ok, as most important part is stored under tag.
  git push origin refs/heads/${BUILDHISTORY_BRANCH}:refs/heads/${BUILDHISTORY_BRANCH} || true
  popd

  # #############
  # Create testinfo data for CI tester session
  set +e
  REFKIT_CI_TEST_RUNS=`grep REFKIT_CI_TEST_RUNS= ${WORKSPACE}/refkit_ci_vars | perl -pe 's/.+="(.*)"/\1/g; s/[^ ,.a-zA-Z0-9_-]//g'`
  if [ -n "$REFKIT_CI_TEST_RUNS" ]; then
    for row in $REFKIT_CI_TEST_RUNS; do
      echo $row >> ${WORKSPACE}/${TARGET_MACHINE}.testinfo.csv
    done
  else
    # No automatic testing targets found
    echo -n "" > ${WORKSPACE}/${TARGET_MACHINE}.testinfo.csv
  fi
  set -e
fi