Skip to content

Commit

Permalink
Update python requirement:
Browse files Browse the repository at this point in the history
- Support both python 3 and 2 for building and running mods
- Require python 3 for packaging
  • Loading branch information
pchote authored and abcdefg30 committed Nov 28, 2020
1 parent 6be7740 commit eb3826e
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 30 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 }')"
Expand Down
9 changes: 7 additions & 2 deletions fetch-engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions launch-dedicated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand All @@ -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"

Expand Down
16 changes: 7 additions & 9 deletions launch-game.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand All @@ -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"

Expand Down
10 changes: 5 additions & 5 deletions packaging/linux/buildpackage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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/"

Expand All @@ -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"
Expand Down Expand Up @@ -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}"
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}"
8 changes: 4 additions & 4 deletions packaging/macos/buildpackage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand All @@ -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/"

Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packaging/package-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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
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 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."
Expand Down
7 changes: 4 additions & 3 deletions packaging/windows/buildpackage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand All @@ -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/"

Expand All @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions utility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down

0 comments on commit eb3826e

Please sign in to comment.