77trap " sleep 1; echo" EXIT
88
99SCRIPT_DIR=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd)
10+ GODOT_DIR=$( realpath $SCRIPT_DIR /..) /godot
1011ANDROID_DIR=$( realpath $SCRIPT_DIR /../../android)
12+ BUILD_DIR=$( realpath $SCRIPT_DIR /..) /build
13+ CONFIG_DIR=$( realpath $SCRIPT_DIR /../config)
1114
1215PLUGIN_NODE_TYPE=" Share"
1316PLUGIN_NAME=" ${PLUGIN_NODE_TYPE} Plugin"
1417PLUGIN_VERSION=' '
1518PLUGIN_PACKAGE_NAME=$( $SCRIPT_DIR /get_gradle_property.sh pluginPackageName $ANDROID_DIR /config.gradle.kts)
1619ANDROID_DEPENDENCIES=$( $SCRIPT_DIR /get_android_dependencies.sh)
17- readarray -t IOS_FRAMEWORKS <<< " $($SCRIPT_DIR/get_config_property.sh -qas frameworks)"
18- readarray -t IOS_LINKER_FLAGS <<< " $($SCRIPT_DIR/get_config_property.sh -qas flags)"
20+ IOS_FRAMEWORKS=()
21+ while IFS= read -r line; do
22+ IOS_FRAMEWORKS+=(" $line " )
23+ done < <( $SCRIPT_DIR /get_config_property.sh -qas frameworks)
24+ IOS_LINKER_FLAGS=()
25+ while IFS= read -r line; do
26+ IOS_LINKER_FLAGS+=(" $line " )
27+ done < <( $SCRIPT_DIR /get_config_property.sh -qas flags)
1928SUPPORTED_GODOT_VERSIONS=(" 4.2" " 4.3" " 4.4" " 4.5" )
2029BUILD_TIMEOUT=40 # increase this value using -t option if device is not able to generate all headers before godot build is killed
2130
22- DEST_DIRECTORY=" ./bin/release"
23- FRAMEWORKDIR=" ./bin/framework"
24- LIB_DIRECTORY=" ./bin/lib"
25- CONFIG_DIRECTORY=" ./config"
31+ DEST_DIR=$BUILD_DIR /release
32+ FRAMEWORKDIR=$BUILD_DIR /framework
33+ LIB_DIR=$BUILD_DIR /lib
2634
2735do_clean=false
2836do_remove_pod_trunk=false
@@ -120,20 +128,26 @@ function display_error()
120128
121129function remove_godot_directory()
122130{
123- if [[ -d " godot " ]]
131+ if [[ -d " $GODOT_DIR " ]]
124132 then
125- display_status " removing 'godot ' directory..."
126- rm -rf " godot "
133+ display_status " removing '$GODOT_DIR ' directory..."
134+ rm -rf $GODOT_DIR
127135 else
128- display_warning " 'godot ' directory not found... "
136+ display_warning " '$GODOT_DIR ' directory not found! "
129137 fi
130138}
131139
132140
133141function clean_plugin_build()
134142{
135- display_status " cleaning existing build directories and generated files..."
136- rm -rf ./bin/*
143+ if [[ -d " $BUILD_DIR " ]]
144+ then
145+ display_status " removing '$BUILD_DIR ' directory..."
146+ rm -rf $BUILD_DIR
147+ else
148+ display_warning " '$BUILD_DIR ' directory not found!"
149+ fi
150+ display_status " cleaning generated files..."
137151 find . -name " *.d" -type f -delete
138152 find . -name " *.o" -type f -delete
139153}
@@ -158,25 +172,21 @@ function download_godot()
158172 exit 1
159173 fi
160174
161- if [[ -d " godot " ]]
175+ if [[ -d " $GODOT_DIR " ]]
162176 then
163- display_error " Error: godot directory already exists. Won't download."
177+ display_error " Error: $GODOT_DIR directory already exists. Won't download."
164178 exit 1
165179 fi
166180
167181 SELECTED_GODOT_VERSION=$1
168182 display_status " downloading godot version $SELECTED_GODOT_VERSION ..."
169183
170- godot_directory=" godot-${SELECTED_GODOT_VERSION} -stable"
171- godot_archive_file_name=" ${godot_directory} .tar.xz"
184+ $SCRIPT_DIR /fetch_git_repo.sh -t ${SELECTED_GODOT_VERSION} -stable https://github.com/godotengine/godot.git $GODOT_DIR
172185
173- curl -LO " https://github.com/godotengine/godot/releases/download/${SELECTED_GODOT_VERSION} -stable/${godot_archive_file_name} "
174- tar -xf " $godot_archive_file_name "
175-
176- mv " $godot_directory " godot
177- rm $godot_archive_file_name
178-
179- echo " $SELECTED_GODOT_VERSION " > godot/GODOT_VERSION
186+ if [[ -d " $GODOT_DIR " ]]
187+ then
188+ echo " $SELECTED_GODOT_VERSION " > $GODOT_DIR /GODOT_VERSION
189+ fi
180190}
181191
182192
@@ -198,13 +208,13 @@ function generate_godot_headers()
198208
199209function generate_static_library()
200210{
201- if [[ ! -f " ./godot /GODOT_VERSION" ]]
211+ if [[ ! -f " $GODOT_DIR /GODOT_VERSION" ]]
202212 then
203213 display_error " Error: godot wasn't downloaded properly. Can't generate static library."
204214 exit 1
205215 fi
206216
207- GODOT_VERSION=$( cat ./godot /GODOT_VERSION)
217+ GODOT_VERSION=$( cat $GODOT_DIR /GODOT_VERSION)
208218
209219 TARGET_TYPE=" $1 "
210220 lib_directory=" $2 "
@@ -232,45 +242,63 @@ function install_pods()
232242
233243function build_plugin()
234244{
235- if [[ ! -f " ./godot /GODOT_VERSION" ]]
245+ if [[ ! -f " $GODOT_DIR /GODOT_VERSION" ]]
236246 then
237247 display_error " Error: godot wasn't downloaded properly. Can't build plugin."
238248 exit 1
239249 fi
240250
241- GODOT_VERSION=$( cat ./godot /GODOT_VERSION)
251+ GODOT_VERSION=$( cat $GODOT_DIR /GODOT_VERSION)
242252
243253 # Clear target directories
244- rm -rf " $DEST_DIRECTORY "
245- rm -rf " $LIB_DIRECTORY "
254+ rm -rf " $DEST_DIR "
255+ rm -rf " $LIB_DIR "
246256
247257 # Create target directories
248- mkdir -p " $DEST_DIRECTORY "
249- mkdir -p " $LIB_DIRECTORY "
258+ mkdir -p " $DEST_DIR "
259+ mkdir -p " $LIB_DIR "
250260
251261 display_status " building plugin library with godot version $GODOT_VERSION ..."
252262
253263 # Compile library
254- generate_static_library release $LIB_DIRECTORY
255- generate_static_library release_debug $LIB_DIRECTORY
256- mv $LIB_DIRECTORY /$PLUGIN_NAME .release_debug.a $LIB_DIRECTORY /$PLUGIN_NAME .debug.a
264+ generate_static_library release $LIB_DIR
265+ generate_static_library release_debug $LIB_DIR
266+ mv $LIB_DIR /$PLUGIN_NAME .release_debug.a $LIB_DIR /$PLUGIN_NAME .debug.a
257267
258268 # Move library
259- cp $LIB_DIRECTORY /$PLUGIN_NAME .{release,debug}.a " $DEST_DIRECTORY "
269+ cp $LIB_DIR /$PLUGIN_NAME .{release,debug}.a " $DEST_DIR "
270+
271+ cp " $CONFIG_DIR " /* .gdip " $DEST_DIR "
272+ }
273+
274+
275+ function merge_string_array() {
276+ local arr=(" $@ " ) # Accept array as input
277+ local result=" "
278+ local first=true
279+
280+ for str in " ${arr[@]} " ; do
281+ if [ " $first " = true ]; then
282+ result=" $str "
283+ first=false
284+ else
285+ result=" $result , $str "
286+ fi
287+ done
260288
261- cp " $CONFIG_DIRECTORY " / * .gdip " $DEST_DIRECTORY "
289+ echo " $result "
262290}
263291
264292
265293function create_zip_archive()
266294{
267- if [[ ! -f " ./godot /GODOT_VERSION" ]]
295+ if [[ ! -f " $GODOT_DIR /GODOT_VERSION" ]]
268296 then
269297 display_error " Error: godot wasn't downloaded properly. Can't create zip archive."
270298 exit 1
271299 fi
272300
273- GODOT_VERSION=$( cat ./godot /GODOT_VERSION)
301+ GODOT_VERSION=$( cat $GODOT_DIR /GODOT_VERSION)
274302
275303 if [[ -z $PLUGIN_VERSION ]]
276304 then
@@ -281,13 +309,13 @@ function create_zip_archive()
281309
282310 file_name=" $PLUGIN_NAME -$godot_version_suffix .zip"
283311
284- if [[ -e " ./bin /release/$file_name " ]]
312+ if [[ -e " $BUILD_DIR /release/$file_name " ]]
285313 then
286314 display_warning " deleting existing $file_name file..."
287- rm ./bin /release/$file_name
315+ rm $BUILD_DIR /release/$file_name
288316 fi
289317
290- tmp_directory=$( realpath $SCRIPT_DIR /../bin/. tmp_zip)
318+ tmp_directory=$BUILD_DIR /. tmp_zip
291319 addon_directory=$( realpath $SCRIPT_DIR /../../addon)
292320
293321 if [[ -d " $tmp_directory " ]]
@@ -321,8 +349,8 @@ function create_zip_archive()
321349 s/@pluginNodeName@/$PLUGIN_NODE_TYPE /g;
322350 s/@pluginPackageName@/$PLUGIN_PACKAGE_NAME /g;
323351 s/@pluginDependencies@/$ANDROID_DEPENDENCIES /g;
324- s/@iosFrameworks@/$IOS_FRAMEWORKS /g;
325- s/@iosLinkerFlags@/$IOS_LINKER_FLAGS /g
352+ s/@iosFrameworks@/$( merge_string_array $ IOS_FRAMEWORKS) /g;
353+ s/@iosLinkerFlags@/$( merge_string_array $ IOS_LINKER_FLAGS) /g
326354 " " $file "
327355 done
328356 fi
@@ -331,10 +359,10 @@ function create_zip_archive()
331359 find $( realpath $SCRIPT_DIR /../Pods) -iname ' *.xcframework' -type d -exec cp -r {} $tmp_directory /ios/framework \;
332360
333361 mkdir -p $tmp_directory /ios/plugins
334- cp $CONFIG_DIRECTORY /* .gdip $tmp_directory /ios/plugins
335- cp $LIB_DIRECTORY /$PLUGIN_NAME .{release,debug}.a $tmp_directory /ios/plugins
362+ cp $CONFIG_DIR /* .gdip $tmp_directory /ios/plugins
363+ cp $LIB_DIR /$PLUGIN_NAME .{release,debug}.a $tmp_directory /ios/plugins
336364
337- mkdir -p $DEST_DIRECTORY
365+ mkdir -p $DEST_DIR
338366
339367 display_status " creating $file_name file..."
340368 cd $tmp_directory ; zip -yr ../release/$file_name ./* ; cd -
@@ -412,7 +440,7 @@ while getopts "aA:bcgG:hHipPt:z:" option; do
412440 esac
413441done
414442
415- if ! [[ " ${SUPPORTED_GODOT_VERSIONS[*]} " =~ [[:space:]]${GODOT_VERSION} [[:space:]] ]]
443+ if ! [[ " ${SUPPORTED_GODOT_VERSIONS[*]} " =~ [[:space:]]${GODOT_VERSION} [[:space:]] ]] && [[ " $do_build " == true ]]
416444then
417445 if [[ " $do_download_godot " == false ]]
418446 then
0 commit comments