From 9121d4b066dcdeeb60405b5f549855ab6252c2f8 Mon Sep 17 00:00:00 2001 From: Zachary Cutlip Date: Wed, 6 Nov 2019 15:40:44 -0800 Subject: [PATCH 1/5] add a function to get lldb's python exe --- install.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/install.sh b/install.sh index f345ba1..c20a3d9 100755 --- a/install.sh +++ b/install.sh @@ -131,6 +131,29 @@ function install_packages { install_yum } +function get_lldb_python_exe { + # Find the Python version used by LLDB + local lldb_pyver=$(${LLDB} -Q -x -b --one-line 'script import platform; print(".".join(platform.python_version_tuple()[:2]))'|tail -1) + local lldb_python=$(${LLDB} -Q -x -b --one-line 'script import sys; print(sys.executable)'|tail -1) + + lldb_python=$(${LLDB} -Q -x -b --one-line 'script import sys; print(sys.executable)'|tail -1) + local lldb_python_basename=$(basename "${lldb_python}") + if [ "python" = "$lldb_python_basename" ]; + then + lldb_python="${lldb_python/%$lldb_pyver/}${lldb_pyver}" + elif [ "lldb" = "$lldb_python_basename" ]; + then + # newer lldb versions report sys.path as /path/to/lldb instead of python + # sys.exec_path still appears to be the parent path of bin/python though + local lldb_python_exec_prefix=$(${LLDB} -Q -x -b --one-line 'script import sys; print(sys.exec_prefix)'|tail -1) + lldb_python="$lldb_python_exec_prefix/bin/python" + lldb_python="${lldb_python/%$lldb_pyver/}${lldb_pyver}" + fi + + echo "$lldb_python" + +} + if [ "${BACKEND_GDB}" -eq 1 ]; then # Find the Python version used by GDB GDB_PYVER=$(${GDB} -batch -q --nx -ex 'pi import platform; print(".".join(platform.python_version_tuple()[:2]))') From aa20166a79b9d953ff7bab748c764c76ee0f1467 Mon Sep 17 00:00:00 2001 From: Zachary Cutlip Date: Wed, 6 Nov 2019 15:42:05 -0800 Subject: [PATCH 2/5] refactor lldb backend setup: - call get_lldb_python_exe for more robust python-getting --- install.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/install.sh b/install.sh index c20a3d9..ae52f88 100755 --- a/install.sh +++ b/install.sh @@ -186,11 +186,8 @@ if [ "${BACKEND_GDB}" -eq 1 ]; then fi if [ "${BACKEND_LLDB}" -eq 1 ]; then - # Find the Python version used by LLDB - LLDB_PYVER=$(${LLDB} -Qxb --one-line 'script import platform; print(".".join(platform.python_version_tuple()[:2]))'|tail -1) - LLDB_PYTHON=$(${LLDB} -Qxb --one-line 'script import sys; print(sys.executable)'|tail -1) - LLDB_PYTHON="${LLDB_PYTHON/%$LLDB_PYVER/}${LLDB_PYVER}" + LLDB_PYTHON=$(get_lldb_python_exe) ${LLDB_PYTHON} -m pip install --user --upgrade six if [ -n "${VENV}" ]; then From d6b9c49cef06c04294689436682bfdcdf8153f62 Mon Sep 17 00:00:00 2001 From: Zachary Cutlip Date: Wed, 6 Nov 2019 15:42:52 -0800 Subject: [PATCH 3/5] llvm folks found it super important to break -Qxb command line args - call lldb with -Q -x -b --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index ae52f88..ac9cffd 100755 --- a/install.sh +++ b/install.sh @@ -197,9 +197,9 @@ if [ "${BACKEND_LLDB}" -eq 1 ]; then LLDB_PYTHON="${VENV}/bin/python" LLDB_SITE_PACKAGES=$(find "${VENV}" -name site-packages) elif [ -z "${USER_MODE}" ]; then - LLDB_SITE_PACKAGES=$(${LLDB} -Qxb --one-line 'script import site; print(site.getsitepackages()[0])'|tail -1) + LLDB_SITE_PACKAGES=$(${LLDB} -Q -x -b --one-line 'script import site; print(site.getsitepackages()[0])'|tail -1) else - LLDB_SITE_PACKAGES=$(${LLDB} -Qxb --one-line 'script import site; print(site.getusersitepackages())'|tail -1) + LLDB_SITE_PACKAGES=$(${LLDB} -Q -x -b --one-line 'script import site; print(site.getusersitepackages())'|tail -1) fi install_packages From 4fcdedfba46f9048812cff3ce64f254489688996 Mon Sep 17 00:00:00 2001 From: Zachary Cutlip Date: Wed, 6 Nov 2019 17:47:46 -0800 Subject: [PATCH 4/5] add a quit() function - more elegant terminating with optonal error message --- install.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/install.sh b/install.sh index ac9cffd..e9fca88 100755 --- a/install.sh +++ b/install.sh @@ -87,6 +87,15 @@ if [ "${BACKEND_LLDB}" -eq 1 ] && [ -z "${LLDB}" ]; then exit 1 fi +function quit { + if [ $# -gt 1 ]; + then + echo "$1" + shift + fi + exit $1 +} + set -ex function install_apt { From be11fbff93af2f4e100fbab05876f10285999297 Mon Sep 17 00:00:00 2001 From: Zachary Cutlip Date: Wed, 6 Nov 2019 17:49:02 -0800 Subject: [PATCH 5/5] ensure pip is installed and upgraded --- install.sh | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index e9fca88..175b206 100755 --- a/install.sh +++ b/install.sh @@ -34,6 +34,11 @@ YUM_DNF=$(command -v dnf) USER_MODE='--user' SUDO='' +#Old versions of pip default to pypi.python.org and fail to install anything +PYPI_URL="https://pypi.org/simple" +PIP_MIN_VER="10.0" +PIP_BOOTSTRAP_URL="https://bootstrap.pypa.io/get-pip.py" + [[ -z "${GDB}" ]] BACKEND_GDB=$? [[ -z "${LLDB}" ]] @@ -140,6 +145,36 @@ function install_packages { install_yum } +function curl_get_pip { + echo "Attempting to curl pip bootstrapt script from $PIP_BOOTSTRAP_URL" + curl "$PIP_BOOTSTRAP_URL" | ${SUDO} ${LLDB_PYTHON} - --upgrade "$USER_MODE" || return $? +} + +function ensure_pip { + # Check if pip is installed already + ${LLDB_PYTHON} -m pip --version >/dev/null 2>&1 + if [ $? -ne 0 ]; + then + # If not, attempt to install it using ensurepip + echo "Attempting to install pip using 'ensurepip'." + ${SUDO} ${LLDB_PYTHON} -m ensurepip $USER_MODE || return $? + fi + # Some really old pip installations default to the old pypi.python.org, which no longer works. + echo "Attempting to upgrade pip." + ${SUDO} ${LLDB_PYTHON} -m pip install "pip>=$PIP_MIN_VER" $USER_MODE -U --index-url "$PYPI_URL" + if [ $? != 0 ]; + then + # We may still fail here due to TLS incompatibility + # TLS 1.x got turned off 2018-04-11 + # https://status.python.org/incidents/hdx7w97m5hr8 + # Curl may be new enough to support TLS 1.2, so try to curl the pip installer from pypa.io + # It's able to download and install pip without TLS errors somehow + echo "Failed to upgrade pip." + echo "Attempting to fall back to installation via curl." + curl_get_pip || return $? + fi +} + function get_lldb_python_exe { # Find the Python version used by LLDB local lldb_pyver=$(${LLDB} -Q -x -b --one-line 'script import platform; print(".".join(platform.python_version_tuple()[:2]))'|tail -1) @@ -196,8 +231,9 @@ fi if [ "${BACKEND_LLDB}" -eq 1 ]; then - LLDB_PYTHON=$(get_lldb_python_exe) - ${LLDB_PYTHON} -m pip install --user --upgrade six + LLDB_PYTHON=$(get_lldb_python_exe) || quit "Failed to locate python interpreter." 1 + ensure_pip || quit "Failed to install pip." 1 + ${LLDB_PYTHON} -m pip install --user --upgrade six || quit "Failed to install or upgrade 'six' python package." 1 if [ -n "${VENV}" ]; then echo "Creating virtualenv..." @@ -206,18 +242,18 @@ if [ "${BACKEND_LLDB}" -eq 1 ]; then LLDB_PYTHON="${VENV}/bin/python" LLDB_SITE_PACKAGES=$(find "${VENV}" -name site-packages) elif [ -z "${USER_MODE}" ]; then - LLDB_SITE_PACKAGES=$(${LLDB} -Q -x -b --one-line 'script import site; print(site.getsitepackages()[0])'|tail -1) + LLDB_SITE_PACKAGES=$(${LLDB} -Q -x -b --one-line 'script import site; print(site.getsitepackages()[0])'|tail -1) || quit "Failed to locate site-packages." 1 else - LLDB_SITE_PACKAGES=$(${LLDB} -Q -x -b --one-line 'script import site; print(site.getusersitepackages())'|tail -1) + LLDB_SITE_PACKAGES=$(${LLDB} -Q -x -b --one-line 'script import site; print(site.getusersitepackages())'|tail -1) || quit "Failed to locate site-packages." 1 fi - install_packages + install_packages || quit "Failed to install packages." 1 if [ "$LLDB_SITE_PACKAGES" == "$GDB_SITE_PACKAGES" ]; then echo "Skipping installation for LLDB - same site-packages directory" else # Install Voltron and dependencies - ${SUDO} ${LLDB_PYTHON} -m pip install -U $USER_MODE $DEV_MODE . + ${SUDO} ${LLDB_PYTHON} -m pip install -U $USER_MODE $DEV_MODE . || quit "Failed to install voltron." 1 fi # Add Voltron to lldbinit