aboutsummaryrefslogtreecommitdiffstats
path: root/b2qt-init-build-env
blob: 9fecb9d8ab3b090672783f254d4f9ca1b3f7a672 (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/sh
############################################################################
##
## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of the Boot to Qt meta layer.
##
## $QT_BEGIN_LICENSE:GPL$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see https://www.qt.io/terms-conditions. For further
## information use the contact form at https://www.qt.io/contact-us.
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 3 or (at your option) any later version
## approved by the KDE Free Qt Foundation. The licenses are as published by
## the Free Software Foundation and appearing in the file LICENSE.GPL3
## included in the packaging of this file. Please review the following
## information to ensure the GNU General Public License requirements will
## be met: https://www.gnu.org/licenses/gpl-3.0.html.
##
## $QT_END_LICENSE$
##
############################################################################

set -e

usage() {
  echo "Usage: $(basename $0) COMMAND [ARGS]"
  echo
  echo "Initialize build environment:"
  echo "  $(basename $0) init [--device <name>] "
  echo "                           [--group <group>] [--bsp <layer name>]"
  echo "                           [--manifest <manifest xml>] [--manifest-dir <dir path>]"
  echo "                           [--reference <mirror path>] [--internal]"
  echo "    --device <name>: target device name, default is 'all'"
  echo "    --group <group>: target group of the device when using boot2qt bsp layer, default is 'default'"
  echo "    --bsp <layer name>: name of the boot2qt bsp layer which was used for the repo init"
  echo "    --manifest <manifest xml>: name of the manifest to be used for initialization"
  echo "    --manifest-dir <dir path>: path to a directory containing repo manifest file(s)"
  echo "    --reference <mirror path>: path to local mirror, initialized previously with '$(basename $0) mirror'"
  echo "    --internal: fetch internal repositories, available only inside The Qt Company network."
  echo "Initialize local mirror:"
  echo "  $(basename $0) mirror"
  echo "List available devices:"
  echo "  $(basename $0) list-devices"
}

while test -n "$1"; do
  case "$1" in
    "help" | "--help" | "-h")
      usage
      exit 0
      ;;
    "--reference" | "-r")
      shift
      REFERENCE=$1
      ;;
    "--device" | "-d")
      shift
      DEVICE=$1
      ;;
    "--group" | "-g")
      shift
      PROJECT_GROUPS=$1
      ;;
    "--repo-url")
      shift
      REPO_URL="--repo-url $1"
      ;;
    "--manifest")
      shift
      MANIFEST=$1
      ;;
    "--manifest-dir")
      shift
      MANIFEST_DIR=$1
      ;;
    "--bsp")
      shift
      BSPLAYER=$1
      ;;
    "--internal")
      INTERNAL="y"
      ;;
    *)
      if [ -n "$COMMAND" ]; then
        echo "Unknown argument: $1"
        usage
        exit 1
      fi
      COMMAND=$1
      ;;
  esac
  shift
done

if [ -z "${COMMAND}" ]; then
  usage
  exit 1
fi

DIR=$(dirname $(readlink -f $0))
if [ -n "${REFERENCE}" ]; then
  REFERENCE="--reference $(readlink -f ${REFERENCE})"
fi

if [ -L $0 ]; then
  USING_BSP_LAYER=1
fi

if [ -n "${MANIFEST_DIR}" ]; then
  MANIFEST_DIR="$(readlink -f ${MANIFEST_DIR})"
fi

if [ -z "${REPO_URL}" ]; then
  REPO_URL="--repo-url git://github.com/theqtcompany/git-repo"
fi

DEVICE=${DEVICE:-all}

if [ -z "${MANIFEST}" ]; then
  if [ -n "${USING_BSP_LAYER}" ]; then
    MANIFEST="conf/manifest.xml"
  else
    MANIFEST="manifest.xml"
  fi
fi

get_repo() {
  REPO="./repo"
  if [ -n "$(command -v repo)" ]; then
    REPO="repo"
  elif [ ! -x "./repo" ]; then
    curl -s https://storage.googleapis.com/git-repo-downloads/repo > "./repo"
    chmod +x ./repo
  fi
}

get_groups() {
  if [ -z "${PROJECT_GROUPS}" ]; then
    case ${DEVICE} in
      all)
        PROJECT_GROUPS="external"
        ;;
      imx8qmmek|imx8mqevk)
        PROJECT_GROUPS="fsl-imx8"
        ;;
      apalis-imx8|colibri-imx8qxp)
        PROJECT_GROUPS="toradex-imx8"
        ;;
      apalis-imx6|colibri-imx6|colibri-imx6ull|colibri-vf|colibri-imx7|colibri-imx7-emmc)
        PROJECT_GROUPS="toradex"
        ;;
      nitrogen6x|nitrogen7|nitrogen8m|nitrogen8mm)
        PROJECT_GROUPS="boundary"
        ;;
      imx6qdlsabresd|imx7dsabresd|imx7s-warp)
        PROJECT_GROUPS="fsl"
        ;;
      smarc-samx6i)
        PROJECT_GROUPS="smx6"
        ;;
      raspberrypi*)
        PROJECT_GROUPS="rpi"
        ;;
      intel-corei7-64)
        PROJECT_GROUPS="intel"
        ;;
      tegra-x1|tegra-t18x)
        PROJECT_GROUPS="nvidia-tegra"
        ;;
      jetson-tx1|jetson-tx2|jetson-tk1)
        PROJECT_GROUPS="jetson"
        ;;
      salvator-x|h3ulcb|m3ulcb|ebisu)
        PROJECT_GROUPS="renesas-gen3"
        ;;
      draak)
        PROJECT_GROUPS="renesas-draak"
        ;;
    esac
  fi

  PROJECT_GROUPS="${PROJECT_GROUPS} default"
  if [ "${INTERNAL}" = "y" ]; then
    PROJECT_GROUPS="${PROJECT_GROUPS} internal"
  fi
}

list_devices() {
  echo "Available device configurations:"
  for device in $(ls ${DIR}/meta-boot2qt-distro/conf/distro/include/*.conf); do
    echo "  $(basename ${device%%.conf})"
  done
}

copy_manifests() {
  if [ -z "${USING_BSP_LAYER}" ]; then
    mkdir -p .repo/manifests
    rm -f .repo/manifests/manifest*.xml
    if [ -z "${MANIFEST_DIR}" ]; then
      cp ${DIR}/scripts/manifest*.xml .repo/manifests/
    else
      cp ${MANIFEST_DIR}/manifest*.xml .repo/manifests/
    fi
  fi
}

mirror() {
  if [ -n "${USING_BSP_LAYER}" ]; then
    echo "mirroring is not supported with boot2qt bsp layers"
    exit 1
  fi

  get_groups
  copy_manifests
  ${REPO} init ${REPO_URL} -u ${PWD}/.repo/repo -b default -m ${MANIFEST} -g "${PROJECT_GROUPS}" --mirror
  ${REPO} sync
}

init() {
  get_groups
  copy_manifests

  if [ -n "${USING_BSP_LAYER}" ]; then
    # re-init without url if we are using boot2qt bsp layer
    ${REPO} init -m ${MANIFEST} -g "${PROJECT_GROUPS}" ${REFERENCE}
  else
    ${REPO} init ${REPO_URL} -u ${PWD}/.repo/repo -b default -m ${MANIFEST} -g "${PROJECT_GROUPS}" ${REFERENCE}
  fi
  ${REPO} sync --optimized-fetch

  if [ ! -e "sources/meta-boot2qt" ]; then
    ln -s ${DIR} sources/meta-boot2qt
  fi

  if [ ! -e "setup-environment.sh" ]; then
    ln -s ${DIR}/scripts/setup-environment.sh setup-environment.sh
  fi

  if [ -n "${USING_BSP_LAYER}" ] && [ ! -e "sources/${BSPLAYER}" ]; then
    ln -s ../.repo/manifests sources/${BSPLAYER}
  fi

  # handle lfs repos which need manual lfs pull
  LFS_REPOS=$(grep filter=lfs -l sources/*/.gitattributes 2>/dev/null || true)
  for repo in ${LFS_REPOS}; do
    ( cd $(dirname ${repo}); git lfs pull )
  done
}

get_repo

case "$COMMAND" in
  "init")
    init
    ;;
  "mirror")
    mirror
    ;;
  "list-devices")
    list_devices
    ;;
  *)
    echo "Unknown command"
    usage
    exit 1
    ;;
esac