33# © 2024-present https://github.com/cengiz-pz
44#
55
6- set -e
7- trap " sleep 1; echo" EXIT
6+ set -euo pipefail
87
98SCRIPT_DIR=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd)
109IOS_DIR=$( realpath $SCRIPT_DIR /..)
@@ -13,22 +12,25 @@ ANDROID_DIR=$ROOT_DIR/android
1312ADDON_DIR=$ROOT_DIR /addon
1413GODOT_DIR=$IOS_DIR /godot
1514IOS_CONFIG_DIR=$IOS_DIR /config
15+ COMMON_DIR=$ROOT_DIR /common
1616PODS_DIR=$IOS_DIR /Pods
1717BUILD_DIR=$IOS_DIR /build
1818DEST_DIR=$BUILD_DIR /release
1919FRAMEWORK_DIR=$BUILD_DIR /framework
2020LIB_DIR=$BUILD_DIR /lib
2121IOS_CONFIG_FILE=$IOS_CONFIG_DIR /config.properties
22- COMMON_CONFIG_FILE=$ROOT_DIR /common /config.properties
22+ COMMON_CONFIG_FILE=$COMMON_DIR /config.properties
2323
2424PLUGIN_NODE_NAME=$( $SCRIPT_DIR /get_config_property.sh -f $COMMON_CONFIG_FILE pluginNodeName)
2525PLUGIN_NAME=" ${PLUGIN_NODE_NAME} Plugin"
2626PLUGIN_VERSION=$( $SCRIPT_DIR /get_config_property.sh -f $COMMON_CONFIG_FILE pluginVersion)
2727IOS_INITIALIZATION_METHOD=$( $SCRIPT_DIR /get_config_property.sh -f $IOS_CONFIG_FILE initialization_method)
2828IOS_DEINITIALIZATION_METHOD=$( $SCRIPT_DIR /get_config_property.sh -f $IOS_CONFIG_FILE deinitialization_method)
29+ IOS_PLATFORM_VERSION=$( $SCRIPT_DIR /get_config_property.sh -f $IOS_CONFIG_FILE platform_version)
2930PLUGIN_PACKAGE_NAME=$( $SCRIPT_DIR /get_gradle_property.sh pluginPackageName $ANDROID_DIR /config.gradle.kts)
3031ANDROID_DEPENDENCIES=$( $SCRIPT_DIR /get_android_dependencies.sh)
3132GODOT_VERSION=$( $SCRIPT_DIR /get_config_property.sh -f $COMMON_CONFIG_FILE godotVersion)
33+ GODOT_RELEASE_TYPE=$( $SCRIPT_DIR /get_config_property.sh -f $COMMON_CONFIG_FILE releaseType)
3234IOS_FRAMEWORKS=()
3335while IFS= read -r line; do
3436 IOS_FRAMEWORKS+=(" $line " )
@@ -71,29 +73,28 @@ function display_help()
7173 echo_yellow " If plugin version is not set with the -z option, then Godot version will be used."
7274 echo
7375 $ROOT_DIR /script/echocolor.sh -Y " Syntax:"
74- echo_yellow " $0 [-a|A <godot version> |c|g|G <godot version> |h|H|i|p|P|t <timeout>|z <version> ]"
76+ echo_yellow " $0 [-a|A|c|g|G|h|H|i|p|P|t <timeout>|z]"
7577 echo
7678 $ROOT_DIR /script/echocolor.sh -Y " Options:"
7779 echo_yellow " a generate godot headers and build plugin"
78- echo_yellow " A download specified godot version, generate godot headers, and"
80+ echo_yellow " A download configured godot version, generate godot headers, and"
7981 echo_yellow " build plugin"
8082 echo_yellow " b build plugin"
8183 echo_yellow " c remove any existing plugin build"
8284 echo_yellow " g remove godot directory"
83- echo_yellow " G download the godot version specified in the option argument"
84- echo_yellow " into godot directory"
85+ echo_yellow " G download the configured godot version into godot directory"
8586 echo_yellow " h display usage information"
8687 echo_yellow " H generate godot headers"
8788 echo_yellow " i ignore if an unsupported godot version selected and continue"
8889 echo_yellow " p remove pods and pod repo trunk"
8990 echo_yellow " P install pods"
9091 echo_yellow " t change timeout value for godot build"
91- echo_yellow " z create zip archive with given version added to the file name"
92+ echo_yellow " z create zip archive, include configured version in the file name"
9293 echo
9394 $ROOT_DIR /script/echocolor.sh -Y " Examples:"
9495 echo_yellow " * clean existing build, remove godot, and rebuild all"
95- echo_yellow " $> $0 -cgA 4.2 "
96- echo_yellow " $> $0 -cgpG 4.2 -HPbz 1.0 "
96+ echo_yellow " $> $0 -cgA"
97+ echo_yellow " $> $0 -cgpGHPbz "
9798 echo
9899 echo_yellow " * clean existing build, remove pods and pod repo trunk, and rebuild plugin"
99100 echo_yellow " $> $0 -cpPb"
@@ -102,9 +103,9 @@ function display_help()
102103 echo_yellow " $> $0 -ca"
103104 echo
104105 echo_yellow " * clean existing build and rebuild plugin with custom plugin version"
105- echo_yellow " $> $0 -cHbz 1.0 "
106+ echo_yellow " $> $0 -cHbz"
106107 echo
107- echo_yellow " * clean existing build and rebuild plugin with custom build timeout"
108+ echo_yellow " * clean existing build and rebuild plugin with custom build-header timeout"
108109 echo_yellow " $> $0 -cHbt 15"
109110 echo
110111}
@@ -191,20 +192,56 @@ function remove_pods()
191192
192193function download_godot()
193194{
194- if [[ -d " $GODOT_DIR " ]]
195- then
196- display_error " Error: $GODOT_DIR directory already exists. Won't download."
197- exit 1
198- fi
199-
200- display_status " downloading godot version $GODOT_VERSION ..."
201-
202- $SCRIPT_DIR /fetch_git_repo.sh -t $GODOT_VERSION -stable https://github.com/godotengine/godot.git $GODOT_DIR
203-
204- if [[ -d " $GODOT_DIR " ]]
205- then
206- echo " $GODOT_VERSION " > $GODOT_DIR /GODOT_VERSION
207- fi
195+ if [[ -d " $GODOT_DIR " ]]; then
196+ display_error " Error: $GODOT_DIR directory already exists. Remove it first or use a different directory."
197+ exit 1
198+ fi
199+
200+ local filename=" godot-${GODOT_VERSION} -${GODOT_RELEASE_TYPE} .tar.xz"
201+ local release_url=" https://github.com/godotengine/godot-builds/releases/download/${GODOT_VERSION} -${GODOT_RELEASE_TYPE} /${filename} "
202+ local archive_path=" ${GODOT_DIR} .tar.xz"
203+ local temp_extract_dir=$( mktemp -d)
204+
205+ display_status " Downloading Godot ${GODOT_VERSION} -${GODOT_RELEASE_TYPE} (official pre-built binary)..."
206+ echo_blue " URL: $release_url "
207+
208+ # Check required tools
209+ if ! command -v curl > /dev/null 2>&1 ; then
210+ display_error " Error: curl is required to download the archive."
211+ exit 1
212+ fi
213+ if ! command -v tar > /dev/null 2>&1 ; then
214+ display_error " Error: tar is required to extract the archive."
215+ exit 1
216+ fi
217+
218+ # Download the .tar.xz archive
219+ if ! curl -L --fail --progress-bar -o " $archive_path " " $release_url " ; then
220+ rm -f " $archive_path "
221+ display_error " Failed to download Godot binary from:\n $release_url \nPlease verify that GODOT_VERSION (${GODOT_VERSION} ) and GODOT_RELEASE_TYPE (${GODOT_RELEASE_TYPE} ) are correct."
222+ exit 1
223+ fi
224+
225+ display_status " Extracting $filename ..."
226+ if ! tar -xaf " $archive_path " -C " $temp_extract_dir " --strip-components=1; then
227+ rm -f " $archive_path "
228+ rm -rf " $temp_extract_dir "
229+ display_error " Failed to extract the .tar.xz archive."
230+ exit 1
231+ fi
232+
233+ # Move extracted contents to final destination
234+ mkdir -p " $GODOT_DIR "
235+ mv " $temp_extract_dir " /* " $GODOT_DIR " /
236+
237+ # Cleanup
238+ rm -f " $archive_path "
239+ rm -rf " $temp_extract_dir "
240+
241+ # Write version marker for the rest of the build system
242+ echo " $GODOT_VERSION " > " $GODOT_DIR /GODOT_VERSION"
243+
244+ echo_green " Godot ${GODOT_VERSION} -${GODOT_RELEASE_TYPE} successfully downloaded and extracted to $GODOT_DIR "
208245}
209246
210247
@@ -233,6 +270,18 @@ function install_pods()
233270
234271function build_plugin()
235272{
273+ if [[ ! -d " $PODS_DIR " ]]
274+ then
275+ display_error " Error: Pods directory does not exist. Run 'pod install' first."
276+ exit 1
277+ fi
278+
279+ if [[ ! -d " $GODOT_DIR " ]]
280+ then
281+ display_error " Error: $GODOT_DIR directory does not exist. Can't build plugin."
282+ exit 1
283+ fi
284+
236285 if [[ ! -f " $GODOT_DIR /GODOT_VERSION" ]]
237286 then
238287 display_error " Error: godot wasn't downloaded properly. Can't build plugin."
@@ -304,7 +353,8 @@ function build_plugin()
304353}
305354
306355
307- function merge_string_array() {
356+ function merge_string_array()
357+ {
308358 local arr=(" $@ " ) # Accept array as input
309359 printf " %s" " ${arr[0]} "
310360 for (( i= 1 ; i< ${# arr[@]} ; i++ )) ; do
@@ -313,19 +363,15 @@ function merge_string_array() {
313363}
314364
315365
316- function replace_extra_properties() {
366+ function replace_extra_properties()
367+ {
317368 local file_path=" $1 "
318- local -a prop_array=(" ${@: 2} " )
319-
320- # Check if file exists and is readable
321- if [[ ! -f " $file_path " || ! -r " $file_path " ]]; then
322- display_error " Error: File '$file_path ' does not exist or is not readable"
323- exit 1
324- fi
369+ shift
370+ local prop_array=(" $@ " )
325371
326- # Check if file is empty
372+ # Check if file exists and is not empty
327373 if [[ ! -s " $file_path " ]]; then
328- echo_blue " Debug : File is empty, no replacements possible "
374+ display_error " Error : File ' $file_path ' does not exist or is empty, skipping replacements"
329375 return 0
330376 fi
331377
@@ -392,10 +438,10 @@ function create_zip_archive()
392438{
393439 local zip_file_name=" $PLUGIN_NAME -iOS-v$PLUGIN_VERSION .zip"
394440
395- if [[ -e " $BUILD_DIR /release /$zip_file_name " ]]
441+ if [[ -e " $DEST_DIR /$zip_file_name " ]]
396442 then
397443 display_warning " deleting existing $zip_file_name file..."
398- rm $BUILD_DIR /release /$zip_file_name
444+ rm $DEST_DIR /$zip_file_name
399445 fi
400446
401447 local tmp_directory=$( mktemp -d)
@@ -430,6 +476,7 @@ function create_zip_archive()
430476 ESCAPED_ANDROID_DEPENDENCIES=$( printf ' %s' " $ANDROID_DEPENDENCIES " | sed ' s/[\/&]/\\&/g' )
431477 ESCAPED_IOS_INITIALIZATION_METHOD=$( printf ' %s' " $IOS_INITIALIZATION_METHOD " | sed ' s/[\/&]/\\&/g' )
432478 ESCAPED_IOS_DEINITIALIZATION_METHOD=$( printf ' %s' " $IOS_DEINITIALIZATION_METHOD " | sed ' s/[\/&]/\\&/g' )
479+ ESCAPED_IOS_PLATFORM_VERSION=$( printf ' %s' " $IOS_PLATFORM_VERSION " | sed ' s/[\/&]/\\&/g' )
433480 ESCAPED_IOS_FRAMEWORKS=$( merge_string_array " ${IOS_FRAMEWORKS[@]} " | sed ' s/[\/&]/\\&/g' )
434481 ESCAPED_IOS_EMBEDDED_FRAMEWORKS=$( merge_string_array " ${IOS_EMBEDDED_FRAMEWORKS[@]} " | sed ' s/[\/&]/\\&/g' )
435482 ESCAPED_IOS_LINKER_FLAGS=$( merge_string_array " ${IOS_LINKER_FLAGS[@]} " | sed ' s/[\/&]/\\&/g' )
@@ -442,12 +489,15 @@ function create_zip_archive()
442489 s|@androidDependencies@|$ESCAPED_ANDROID_DEPENDENCIES |g;
443490 s|@iosInitializationMethod@|$ESCAPED_IOS_INITIALIZATION_METHOD |g;
444491 s|@iosDeinitializationMethod@|$ESCAPED_IOS_DEINITIALIZATION_METHOD |g;
492+ s|@iosPlatformVersion@|$ESCAPED_IOS_PLATFORM_VERSION |g;
445493 s|@iosFrameworks@|$ESCAPED_IOS_FRAMEWORKS |g;
446494 s|@iosEmbeddedFrameworks@|$ESCAPED_IOS_EMBEDDED_FRAMEWORKS |g;
447495 s|@iosLinkerFlags@|$ESCAPED_IOS_LINKER_FLAGS |g
448496 " " $file "
449497
450- replace_extra_properties $file ${EXTRA_PROPERTIES[@]}
498+ if [[ ${# EXTRA_PROPERTIES[@]} -gt 0 ]]; then
499+ replace_extra_properties " $file " " ${EXTRA_PROPERTIES[@]} "
500+ fi
451501 done
452502 else
453503 display_error " Error: '$ADDON_DIR ' not found."
@@ -468,7 +518,7 @@ function create_zip_archive()
468518}
469519
470520
471- while getopts " aAbcgG:hHipPt :z" option; do
521+ while getopts " aAbcgGhHipPt :z" option; do
472522 case $option in
473523 h)
474524 display_help
0 commit comments