Skip to content

Instantly share code, notes, and snippets.

@omardelarosa
Created January 2, 2021 22:23
Show Gist options
  • Save omardelarosa/c3e87deb07f96bc2001ba975ccb2b56d to your computer and use it in GitHub Desktop.
Save omardelarosa/c3e87deb07f96bc2001ba975ccb2b56d to your computer and use it in GitHub Desktop.
Automating GodotPython Builds for Mac OSX

This build script is an example of how to automate GodotPython builds by using custom build templates for Mac OSX builds. For more instructions on how to make custom build templates check out: https://godotforums.org/discussion/20550/how-to-create-export-templates

project:
   addons:
      pythonscript:
         osx-64:
            bin
            include
            lib
            licenses
            libpythonscript.dylib
  lib:    # <------- Location of all project Python files
     python_based_node.py # <--- A Node that is defined using Python
  python_based_scene.tscn # <---- A Scene that references the node above.
  misc_resource.tscn
  misc_resources_dir
  project.godot
# And a build_templates directory strcutured as:
build_templates:
   osx-64:
      osx_template.source.app
   windows:
      another_build_template
   linux:
      a_linux_build_template

At a high level, here is the flow:

  1. Copy a blank OS-specific build template (as described in Godot forums)
  2. Copy the files from addons/pythonscript/osx-64/ into the build template (in my case for MacOS this is build_template.app/Contents/Frameworks/ ) but this is basically the same location where GDNative DLL files ends up on their respective operating system.
  3. Copy the files from path/to/project/lib directory (i.e. all the python files from my project) are copied into the embedded python location in the bundle. In my case this begins in addons/pythonscript/osx-64/lib/python3.8/site-packages and then ends up in build_template.app/Contents/Frameworks/lib/python3.8/site-packages/lib
  4. Once all the python files have been copied, make a zip archive from the build template.
  5. Set the custom_template/release and custom_template/debug values in ProjectSettings to the absolute paths of your output build template zip file.
  6. Export your project and all the GodotPython files be in their correct location alongside the DLLs.
#!/bin/bash
# Source any environment variables you need
source /path/to/your/env.sh
OS_BUILD_NAME="osx-64"
PROJECT_ABSOLUTE_PATH="/path/to/your/project/"
BUILD_TEMPLATES_OS_ROOT_ABSOLUTE="/path/to/your/os_build_templates/$OS_BUILD_NAME"
BUILD_TEMPLATES_OS_ROOT="../build_templates/$OS_BUILD_NAME"
PYTHON_ADDONS_ROOT="./addons/pythonscript"
PROJECT_PYTHON_FILES_DIR_NAME="python"
OS_TARGET_TEMPLATE_FILE_NAME="osx_template.app"
OS_SOURCE_TEMPLATE_FILE_NAME="osx_template.original.app"
PYTHON_SCRIPT_OS_SPECIFIC_FILES="$PYTHON_ADDONS_ROOT/$OS_BUILD_NAME"
GODOT_BUILD_TEMPLATE_FILE="$BUILD_TEMPLATES_OS_ROOT/$OS_TARGET_TEMPLATE_FILE_NAME"
GODOT_BUILD_TEMPLATE_ORIGINAL_FILE="$BUILD_TEMPLATES_OS_ROOT/$OS_SOURCE_TEMPLATE_FILE_NAME"
# Made using Godot source code using these instructions:
# https://godotforums.org/discussion/20550/how-to-create-export-templates
#
echo "Building $OS_BUILD_NAME templates to $BUILD_TEMPLATES_OS_ROOT"
rm -rf "$GODOT_BUILD_TEMPLATE_FILE"
mkdir -p "$GODOT_BUILD_TEMPLATE_FILE"
# # Install your pip packages etc.
source $PYTHON_LIB_PATH/install.sh
# Create archives of target files
cd $PYTHON_SCRIPT_OS_SPECIFIC_FILES
zip -r "$BUILD_TEMPLATES_OS_ROOT_ABSOLUTE/addons_lib.zip" ./*
cd $PROJECT_ABSOLUTE_PATH/python
zip -r "$BUILD_TEMPLATES_OS_ROOT_ABSOLUTE/python_project_files.zip" ./*
cd $PROJECT_ABSOLUTE_PATH
cp -r "$GODOT_BUILD_TEMPLATE_ORIGINAL_FILE/" "$GODOT_BUILD_TEMPLATE_FILE/"
mkdir -p "$GODOT_BUILD_TEMPLATE_FILE/Contents/Frameworks/"
unzip "$BUILD_TEMPLATES_OS_ROOT/addons_lib.zip" -d "$GODOT_BUILD_TEMPLATE_FILE/Contents/Frameworks/"
cd $BUILD_TEMPLATES_OS_ROOT
zip -r "$BUILD_TEMPLATES_OS_ROOT_ABSOLUTE/$OS_BUILD_NAME.template.zip" "./$OS_TARGET_TEMPLATE_FILE_NAME/"
# Clean up temporary files
echo "cleaning up: $BUILD_TEMPLATES_OS_ROOT_ABSOLUTE/python_project_files.zip"
rm "$BUILD_TEMPLATES_OS_ROOT_ABSOLUTE/python_project_files.zip"
echo "cleaning up: $BUILD_TEMPLATES_OS_ROOT_ABSOLUTE/addons_lib.zip"
rm "$BUILD_TEMPLATES_OS_ROOT_ABSOLUTE/addons_lib.zip"
echo "cleaning up: $OS_TARGET_TEMPLATE_FILE_NAME"
rm -rf "$OS_TARGET_TEMPLATE_FILE_NAME/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment