Add better Python detection for contrib scripts. (#3150)
authorMathias Preiner <mathias.preiner@gmail.com>
Fri, 2 Aug 2019 20:49:03 +0000 (13:49 -0700)
committerAndrew Reynolds <andrew.j.reynolds@gmail.com>
Fri, 2 Aug 2019 20:49:03 +0000 (15:49 -0500)
contrib/get-antlr-3.4
contrib/get-script-header.sh

index 6bfa18c4645fda5f5b0e9abbee51ca5550097405..a3dfb410d163b78b340a4a723df9b206b725606d 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 #
 source "$(dirname "$0")/get-script-header.sh"
 ANTLR_HOME_DIR=antlr-3.4
@@ -46,7 +46,7 @@ cd libantlr3c-3.4
 
 # Use an absolute path for the installation directory to avoid spurious libtool
 # warnings about the ANTLR library having moved
-PREFIX=$(python -c "import os; print(os.path.realpath('$(pwd)/../..'))")
+PREFIX=$($PYTHON -c "import os; print(os.path.realpath('$(pwd)/../..'))")
 
 # Make antlr3debughandlers.c empty to avoid unreferenced symbols
 rm -rf src/antlr3debughandlers.c && touch src/antlr3debughandlers.c
index de4a935875a008670ae9aa017199f99e797f8e66..e5b7080420e9279fb024a7015b3815cf2d83d87f 100644 (file)
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/usr/bin/env bash
 #
-set -e
+set -e -o pipefail
 
 cd "$(dirname "$0")/.."
 
@@ -24,3 +24,15 @@ function webget {
     exit 1
   fi
 }
+
+for cmd in python python2 python3; do
+  if [ -x "$(command -v $cmd)" ]; then
+    PYTHON="$cmd"
+    break
+  fi
+done
+
+if [ -z "$PYTHON" ]; then
+  echo "Error: Couldn't find python, python2, or python3." >&2
+  exit 1
+fi