[flang-commits] [flang] 38e745b - [flang] Make the `flang` wrapper script check the Bash version

Andrzej Warzynski via flang-commits flang-commits at lists.llvm.org
Wed Jan 12 01:42:26 PST 2022


Author: Andrzej Warzynski
Date: 2022-01-12T09:37:35Z
New Revision: 38e745b006238bee87476c3747b3e7229a8bc5c2

URL: https://github.com/llvm/llvm-project/commit/38e745b006238bee87476c3747b3e7229a8bc5c2
DIFF: https://github.com/llvm/llvm-project/commit/38e745b006238bee87476c3747b3e7229a8bc5c2.diff

LOG: [flang] Make the `flang` wrapper script check the Bash version

The `flang` wrapper script has been written in a relatively modern
version of Bash and it fails on systems with older versions. This patch
makes the script check the version of Bash being used to run it and
generates an error when unsupported version is used.

This was discussed in more detail in:
  * https://github.com/flang-compiler/f18-llvm-project/issues/1344.
Many thanks to Anthony Cabrera for the suggestion and for identifying
the oldest version of Bash that we can use here.

Differential Revision: https://reviews.llvm.org/D116608

Added: 
    

Modified: 
    flang/tools/f18/flang

Removed: 
    


################################################################################
diff  --git a/flang/tools/f18/flang b/flang/tools/f18/flang
index 6176a7501a973..1d657ae64c742 100755
--- a/flang/tools/f18/flang
+++ b/flang/tools/f18/flang
@@ -12,6 +12,9 @@
 #   * run Flang's compiler driver to unparse the input source files
 #   * use the external compiler (defined via FLANG_FC environment variable) to
 #   compile the unparsed source files
+#
+# Tested with Bash 4.4.23. This script will exit immediately if you use an
+# older version of Bash.
 #===------------------------------------------------------------------------===#
 set -euo pipefail
 
@@ -25,6 +28,27 @@ COMPILE_ONLY="False"
 PREPROCESS_ONLY="False"
 PRINT_VERSION="False"
 
+# === check_bash_version ======================================================
+#
+# Checks the Bash version that's used to run this script. Exits immediately if
+# it's lower than 4.4.23
+# =============================================================================
+check_bash_version() {
+  message="Error: Your Bash is too old. Please use Bash >= 4.4.23"
+  # Major version
+  [[ "${BASH_VERSINFO[0]:-0}" -lt 4 ]] && echo $message && exit 1
+
+  # Minor version
+  if [[ "${BASH_VERSINFO[0]}" == 4 ]]; then
+    [[ "${BASH_VERSINFO[1]:-0}" -lt 4 ]] && echo $message && exit 1
+  fi
+
+  # Patch version
+  if [[ "${BASH_VERSINFO[0]}" == 4 ]] && [[ "${BASH_VERSINFO[1]}" == 4 ]] ; then
+    [[ "${BASH_VERSINFO[2]:-0}" -lt 23 ]] && echo $message && exit 1
+  fi
+}
+
 # === parse_args ==============================================================
 #
 # Parse the input arguments passed to this script. Sets the global variables
@@ -324,6 +348,7 @@ get_relocatable_name() {
 # Main entry point for this script
 # =============================================================================
 main() {
+  check_bash_version
   parse_args "$@"
 
   if [[ $PRINT_VERSION == "True" ]]; then


        


More information about the flang-commits mailing list