Gilles Peskine | 62cf2e8 | 2020-03-27 16:35:23 +0100 | [diff] [blame] | 1 | #! /usr/bin/env bash |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 2 | |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame^] | 3 | # all.sh (transitional wrapper) |
Simon Butcher | 3ea7f52 | 2016-03-07 23:22:10 +0000 | [diff] [blame] | 4 | # |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 5 | # Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 6 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 7 | |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame^] | 8 | # 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é-Gonnard | 7b55695 | 2024-10-09 11:18:43 +0200 | [diff] [blame] | 19 | |
Manuel Pégourié-Gonnard | 8da0e9e | 2024-10-23 09:42:47 +0200 | [diff] [blame] | 20 | # This script must be invoked from the project's root. |
| 21 | |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame^] | 22 | set -eu |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 23 | |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame^] | 24 | # Get the list of components available on each side. |
| 25 | COMP_MBEDTLS=$(tests/scripts/mbedtls-all.sh --list-all-components | sort) |
| 26 | COMP_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 |
| 29 | COMMON=$(comm -12 <(echo "$COMP_MBEDTLS") <(echo "$COMP_CRYPTO") | tr '\n' ' ') |
| 30 | if [ -n "$COMMON" ]; then |
| 31 | echo "The following components are duplicated: $COMMON" >&2 |
| 32 | exit 2 |
| 33 | fi |
| 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 |
| 43 | COMP_CRYPTO=$(echo $COMP_CRYPTO | tr '\n' ' ') |
| 44 | for arg in "$@"; do |
| 45 | case " $COMP_CRYPTO " in |
| 46 | *" $arg "*) ;; |
| 47 | *) mbedtls_args+=( $arg ) ;; |
| 48 | esac |
| 49 | done |
| 50 | |
| 51 | # crypto args are global args without the mbedtls components |
| 52 | COMP_MBEDTLS=$(echo $COMP_MBEDTLS | tr '\n' ' ') |
| 53 | for arg in "$@"; do |
| 54 | case " $COMP_MBEDTLS " in |
| 55 | *" $arg "*) ;; |
| 56 | *) crypto_args+=( $arg ) ;; |
| 57 | esac |
| 58 | done |
| 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 |
| 64 | set +e |
| 65 | tests/scripts/mbedtls-all.sh "${mbedtls_args[@]}" |
| 66 | mbedtls_exit=$? |
| 67 | set -e |
| 68 | if [ $mbedtls_exit -ne 0 ]; then |
| 69 | echo "mbedtls-all.sh exited $mbedtls_exit" >&2 |
| 70 | fi |
| 71 | |
| 72 | # if it returned non-zero, should we keep going? |
| 73 | if [ $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 |
| 78 | fi |
| 79 | |
| 80 | # call tf-psa-crypto's all.sh |
| 81 | set +e |
| 82 | (cd tf-psa-crypto && tests/scripts/all.sh "${crypto_args[@]}") |
| 83 | crypto_exit=$? |
| 84 | set -e |
| 85 | if [ $crypto_exit -ne 0 ]; then |
| 86 | echo "tf-psa-crypto's all.sh exited $crypto_exit" >&2 |
| 87 | fi |
| 88 | |
| 89 | # return an appropriate exit code |
| 90 | if [ $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 |
| 94 | else |
| 95 | exit $crypto_exit |
| 96 | fi |