๐Ÿ“ฆ apache / nuttx

๐Ÿ“„ cibuild.sh ยท 189 lines
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#!/usr/bin/env bash
############################################################################
# tools/ci/cibuild.sh
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.  The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

set -e
set -o xtrace

CID=$(cd "$(dirname "$0")" && pwd)
CIWORKSPACE=$(cd "${CID}"/../../../ && pwd -P)
CIPLAT=${CIWORKSPACE}/nuttx/tools/ci/platforms
nuttx=${CIWORKSPACE}/nuttx
apps=${CIWORKSPACE}/apps

os=$(uname -s)
osarch=$(uname -m)
if [ -f /etc/os-release ]; then
  osname=$(grep "^ID=" /etc/os-release | cut -d'=' -f2 | tr -d '"')
else
  osname=${os}
fi

function to_do {
  echo ""
  echo "NuttX TODO: $1"
  echo "The $1 platform does not appear to have been added to this project."
  echo ""
  exit 1
}

function install_tools {
  export NUTTXTOOLS=${CIWORKSPACE}/tools
  mkdir -p "${NUTTXTOOLS}"

  case ${osname} in
    alpine)
      to_do "alpine"
      ;;
    arch)
      to_do "arch"
      ;;
    CYGWIN*)
      to_do "CYGWIN"
      ;;
    debian)
      to_do "debian"
      ;;
    fedora)
      to_do "fedora"
      ;;
    freebsd)
      to_do "freebsd"
      ;;
    Darwin)
      if [ "X$osarch" == "Xx86_64" ]; then
        "${CIPLAT}"/darwin.sh
      else
        "${CIPLAT}"/darwin_arm64.sh
      fi
      ;;
    Linux)
      "${CIPLAT}"/linux.sh
      ;;
    manjaro)
      to_do "manjaro"
      ;;
    msys2)
      "${CIPLAT}"/msys2.sh
      ;;
    ubuntu)
      "${CIPLAT}"/ubuntu.sh
      ;;
    *)
      to_do "unknown"
      ;;
  esac

  source "${CIWORKSPACE}"/tools/env.sh
}

function usage {
  echo ""
  echo "USAGE: $0 [-i] [-s] [-c] [-*] <testlist>"
  echo "       $0 -h"
  echo ""
  echo "Where:"
  echo "  -i install tools"
  echo "  -s setup repos"
  echo "  -c enable ccache"
  echo "  -* support all options in testbuild.sh"
  echo "  -h will show this help text and terminate"
  echo "  <testlist> select testlist file"
  echo ""
  exit 1
}

function enable_ccache {
  export CCACHE_DIR="${CIWORKSPACE}"/tools/ccache
}

function setup_repos {
  pushd .
  if [ -d "${nuttx}" ]; then
    cd "${nuttx}"; git pull
  else
    git clone https://github.com/apache/nuttx.git "${nuttx}"
    cd "${nuttx}"
  fi
  git log -1

  if [ -d "${apps}" ]; then
    cd "${apps}"; git pull
  else
    git clone https://github.com/apache/nuttx-apps.git "${apps}"
    cd "${apps}"
  fi
  git log -1
  popd
}

function run_builds {
  local ncpus
  if [ "X$osname" == "XDarwin" ]; then
    ncpus=$(sysctl -n hw.ncpu)
  else
    ncpus=$(grep -c ^processor /proc/cpuinfo)
  fi

  options+="-j ${ncpus}"

  for build in "${builds[@]}"; do
    "${nuttx}"/tools/testbuild.sh ${options} -e "-Wno-cpp -Werror" "${build}"
  done

  if [ -d "${CCACHE_DIR}" ]; then
    # Print a summary of configuration and statistics counters
    ccache -s
  fi
}

if [ -z "$1" ]; then
   usage
fi

while [ -n "$1" ]; do
  case "$1" in
  -h )
    usage
    ;;
  -i )
    install_tools
    ;;
  -c )
    enable_ccache
    ;;
  -s )
    setup_repos
    ;;
  -* )
    options+="$1 "
    ;;
  * )
    builds=( "$@" )
    break
    ;;
  esac
  shift
done

run_builds