Skip to content

Commit

Permalink
[scripts] apply shfmt changes (openthread#4966)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhui committed May 19, 2020
1 parent 916023b commit cb9b353
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 195 deletions.
4 changes: 2 additions & 2 deletions bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ nlbuild_autotools_stem="third_party/nlbuild-autotools/repo"

# Establish some key directories

srcdir=`dirname ${0}`
abs_srcdir=`pwd`
srcdir=$(dirname ${0})
abs_srcdir=$(pwd)
abs_top_srcdir="${abs_srcdir}"

exec ${srcdir}/${nlbuild_autotools_stem}/scripts/bootstrap -I "${abs_top_srcdir}/${nlbuild_autotools_stem}" $*
3 changes: 2 additions & 1 deletion script/check-gn-build
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
set -e
set -x

main() {
main()
{
gn gen gn-out
ninja -C gn-out
test -f gn-out/obj/lib-ot-core.a
Expand Down
12 changes: 8 additions & 4 deletions script/check-ncp-rcp-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
set -e
set -x

at_exit() {
at_exit()
{
EXIT_CODE=$?

killall expect || true
Expand All @@ -41,12 +42,14 @@ at_exit() {
exit $EXIT_CODE
}

build() {
build()
{
make -f examples/Makefile-simulation
make -f src/posix/Makefile-posix
}

check() {
check()
{
trap at_exit INT TERM EXIT

rm -rf tmp/
Expand Down Expand Up @@ -127,7 +130,8 @@ EOF
test -n "{RADIO_VERSION}"
}

main() {
main()
{
case "$1" in
build)
build
Expand Down
2 changes: 1 addition & 1 deletion script/check-posix-build-autotools
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ build()
reset_source
make -f src/posix/Makefile-posix

if [[ $OSTYPE != "darwin"* ]] ; then
if [[ $OSTYPE != "darwin"* ]]; then
reset_source
make -f src/posix/Makefile-posix RCP_BUS=spi
fi
Expand Down
2 changes: 1 addition & 1 deletion script/check-posix-build-cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ main()
reset_source
build

if [[ $OSTYPE != "darwin"* ]] ; then
if [[ $OSTYPE != "darwin"* ]]; then
reset_source
build -DOT_POSIX_CONFIG_RCP_BUS=SPI
fi
Expand Down
37 changes: 21 additions & 16 deletions script/check-posix-pty
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
set -e
set -x

die() {
echo " *** ERROR: " $*
exit 1
die()
{
echo " *** ERROR: " $*
exit 1
}

at_exit() {
at_exit()
{
EXIT_CODE=$?

sudo killall expect || true
Expand All @@ -46,17 +48,19 @@ at_exit() {
exit $EXIT_CODE
}

build() {
build()
{
make -f examples/Makefile-simulation
make -f src/posix/Makefile-posix PLATFORM_NETIF=1 PLATFORM_UDP=1 UDP_FORWARD=0 MAX_POWER_TABLE=1
}

check() {
check()
{
trap at_exit INT TERM EXIT

SOCAT_OUTPUT=/tmp/ot-socat
OT_OUTPUT=/tmp/ot-output
socat -d -d pty,raw,echo=0 pty,raw,echo=0 > /dev/null 2> $SOCAT_OUTPUT &
socat -d -d pty,raw,echo=0 pty,raw,echo=0 >/dev/null 2>$SOCAT_OUTPUT &
while true; do
if test $(head -n2 $SOCAT_OUTPUT | wc -l) = 2; then
RADIO_PTY=$(head -n1 $SOCAT_OUTPUT | grep -o '/dev/.\+')
Expand All @@ -70,7 +74,7 @@ check() {
echo 'CORE_PTY' $CORE_PTY

RADIO_NCP_PATH="$(pwd)/$(ls output/*linux*/bin/ot-rcp)"
$RADIO_NCP_PATH 1 > $RADIO_PTY < $RADIO_PTY &
$RADIO_NCP_PATH 1 >$RADIO_PTY <$RADIO_PTY &

# Cover setting a valid network interface name.
readonly VALID_NETIF_NAME="wan$(date +%H%M%S)"
Expand All @@ -79,7 +83,7 @@ check() {
'--max-power-table=11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26'
)

if [[ "${DAEMON}" = 1 ]]; then
if [[ ${DAEMON} == 1 ]]; then
sudo "$(pwd)/$(ls output/posix/*linux*/bin/ot-daemon)" "${options[@]}" -I "${VALID_NETIF_NAME}" ${CORE_PTY} &
sleep 1
OT_CLI_CMD="$(pwd)/$(ls output/posix/*linux*/bin/ot-ctl)"
Expand All @@ -94,11 +98,11 @@ check() {
readonly INVALID_NETIF_NAME="wan0123456789123"
sudo ${OT_CLI_CMD} -I "${INVALID_NETIF_NAME}" -n || test $? = 2

if [[ "${DAEMON}" = 1 ]]; then
if [[ ${DAEMON} == 1 ]]; then
sudo ${OT_CLI_CMD} panid 0xface | grep 'Done' || die 'failed to set panid with ot-ctl'
fi

sudo expect <<EOF > "${OT_OUTPUT}" &
sudo expect <<EOF >"${OT_OUTPUT}" &
spawn ${OT_CLI_CMD}
send "panid 0xface\r\n"
expect "Done"
Expand Down Expand Up @@ -134,13 +138,13 @@ EOF
extaddr=$(awk '/extaddr/{getline; print}' $OT_OUTPUT | tr -d '\r\n')
echo "Extended address is: ${extaddr}"

if [[ "${DAEMON}" = 1 ]]; then
if [[ ${DAEMON} == 1 ]]; then
sudo killall -9 expect || true
sudo killall -9 ot-ctl || true
NETIF_INDEX=$(ip link show "${VALID_NETIF_NAME}" | cut -f 1 -d ":" | head -n 1)
sudo PATH="$(dirname ${OT_CLI_CMD}):${PATH}" \
python3 "$PWD/tests/scripts/misc/test_multicast_join.py" "${NETIF_INDEX}" \
|| die 'multicast group join failed'
python3 "$PWD/tests/scripts/misc/test_multicast_join.py" "${NETIF_INDEX}" \
|| die 'multicast group join failed'
fi

LEADER_ALOC=fdde:ad00:beef::ff:fe00:fc00
Expand All @@ -149,10 +153,11 @@ EOF
echo "CoAP response is: ${coap_response}"

# Verify CoAP response contains the extended address
[[ "${coap_response}" = *${extaddr}* ]] && echo 'Success' || die 'failed to get extended address'
[[ ${coap_response} == *${extaddr}* ]] && echo 'Success' || die 'failed to get extended address'
}

main() {
main()
{
case $1 in
build)
build
Expand Down
2 changes: 1 addition & 1 deletion script/check-scan-build
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ do_scan_build()
"-DMBEDTLS_DEBUG_C"
"-I$(pwd)/third_party/mbedtls"
"-I$(pwd)/third_party/mbedtls/repo/include"
"-DMBEDTLS_CONFIG_FILE=\\\"mbedtls-config.h\\\""
'-DMBEDTLS_CONFIG_FILE=\"mbedtls-config.h\"'
)

configure_options=(
Expand Down
28 changes: 14 additions & 14 deletions script/check-size
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ markdown_size()
local name
name=$(basename "$1")

read -r -a size_old <<< "$(size "$1" | awk '{text+=$1} {bss+=$2} {data+=$3} {total+=$4} END {printf "%d %d %d %d", text, bss, data, total}')"
read -r -a size_new <<< "$(size "$2" | awk '{text+=$1} {bss+=$2} {data+=$3} {total+=$4} END {printf "%d %d %d %d", text, bss, data, total}')"
read -r -a size_old <<<"$(size "$1" | awk '{text+=$1} {bss+=$2} {data+=$3} {total+=$4} END {printf "%d %d %d %d", text, bss, data, total}')"
read -r -a size_new <<<"$(size "$2" | awk '{text+=$1} {bss+=$2} {data+=$3} {total+=$4} END {printf "%d %d %d %d", text, bss, data, total}')"

local -a size_diff

for i in 0 1 2 3; do
size_diff[$i]="$((size_new["$i"] - size_old["$i"]))"
if [[ "${size_diff["$i"]}" != 0 ]]; then
if [[ ${size_diff["$i"]} != 0 ]]; then
size_diff["$i"]=$(printf '%+d' "${size_diff["$i"]}")
fi
done
Expand All @@ -86,11 +86,11 @@ markdown()
case "$1" in
init)
shift
markdown_init "$@" > "${OT_REPORT_FILE}"
markdown_init "$@" >"${OT_REPORT_FILE}"
;;
size)
shift
markdown_size "$@" >> "${OT_REPORT_FILE}"
markdown_size "$@" >>"${OT_REPORT_FILE}"
;;
post)
mdv "${OT_REPORT_FILE}"
Expand Down Expand Up @@ -152,11 +152,11 @@ size_nrf52840()
local reporter

# not on GitHub Actions or not a pull request event
if [[ ! "${GITHUB_ACTIONS+x}" || ! "${GITHUB_REF-}" =~ ^refs/pull/[0-9]+/merge ]]; then
if [[ ! ${GITHUB_ACTIONS+x} || ! ${GITHUB_REF-} =~ ^refs/pull/[0-9]+/merge ]]; then
reporter=markdown
else
reporter=./size-report
curl -s "${SIZE_REPORT_URL}/bash" > size-report
curl -s "${SIZE_REPORT_URL}/bash" >size-report
chmod a+x size-report
export OT_SHA_NEW OT_SHA_OLD
fi
Expand All @@ -167,16 +167,16 @@ size_nrf52840()
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/bin/ot-cli-mtd "${OT_TMP_DIR}"/b/output/nrf52840/bin/ot-cli-mtd
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/bin/ot-ncp-ftd "${OT_TMP_DIR}"/b/output/nrf52840/bin/ot-ncp-ftd
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/bin/ot-ncp-mtd "${OT_TMP_DIR}"/b/output/nrf52840/bin/ot-ncp-mtd
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/bin/ot-rcp "${OT_TMP_DIR}"/b/output/nrf52840/bin/ot-rcp
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/bin/ot-rcp "${OT_TMP_DIR}"/b/output/nrf52840/bin/ot-rcp

"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-cli-ftd.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-cli-ftd.a
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-cli-mtd.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-cli-mtd.a
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-ftd.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-ftd.a
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-mtd.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-mtd.a
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-ftd.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-ftd.a
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-mtd.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-mtd.a
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-ncp-ftd.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-ncp-ftd.a
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-ncp-mtd.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-ncp-mtd.a
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-rcp.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-rcp.a
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-radio.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-radio.a
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-rcp.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-rcp.a
"${reporter}" size "${OT_TMP_DIR}"/a/output/nrf52840/lib/libopenthread-radio.a "${OT_TMP_DIR}"/b/output/nrf52840/lib/libopenthread-radio.a

"${reporter}" post
}
Expand All @@ -186,9 +186,9 @@ main()
if [[ $# == 0 ]]; then
setup
size_nrf52840
elif [[ "$1" == setup ]]; then
elif [[ $1 == setup ]]; then
setup
elif [[ "$1" == nrf52840 ]]; then
elif [[ $1 == nrf52840 ]]; then
size_nrf52840
else
echo "USAGE: $0 [setup|nrf52840]"
Expand Down
16 changes: 8 additions & 8 deletions script/clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

CLANG_FORMAT_VERSION="clang-format version 6.0"

die() {
die()
{
echo " *** ERROR: $*"
exit 1
}
Expand All @@ -38,12 +39,12 @@ die() {
# expand_aliases shell option is set using shopt.
shopt -s expand_aliases

if command -v clang-format-6.0 > /dev/null; then
if command -v clang-format-6.0 >/dev/null; then
alias clang-format=clang-format-6.0
elif command -v clang-format > /dev/null; then
elif command -v clang-format >/dev/null; then
case "$(clang-format --version)" in
"$CLANG_FORMAT_VERSION"*)
;;
"$CLANG_FORMAT_VERSION"*) ;;

*)
die "$(clang-format --version); clang-format 6.0 required"
;;
Expand All @@ -56,8 +57,7 @@ clang-format "$@" || die

# ensure EOF newline
REPLACE=no
for arg
do
for arg; do
case $arg in
-i)
REPLACE=yes
Expand All @@ -68,7 +68,7 @@ done
file=$arg

[ $REPLACE != yes ] || {
[ -n "$(tail -c1 "$file")" ] && echo >> "$file"
[ -n "$(tail -c1 "$file")" ] && echo >>"$file"
}

exit 0
3 changes: 2 additions & 1 deletion script/clang-format-check
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@

set -euo pipefail

die() {
die()
{
echo " *** ERROR: $*"
exit 1
}
Expand Down
Loading

0 comments on commit cb9b353

Please sign in to comment.