blob: 76738d9c0e05ce88113ba118a15214035baa35b8 [file] [log] [blame]
Gilles Peskine62cf2e82020-03-27 16:35:23 +01001#! /usr/bin/env bash
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +02003# all.sh (transitional wrapper)
Simon Butcher3ea7f522016-03-07 23:22:10 +00004#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine192c72f2017-12-21 15:59:21 +01007
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +02008# During the transition of CI associated with the repo split,
9# we want all.sh from the mbedtls repo to transparently run both
10# mbedtls and tf-psa-crypto components.
11# This is what this wrapper is about.
12# Once the transition is over, this wrapper can be removed,
13# and mbedtls-all.sh renamed again to all.sh.
14#
15# This wrapper is mostly for the CI's benefit. Developers probably want to
16# directly invoke one or two of the following commands:
17# - tests/scripts/mbedtls-all.sh ...
18# - (cd tf-psa-crypto && tests/scripts/all.sh ...)
Manuel Pégourié-Gonnard7b556952024-10-09 11:18:43 +020019
Manuel Pégourié-Gonnard8da0e9e2024-10-23 09:42:47 +020020# This script must be invoked from the project's root.
21
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +020022set -eu
Gilles Peskine8f073122018-11-27 15:58:47 +010023
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +020024# Get the list of components available on each side.
25COMP_MBEDTLS=$(tests/scripts/mbedtls-all.sh --list-all-components | sort)
26COMP_CRYPTO=$(cd tf-psa-crypto && tests/scripts/all.sh --list-all-components | sort)
27
28# Error out if any component is available on both sides
29COMMON=$(comm -12 <(echo "$COMP_MBEDTLS") <(echo "$COMP_CRYPTO") | tr '\n' ' ')
30if [ -n "$COMMON" ]; then
31 echo "The following components are duplicated: $COMMON" >&2
32 exit 2
33fi
34
35# all.sh complains when a component is requested explicitly but is not
36# available. However, here we actually run two instances of all.sh, so when
37# requesting one component epxlicitly, at least one instance is not going to
38# know about it. So, when invoking each side, remove the other side's
39# components from its command line. This is safe because we know from above
40# that no component is on both sides.
41
42# mbedtls args are global args without the crypto components
43COMP_CRYPTO=$(echo $COMP_CRYPTO | tr '\n' ' ')
44for arg in "$@"; do
45 case " $COMP_CRYPTO " in
46 *" $arg "*) ;;
47 *) mbedtls_args+=( $arg ) ;;
48 esac
49done
50
51# crypto args are global args without the mbedtls components
52COMP_MBEDTLS=$(echo $COMP_MBEDTLS | tr '\n' ' ')
53for arg in "$@"; do
54 case " $COMP_MBEDTLS " in
55 *" $arg "*) ;;
56 *) crypto_args+=( $arg ) ;;
57 esac
58done
59
60# Note: don't print debug info on what commands are being run, because we
61# don't want to pollute the output especially when --list-components is used.
62
63# call mbedtls's all.sh
64set +e
65tests/scripts/mbedtls-all.sh "${mbedtls_args[@]}"
66mbedtls_exit=$?
67set -e
68if [ $mbedtls_exit -ne 0 ]; then
69 echo "mbedtls-all.sh exited $mbedtls_exit" >&2
70fi
71
72# if it returned non-zero, should we keep going?
73if [ $mbedtls_exit -ne 0 ]; then
74 case " $@ " in
75 *" --keep-going "*) ;; # fall through and run tf-psa-crypto's all.sh
76 *) exit $mbedtls_exit;;
77 esac
78fi
79
80# call tf-psa-crypto's all.sh
81set +e
82(cd tf-psa-crypto && tests/scripts/all.sh "${crypto_args[@]}")
83crypto_exit=$?
84set -e
85if [ $crypto_exit -ne 0 ]; then
86 echo "tf-psa-crypto's all.sh exited $crypto_exit" >&2
87fi
88
89# return an appropriate exit code
90if [ $mbedtls_exit -ne 0 ]; then
91 echo "mbedtls-all.sh exited $mbedtls_exit" >&2
92 echo "Please scroll up for a summary of errors in mbedtls-all.sh" >&2
93 exit $mbedtls_exit
94else
95 exit $crypto_exit
96fi