mirror of
https://github.com/TangentFoxy/love-release.git
synced 2025-07-28 02:52:20 +00:00
Improves modules sourcing
A module should always begin with a test to `execute_module` to see if it should be executed. As modules are always sourced (even when embedded), a simple `return` will stop the subscript. Modules are executed in a subscript, so the global space will not be polluted, and will also be reset after the execution of the module. This commit also solves some bugs in Makefile and lua parser.
This commit is contained in:
6
Makefile
6
Makefile
@@ -11,7 +11,7 @@ SED_INSTALL_DIR=$(shell echo "$(INSTALL_DIR)" | sed -e 's/[\/&]/\\&/g')
|
||||
|
||||
love-release: clean
|
||||
mkdir -p $(BUILD_DIR)
|
||||
sed -e 's/INSTALL=false/INSTALL=true/' -e 's/SCRIPTS_DIR="scripts"/SCRIPTS_DIR="$(SED_INSTALL_DIR)\/scripts"/' love-release.sh > '$(BUILD_DIR)/love-release'
|
||||
sed -e 's/INSTALLED=false/INSTALLED=true/' -e 's/SCRIPTS_DIR="scripts"/SCRIPTS_DIR="$(SED_INSTALL_DIR)\/scripts"/' love-release.sh > '$(BUILD_DIR)/love-release'
|
||||
cp love-release.1 '$(BUILD_DIR)/love-release.1'
|
||||
gzip '$(BUILD_DIR)/love-release.1'
|
||||
|
||||
@@ -26,9 +26,9 @@ install:
|
||||
embedded: clean
|
||||
mkdir -p '$(BUILD_DIR)'
|
||||
sed 's/EMBEDDED=false/EMBEDDED=true/' love-release.sh > '$(BUILD_DIR)/love-release.sh'
|
||||
for file in scripts/*; do \
|
||||
for file in scripts/*.sh; do \
|
||||
module="$$(basename -s '.sh' "$$file")"; \
|
||||
content='if [[ $$(execute_module "'"$$module"'") == true ]]; then'$$'\n'"$$(cat $$file)"$$'\n''fi'$$'\n\n'; \
|
||||
content='(source <(cat <<\EndOfModule'$$'\n'"$$(cat $$file)"$$'\n''EndOfModule'$$'\n''))'$$'\n\n'; \
|
||||
echo "$$content" >> "$(BUILD_DIR)/tmp"; \
|
||||
done
|
||||
sed -i.bak -e '/include_scripts_here$$/r $(BUILD_DIR)/tmp' '$(BUILD_DIR)/love-release.sh';
|
||||
|
@@ -35,6 +35,7 @@ check_deps ()
|
||||
# Reset script variables
|
||||
reset_vars () {
|
||||
TITLE="$(basename $(pwd))"
|
||||
MODULE=
|
||||
RELEASE_DIR=releases
|
||||
CACHE_DIR=~/.cache/love-release
|
||||
}
|
||||
@@ -168,7 +169,7 @@ f()
|
||||
love.conf(t)
|
||||
|
||||
-- "love", "windows", "osx", "debian" or "android"
|
||||
os = "$OS"
|
||||
os = "$1"
|
||||
|
||||
fields = {
|
||||
"identity", "version", "game_version", "icon", "exclude",
|
||||
@@ -178,8 +179,8 @@ for _, f in ipairs(fields) do
|
||||
t[f] = t[f] or ""
|
||||
end
|
||||
|
||||
for i in ipairs(t.os) do
|
||||
t.os[os] = {}
|
||||
for _, v in ipairs(t.os) do
|
||||
t.os[v] = {}
|
||||
end
|
||||
|
||||
if not t.os or #t.os == 0 then t.os.love = {} end
|
||||
@@ -203,7 +204,7 @@ else
|
||||
print(os:upper()..'=false')
|
||||
end
|
||||
|
||||
if os == "windows" then
|
||||
if t.os.windows and os == "windows" then
|
||||
t.os.windows.x86 = t.os.windows.x86 and true or false
|
||||
t.os.windows.x64 = t.os.windows.x64 and true or false
|
||||
t.os.windows.installer = t.os.windows.installer and true or false
|
||||
@@ -231,6 +232,9 @@ dump_var () {
|
||||
echo "LOVE_DEF_VERSION=$LOVE_DEF_VERSION"
|
||||
echo "LOVE_WEB_VERSION=$LOVE_WEB_VERSION"
|
||||
echo
|
||||
echo "RELEASE_DIR=$RELEASE_DIR"
|
||||
echo "CACHE_DIR=$CACHE_DIR"
|
||||
echo
|
||||
echo "IDENTITY=$IDENTITY"
|
||||
echo "GAME_VERSION=$GAME_VERSION"
|
||||
echo "ICON=$ICON"
|
||||
@@ -244,30 +248,39 @@ dump_var () {
|
||||
|
||||
|
||||
# Modules functions
|
||||
|
||||
# Test if module should be executed
|
||||
## $1: Module name
|
||||
## return: true if module should be executed
|
||||
execute_module ()
|
||||
{
|
||||
reset_vars
|
||||
local module="$1"
|
||||
MODULE="$module"
|
||||
read_config "$module"
|
||||
module=${module^^}
|
||||
if [[ ${!module} == true && -z $DEFAULT_MODULE ]]; then
|
||||
if [[ ${module} == "LOVE" ]]; then
|
||||
DEFAULT_MODULE=true
|
||||
else
|
||||
DEFAULT_MODULE=false
|
||||
if [[ ${!module} == true ]]; then
|
||||
if [[ -z $DEFAULT_MODULE ]]; then
|
||||
if [[ ${module} == "LOVE" ]]; then
|
||||
DEFAULT_MODULE=true
|
||||
else
|
||||
DEFAULT_MODULE=false
|
||||
fi
|
||||
fi
|
||||
else
|
||||
reset_vars
|
||||
fi
|
||||
echo "${!module}"
|
||||
}
|
||||
|
||||
# Init module
|
||||
## $1: Pretty module name
|
||||
init_module ()
|
||||
{
|
||||
reset_vars
|
||||
MODULE="$1"
|
||||
mkdir -p "$RELEASE_DIR"
|
||||
mkdir -p "$CACHE_DIR"/"$LOVE_VERSION"
|
||||
echo "Generating $TITLE with Love $LOVE_VERSION for ${MODULE}..."
|
||||
mkdir -p "$CACHE_DIR"
|
||||
echo "Generating $TITLE with LÖVE $LOVE_VERSION for ${MODULE}..."
|
||||
}
|
||||
|
||||
# Create the LÖVE file
|
||||
@@ -283,14 +296,19 @@ create_love_file ()
|
||||
|
||||
# Exit module
|
||||
## $1: exit code.
|
||||
## 0 - success, other - failure
|
||||
## 0 - success
|
||||
## 1 - binary not found or downloaded
|
||||
## other - failure
|
||||
## $2: error message
|
||||
exit_module ()
|
||||
{
|
||||
if [[ -z $1 || "$1" == "0" ]]; then
|
||||
echo "Done !"
|
||||
elif [[ "$1" == "1" ]]; then
|
||||
>&2 echo -e "$2"
|
||||
>&2 echo "LÖVE $LOVE_VERSION could not be found or downloaded."
|
||||
else
|
||||
echo -e "$2"
|
||||
>&2 echo -e "$2"
|
||||
exit $1
|
||||
fi
|
||||
}
|
||||
@@ -321,17 +339,19 @@ if [[ $EMBEDDED == true ]]; then
|
||||
elif [[ $INSTALLED == true ]]; then
|
||||
SCRIPTS_DIR="scripts"
|
||||
for file in "$SCRIPTS_DIR"/*.sh; do
|
||||
MODULE="$(basename -s '.sh' "$file")"
|
||||
if [[ $(execute_module "$MODULE") == true ]]; then
|
||||
source "$file"
|
||||
fi
|
||||
(source "$file")
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ -z $DEFAULT_MODULE || $DEFAULT_MODULE == true ]]; then
|
||||
MODULE="love"
|
||||
init_module
|
||||
(
|
||||
reset_vars
|
||||
read_config "love"
|
||||
init_module "LÖVE"
|
||||
create_love_file 9
|
||||
exit_module
|
||||
)
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
|
@@ -1,4 +1,8 @@
|
||||
# Android debug package
|
||||
if [[ $(execute_module "android") == false ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
init_module "Android"
|
||||
|
||||
|
||||
|
@@ -1,4 +1,8 @@
|
||||
# Debian package
|
||||
if [[ $(execute_module "debian") == false ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
init_module "Debian"
|
||||
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
# Example
|
||||
return
|
||||
|
||||
# This example script should show you how to write a module for love-release.
|
||||
|
||||
|
@@ -1,4 +1,8 @@
|
||||
# Mac OS X
|
||||
if [[ $(execute_module "osx") == false ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
init_module "Mac OS X"
|
||||
|
||||
|
||||
|
@@ -1,4 +1,8 @@
|
||||
# Windows
|
||||
if [[ $(execute_module "windows") == false ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
init_module "Windows"
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user