From eb3826e9350b8d778431ed1b711a6bc1b07436a3 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 28 Nov 2020 11:23:52 +0000 Subject: [PATCH] Update python requirement: - Support both python 3 and 2 for building and running mods - Require python 3 for packaging --- Makefile | 10 +++++++++- fetch-engine.sh | 9 +++++++-- launch-dedicated.sh | 9 +++++++-- launch-game.sh | 16 +++++++--------- packaging/linux/buildpackage.sh | 10 +++++----- packaging/macos/buildpackage.sh | 8 ++++---- packaging/package-all.sh | 4 ++-- packaging/windows/buildpackage.sh | 7 ++++--- utility.sh | 10 ++++++++-- 9 files changed, 53 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index e7ba025..1d5e87e 100644 --- a/Makefile +++ b/Makefile @@ -23,10 +23,18 @@ .PHONY: utility stylecheck build clean engine version check check-scripts check-sdk-scripts check-packaging-scripts check-variables .DEFAULT_GOAL := all +PYTHON = $(shell command -v python3 2> /dev/null) +ifeq ($(PYTHON),) +PYTHON = $(shell command -v python 2> /dev/null) +endif +ifeq ($(PYTHON),) +$(error "The OpenRA mod template requires python.") +endif + VERSION = $(shell git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || echo git-`git rev-parse --short HEAD`) MOD_ID = $(shell cat user.config mod.config 2> /dev/null | awk -F= '/MOD_ID/ { print $$2; exit }') ENGINE_DIRECTORY = $(shell cat user.config mod.config 2> /dev/null | awk -F= '/ENGINE_DIRECTORY/ { print $$2; exit }') -MOD_SEARCH_PATHS = "$(shell python -c "import os; print(os.path.realpath('.'))")/mods,./mods" +MOD_SEARCH_PATHS = "$(shell $(PYTHON) -c "import os; print(os.path.realpath('.'))")/mods,./mods" WHITELISTED_OPENRA_ASSEMBLIES = "$(shell cat user.config mod.config 2> /dev/null | awk -F= '/WHITELISTED_OPENRA_ASSEMBLIES/ { print $$2; exit }')" WHITELISTED_THIRDPARTY_ASSEMBLIES = "$(shell cat user.config mod.config 2> /dev/null | awk -F= '/WHITELISTED_THIRDPARTY_ASSEMBLIES/ { print $$2; exit }')" diff --git a/fetch-engine.sh b/fetch-engine.sh index e49866b..93783b8 100755 --- a/fetch-engine.sh +++ b/fetch-engine.sh @@ -3,7 +3,12 @@ # This should not be called manually command -v curl >/dev/null 2>&1 || command -v wget > /dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires curl or wget."; exit 1; } -command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } +if command -v python3 >/dev/null 2>&1; then + PYTHON="python3" +else + command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } + PYTHON="python" +fi require_variables() { missing="" @@ -17,7 +22,7 @@ require_variables() { fi } -TEMPLATE_LAUNCHER=$(python -c "import os; print(os.path.realpath('$0'))") +TEMPLATE_LAUNCHER=$(${PYTHON} -c "import os; print(os.path.realpath('$0'))") TEMPLATE_ROOT=$(dirname "${TEMPLATE_LAUNCHER}") # shellcheck source=mod.config diff --git a/launch-dedicated.sh b/launch-dedicated.sh index 49152ce..fe2a65e 100755 --- a/launch-dedicated.sh +++ b/launch-dedicated.sh @@ -5,8 +5,13 @@ # Read the file to see which settings you can override set -e -command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } command -v mono >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires mono."; exit 1; } +if command -v python3 >/dev/null 2>&1; then + PYTHON="python3" +else + command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } + PYTHON="python" +fi require_variables() { missing="" @@ -20,7 +25,7 @@ require_variables() { fi } -TEMPLATE_LAUNCHER=$(python -c "import os; print(os.path.realpath('$0'))") +TEMPLATE_LAUNCHER=$(${PYTHON} -c "import os; print(os.path.realpath('$0'))") TEMPLATE_ROOT=$(dirname "${TEMPLATE_LAUNCHER}") MOD_SEARCH_PATHS="${TEMPLATE_ROOT}/mods,./mods" diff --git a/launch-game.sh b/launch-game.sh index a67f92d..e2de548 100755 --- a/launch-game.sh +++ b/launch-game.sh @@ -2,6 +2,12 @@ set -e command -v mono >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires mono."; exit 1; } +if command -v python3 >/dev/null 2>&1; then + PYTHON="python3" +else + command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } + PYTHON="python" +fi require_variables() { missing="" @@ -15,15 +21,7 @@ require_variables() { fi } -if command -v python3 >/dev/null 2>&1; then - TEMPLATE_LAUNCHER=$(python3 -c "import os; print(os.path.realpath('$0'))") -elif command -v python >/dev/null 2>&1; then - TEMPLATE_LAUNCHER=$(python -c "import os; print(os.path.realpath('$0'))") -else - echo >&2 "The OpenRA mod template requires python." - exit 1 -fi - +TEMPLATE_LAUNCHER=$(${PYTHON} -c "import os; print(os.path.realpath('$0'))") TEMPLATE_ROOT=$(dirname "${TEMPLATE_LAUNCHER}") MOD_SEARCH_PATHS="${TEMPLATE_ROOT}/mods,./mods" diff --git a/packaging/linux/buildpackage.sh b/packaging/linux/buildpackage.sh index d89a615..dcc0390 100755 --- a/packaging/linux/buildpackage.sh +++ b/packaging/linux/buildpackage.sh @@ -3,7 +3,7 @@ set -e command -v make >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires make."; exit 1; } -command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } +command -v python3 >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python 3."; exit 1; } command -v tar >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires tar."; exit 1; } command -v curl >/dev/null 2>&1 || command -v wget > /dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires curl or wget."; exit 1; } @@ -24,7 +24,7 @@ if [ $# -eq "0" ]; then exit 1 fi -PACKAGING_DIR=$(python -c "import os; print(os.path.dirname(os.path.realpath('$0')))") +PACKAGING_DIR=$(python3 -c "import os; print(os.path.dirname(os.path.realpath('$0')))") TEMPLATE_ROOT="${PACKAGING_DIR}/../../" ARTWORK_DIR="${PACKAGING_DIR}/../artwork/" @@ -42,9 +42,9 @@ require_variables "MOD_ID" "ENGINE_DIRECTORY" "PACKAGING_DISPLAY_NAME" "PACKAGIN TAG="$1" if [ $# -eq "1" ]; then - OUTPUTDIR=$(python -c "import os; print(os.path.realpath('.'))") + OUTPUTDIR=$(python3 -c "import os; print(os.path.realpath('.'))") else - OUTPUTDIR=$(python -c "import os; print(os.path.realpath('$2'))") + OUTPUTDIR=$(python3 -c "import os; print(os.path.realpath('$2'))") fi BUILTDIR="${PACKAGING_DIR}/${PACKAGING_INSTALLER_NAME}.appdir" @@ -169,4 +169,4 @@ install -m 0755 include/gtk-dialog.py "${BUILTDIR}/usr/bin/gtk-dialog.py" ARCH=x86_64 ./squashfs-root/AppRun "${BUILTDIR}" "${OUTPUTDIR}/${PACKAGING_INSTALLER_NAME}-${TAG}-x86_64.AppImage" # Clean up -rm -rf openra-mod.temp openra-mod-server.temp openra-mod-utility.temp temp.desktop temp.xml AppRun.temp appimagetool-x86_64.AppImage squashfs-root "${PACKAGING_APPIMAGE_DEPENDENCIES_TEMP_ARCHIVE_NAME}" "${BUILTDIR}" \ No newline at end of file +rm -rf openra-mod.temp openra-mod-server.temp openra-mod-utility.temp temp.desktop temp.xml AppRun.temp appimagetool-x86_64.AppImage squashfs-root "${PACKAGING_APPIMAGE_DEPENDENCIES_TEMP_ARCHIVE_NAME}" "${BUILTDIR}" diff --git a/packaging/macos/buildpackage.sh b/packaging/macos/buildpackage.sh index 84008f4..02fd8cd 100755 --- a/packaging/macos/buildpackage.sh +++ b/packaging/macos/buildpackage.sh @@ -20,7 +20,7 @@ if [[ "$OSTYPE" != "darwin"* ]]; then fi command -v make >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires make."; exit 1; } -command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } +command -v python3 >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } require_variables() { missing="" @@ -39,7 +39,7 @@ if [ $# -eq "0" ]; then exit 1 fi -PACKAGING_DIR=$(python -c "import os; print(os.path.dirname(os.path.realpath('$0')))") +PACKAGING_DIR=$(python3 -c "import os; print(os.path.dirname(os.path.realpath('$0')))") TEMPLATE_ROOT="${PACKAGING_DIR}/../../" ARTWORK_DIR="${PACKAGING_DIR}/../artwork/" @@ -70,9 +70,9 @@ fi TAG="$1" if [ $# -eq "1" ]; then - OUTPUTDIR=$(python -c "import os; print(os.path.realpath('.'))") + OUTPUTDIR=$(python3 -c "import os; print(os.path.realpath('.'))") else - OUTPUTDIR=$(python -c "import os; print(os.path.realpath('$2'))") + OUTPUTDIR=$(python3 -c "import os; print(os.path.realpath('$2'))") fi BUILTDIR="${PACKAGING_DIR}/build" diff --git a/packaging/package-all.sh b/packaging/package-all.sh index 32c3c39..d205866 100755 --- a/packaging/package-all.sh +++ b/packaging/package-all.sh @@ -13,7 +13,7 @@ else OUTPUTDIR=$2 fi -command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } +command -v python3 >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python 3."; exit 1; } command -v make >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires make."; exit 1; } if [[ "$OSTYPE" != "darwin"* ]]; then @@ -21,7 +21,7 @@ if [[ "$OSTYPE" != "darwin"* ]]; then command -v makensis >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires makensis."; exit 1; } fi -PACKAGING_DIR=$(python -c "import os; print(os.path.dirname(os.path.realpath('$0')))") +PACKAGING_DIR=$(python3 -c "import os; print(os.path.dirname(os.path.realpath('$0')))") if [[ "$OSTYPE" == "darwin"* ]]; then echo "Windows packaging requires a Linux host." diff --git a/packaging/windows/buildpackage.sh b/packaging/windows/buildpackage.sh index 09f5fc4..096ab58 100755 --- a/packaging/windows/buildpackage.sh +++ b/packaging/windows/buildpackage.sh @@ -2,6 +2,7 @@ set -e command -v makensis >/dev/null 2>&1 || { echo >&2 "Windows packaging requires makensis."; exit 1; } command -v convert >/dev/null 2>&1 || { echo >&2 "Windows packaging requires ImageMagick."; exit 1; } +command -v python3 >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } require_variables() { missing="" @@ -20,7 +21,7 @@ if [ $# -eq "0" ]; then exit 1 fi -PACKAGING_DIR=$(python -c "import os; print(os.path.dirname(os.path.realpath('$0')))") +PACKAGING_DIR=$(python3 -c "import os; print(os.path.dirname(os.path.realpath('$0')))") TEMPLATE_ROOT="${PACKAGING_DIR}/../../" ARTWORK_DIR="${PACKAGING_DIR}/../artwork/" @@ -38,9 +39,9 @@ require_variables "MOD_ID" "ENGINE_DIRECTORY" "PACKAGING_DISPLAY_NAME" "PACKAGIN TAG="$1" if [ $# -eq "1" ]; then - OUTPUTDIR=$(python -c "import os; print(os.path.realpath('.'))") + OUTPUTDIR=$(python3 -c "import os; print(os.path.realpath('.'))") else - OUTPUTDIR=$(python -c "import os; print(os.path.realpath('$2'))") + OUTPUTDIR=$(python3 -c "import os; print(os.path.realpath('$2'))") fi BUILTDIR="${PACKAGING_DIR}/build" diff --git a/utility.sh b/utility.sh index b649e7b..57251eb 100755 --- a/utility.sh +++ b/utility.sh @@ -5,9 +5,15 @@ set -e command -v make >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires make."; exit 1; } -command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } command -v mono >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires mono."; exit 1; } +if command -v python3 >/dev/null 2>&1; then + PYTHON="python3" +else + command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } + PYTHON="python" +fi + require_variables() { missing="" for i in "$@"; do @@ -20,7 +26,7 @@ require_variables() { fi } -TEMPLATE_LAUNCHER=$(python -c "import os; print(os.path.realpath('$0'))") +TEMPLATE_LAUNCHER=$(${PYTHON} -c "import os; print(os.path.realpath('$0'))") TEMPLATE_ROOT=$(dirname "${TEMPLATE_LAUNCHER}") MOD_SEARCH_PATHS="${TEMPLATE_ROOT}/mods,./mods"