| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "plugin_config_apple_embedded.h" |
| 34 |
|
| 35 |
#include "core/config/project_settings.h" |
| 36 |
#include "core/io/dir_access.h" |
| 37 |
#include "core/io/file_access.h" |
| 38 |
#include "core/io/image_loader.h" |
| 39 |
#include "core/io/marshalls.h" |
| 40 |
#include "core/io/resource_saver.h" |
| 41 |
#include "core/io/zip_io.h" |
| 42 |
#include "core/os/os.h" |
| 43 |
#include "core/templates/safe_refcount.h" |
| 44 |
#include "editor/export/editor_export_platform.h" |
| 45 |
#include "editor/settings/editor_settings.h" |
| 46 |
#include "main/splash.gen.h" |
| 47 |
#include "scene/resources/image_texture.h" |
| 48 |
|
| 49 |
#include <sys/stat.h> |
| 50 |
#include <functional> |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
const String ENV_APPLE_PLATFORM_PROFILE_UUID_DEBUG = "GODOT_APPLE_PLATFORM_PROVISIONING_PROFILE_UUID_DEBUG"; |
| 55 |
const String ENV_APPLE_PLATFORM_PROFILE_UUID_RELEASE = "GODOT_APPLE_PLATFORM_PROVISIONING_PROFILE_UUID_RELEASE"; |
| 56 |
const String ENV_APPLE_PLATFORM_PROFILE_SPECIFIER_DEBUG = "GODOT_APPLE_PLATFORM_PROFILE_SPECIFIER_DEBUG"; |
| 57 |
const String ENV_APPLE_PLATFORM_PROFILE_SPECIFIER_RELEASE = "GODOT_APPLE_PLATFORM_PROFILE_SPECIFIER_RELEASE"; |
| 58 |
|
| 59 |
static const String storyboard_image_scale_mode[] = { |
| 60 |
"center", |
| 61 |
"scaleAspectFit", |
| 62 |
"scaleAspectFill", |
| 63 |
"scaleToFill", |
| 64 |
}; |
| 65 |
|
| 66 |
class EditorExportPlatformAppleEmbedded : public EditorExportPlatform { |
| 67 |
GDCLASS(EditorExportPlatformAppleEmbedded, EditorExportPlatform); |
| 68 |
|
| 69 |
Ref<ImageTexture> logo; |
| 70 |
Ref<ImageTexture> run_icon; |
| 71 |
|
| 72 |
|
| 73 |
mutable SafeFlag plugins_changed; |
| 74 |
SafeFlag devices_changed; |
| 75 |
|
| 76 |
struct Device { |
| 77 |
String id; |
| 78 |
String name; |
| 79 |
bool wifi = false; |
| 80 |
bool use_ios_deploy = false; |
| 81 |
}; |
| 82 |
|
| 83 |
Vector<Device> devices; |
| 84 |
Mutex device_lock; |
| 85 |
|
| 86 |
Mutex plugins_lock; |
| 87 |
mutable Vector<PluginConfigAppleEmbedded> plugins; |
| 88 |
#ifdef MACOS_ENABLED |
| 89 |
Thread check_for_changes_thread; |
| 90 |
SafeFlag quit_request; |
| 91 |
SafeFlag has_runnable_preset; |
| 92 |
|
| 93 |
static bool _check_xcode_install(); |
| 94 |
static void _check_for_changes_poll_thread(void *ud); |
| 95 |
void _update_preset_status(); |
| 96 |
|
| 97 |
protected: |
| 98 |
void _start_remote_device_poller_thread() { |
| 99 |
check_for_changes_thread.start(_check_for_changes_poll_thread, this); |
| 100 |
} |
| 101 |
|
| 102 |
void _stop_remote_device_poller_thread() { |
| 103 |
quit_request.set(); |
| 104 |
if (check_for_changes_thread.is_started()) { |
| 105 |
check_for_changes_thread.wait_to_finish(); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
int _execute(const String &p_path, const List<String> &p_arguments, std::function<void(const String &)> p_on_data); |
| 110 |
|
| 111 |
private: |
| 112 |
#endif |
| 113 |
|
| 114 |
typedef Error (*FileHandler)(String p_file, void *p_userdata); |
| 115 |
static Error _walk_dir_recursive(Ref<DirAccess> &p_da, FileHandler p_handler, void *p_userdata); |
| 116 |
static Error _codesign(String p_file, void *p_userdata); |
| 117 |
|
| 118 |
struct ExportArchitecture { |
| 119 |
String name; |
| 120 |
bool is_default = false; |
| 121 |
|
| 122 |
ExportArchitecture() {} |
| 123 |
|
| 124 |
ExportArchitecture(String p_name, bool p_is_default) { |
| 125 |
name = p_name; |
| 126 |
is_default = p_is_default; |
| 127 |
} |
| 128 |
}; |
| 129 |
|
| 130 |
struct AppleEmbeddedExportAsset { |
| 131 |
String exported_path; |
| 132 |
bool is_framework = false; |
| 133 |
bool should_embed = false; |
| 134 |
}; |
| 135 |
|
| 136 |
String _get_additional_plist_content(); |
| 137 |
String _get_linker_flags(); |
| 138 |
String _get_cpp_code(); |
| 139 |
|
| 140 |
protected: |
| 141 |
struct AppleEmbeddedConfigData { |
| 142 |
String pkg_name; |
| 143 |
String binary_name; |
| 144 |
String plist_content; |
| 145 |
String architectures; |
| 146 |
String linker_flags; |
| 147 |
String cpp_code; |
| 148 |
String modules_buildfile; |
| 149 |
String modules_fileref; |
| 150 |
String modules_buildphase; |
| 151 |
String modules_buildgrp; |
| 152 |
Vector<String> capabilities; |
| 153 |
}; |
| 154 |
|
| 155 |
struct CodeSigningDetails { |
| 156 |
String debug_signing_identity; |
| 157 |
String release_signing_identity; |
| 158 |
String debug_provisioning_profile_uuid; |
| 159 |
String release_provisioning_profile_uuid; |
| 160 |
String debug_provisioning_profile_specifier; |
| 161 |
String release_provisioning_profile_specifier; |
| 162 |
bool debug_manual_signing = false; |
| 163 |
bool release_manual_signing = false; |
| 164 |
|
| 165 |
CodeSigningDetails(const Ref<EditorExportPreset> &p_preset) { |
| 166 |
debug_signing_identity = p_preset->get("application/code_sign_identity_debug").operator String().is_empty() ? "Apple Development" : p_preset->get("application/code_sign_identity_debug"); |
| 167 |
release_signing_identity = p_preset->get("application/code_sign_identity_release").operator String().is_empty() ? "Apple Distribution" : p_preset->get("application/code_sign_identity_release"); |
| 168 |
|
| 169 |
debug_provisioning_profile_uuid = p_preset->get_or_env("application/provisioning_profile_uuid_debug", ENV_APPLE_PLATFORM_PROFILE_UUID_DEBUG).operator String(); |
| 170 |
release_provisioning_profile_uuid = p_preset->get_or_env("application/provisioning_profile_uuid_release", ENV_APPLE_PLATFORM_PROFILE_UUID_DEBUG).operator String(); |
| 171 |
|
| 172 |
debug_manual_signing = !debug_provisioning_profile_uuid.is_empty() || (debug_signing_identity != "Apple Development" && debug_signing_identity != "Apple Distribution"); |
| 173 |
release_manual_signing = !release_provisioning_profile_uuid.is_empty() || (release_signing_identity != "Apple Development" && release_signing_identity != "Apple Distribution"); |
| 174 |
|
| 175 |
debug_provisioning_profile_specifier = p_preset->get_or_env("application/provisioning_profile_specifier_debug", ENV_APPLE_PLATFORM_PROFILE_SPECIFIER_DEBUG).operator String(); |
| 176 |
debug_manual_signing |= !debug_provisioning_profile_specifier.is_empty(); |
| 177 |
|
| 178 |
release_provisioning_profile_specifier = p_preset->get_or_env("application/provisioning_profile_specifier_release", ENV_APPLE_PLATFORM_PROFILE_SPECIFIER_RELEASE).operator String(); |
| 179 |
release_manual_signing |= !release_provisioning_profile_specifier.is_empty(); |
| 180 |
} |
| 181 |
}; |
| 182 |
|
| 183 |
struct IconInfo { |
| 184 |
const char *preset_key; |
| 185 |
const char *idiom; |
| 186 |
const char *export_name; |
| 187 |
const char *actual_size_side; |
| 188 |
const char *scale; |
| 189 |
const char *unscaled_size; |
| 190 |
bool force_opaque; |
| 191 |
}; |
| 192 |
|
| 193 |
private: |
| 194 |
void _fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const AppleEmbeddedConfigData &p_config, bool p_debug); |
| 195 |
|
| 196 |
Vector<ExportArchitecture> _get_supported_architectures() const; |
| 197 |
Vector<String> _get_preset_architectures(const Ref<EditorExportPreset> &p_preset) const; |
| 198 |
|
| 199 |
void _check_xcframework_content(const String &p_path, int &r_total_libs, int &r_static_libs, int &r_dylibs, int &r_frameworks) const; |
| 200 |
Error _convert_to_framework(const String &p_source, const String &p_destination, const String &p_id) const; |
| 201 |
|
| 202 |
void _add_assets_to_project(const String &p_out_dir, const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<AppleEmbeddedExportAsset> &p_additional_assets); |
| 203 |
Error _export_additional_assets(const Ref<EditorExportPreset> &p_preset, const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, bool p_should_embed, Vector<AppleEmbeddedExportAsset> &r_exported_assets); |
| 204 |
Error _copy_asset(const Ref<EditorExportPreset> &p_preset, const String &p_out_dir, const String &p_asset, const String *p_custom_file_name, bool p_is_framework, bool p_should_embed, Vector<AppleEmbeddedExportAsset> &r_exported_assets); |
| 205 |
Error _export_additional_assets(const Ref<EditorExportPreset> &p_preset, const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<AppleEmbeddedExportAsset> &r_exported_assets); |
| 206 |
Error _export_apple_embedded_plugins(const Ref<EditorExportPreset> &p_preset, AppleEmbeddedConfigData &p_config_data, const String &dest_dir, Vector<AppleEmbeddedExportAsset> &r_exported_assets, bool p_debug); |
| 207 |
|
| 208 |
Error _export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags, bool p_oneclick); |
| 209 |
|
| 210 |
bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const; |
| 211 |
|
| 212 |
protected: |
| 213 |
virtual String _process_config_file_line(const Ref<EditorExportPreset> &p_preset, const String &p_line, const AppleEmbeddedConfigData &p_config, bool p_debug, const CodeSigningDetails &p_code_signing); |
| 214 |
|
| 215 |
void _blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot); |
| 216 |
|
| 217 |
virtual Error _export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) { return OK; } |
| 218 |
virtual Error _export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) { return OK; } |
| 219 |
|
| 220 |
virtual String get_platform_name() const = 0; |
| 221 |
virtual String get_sdk_name() const = 0; |
| 222 |
virtual const Vector<String> get_device_types() const = 0; |
| 223 |
virtual String get_minimum_deployment_target() const = 0; |
| 224 |
|
| 225 |
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const override; |
| 226 |
virtual void get_export_options(List<ExportOption> *r_options) const override; |
| 227 |
virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const override; |
| 228 |
virtual String get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const override; |
| 229 |
|
| 230 |
virtual Vector<IconInfo> get_icon_infos() const = 0; |
| 231 |
|
| 232 |
void _notification(int p_what); |
| 233 |
|
| 234 |
virtual void get_platform_features(List<String> *r_features) const override { |
| 235 |
r_features->push_back("mobile"); |
| 236 |
r_features->push_back("apple_embedded"); |
| 237 |
} |
| 238 |
|
| 239 |
void _initialize(const char *p_platform_logo_svg, const char *p_run_icon_svg); |
| 240 |
|
| 241 |
public: |
| 242 |
virtual Ref<Texture2D> get_logo() const override { return logo; } |
| 243 |
virtual Ref<Texture2D> get_run_icon() const override { return run_icon; } |
| 244 |
|
| 245 |
virtual int get_options_count() const override; |
| 246 |
virtual String get_options_tooltip() const override; |
| 247 |
virtual Ref<Texture2D> get_option_icon(int p_index) const override; |
| 248 |
virtual String get_option_label(int p_index) const override; |
| 249 |
virtual String get_option_tooltip(int p_index) const override; |
| 250 |
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) override; |
| 251 |
|
| 252 |
virtual bool poll_export() override { |
| 253 |
bool dc = devices_changed.is_set(); |
| 254 |
if (dc) { |
| 255 |
|
| 256 |
devices_changed.clear(); |
| 257 |
} |
| 258 |
return dc; |
| 259 |
} |
| 260 |
|
| 261 |
virtual bool should_update_export_options() override { |
| 262 |
bool export_options_changed = plugins_changed.is_set(); |
| 263 |
if (export_options_changed) { |
| 264 |
|
| 265 |
plugins_changed.clear(); |
| 266 |
} |
| 267 |
return export_options_changed; |
| 268 |
} |
| 269 |
|
| 270 |
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override { |
| 271 |
List<String> list; |
| 272 |
if (p_preset.is_valid()) { |
| 273 |
bool project_only = p_preset->get("application/export_project_only"); |
| 274 |
if (project_only) { |
| 275 |
list.push_back("xcodeproj"); |
| 276 |
} else { |
| 277 |
list.push_back("ipa"); |
| 278 |
} |
| 279 |
} |
| 280 |
return list; |
| 281 |
} |
| 282 |
|
| 283 |
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags = 0) override; |
| 284 |
|
| 285 |
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const override; |
| 286 |
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override; |
| 287 |
|
| 288 |
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) override { |
| 289 |
} |
| 290 |
|
| 291 |
~EditorExportPlatformAppleEmbedded(); |
| 292 |
|
| 293 |
|
| 294 |
static Vector<String> list_plugin_config_files(const String &p_path, bool p_check_directories) { |
| 295 |
Vector<String> dir_files; |
| 296 |
Ref<DirAccess> da = DirAccess::open(p_path); |
| 297 |
if (da.is_valid()) { |
| 298 |
da->list_dir_begin(); |
| 299 |
while (true) { |
| 300 |
String file = da->get_next(); |
| 301 |
if (file.is_empty()) { |
| 302 |
break; |
| 303 |
} |
| 304 |
|
| 305 |
if (file == "." || file == "..") { |
| 306 |
continue; |
| 307 |
} |
| 308 |
|
| 309 |
if (da->current_is_hidden()) { |
| 310 |
continue; |
| 311 |
} |
| 312 |
|
| 313 |
if (da->current_is_dir()) { |
| 314 |
if (p_check_directories) { |
| 315 |
Vector<String> directory_files = list_plugin_config_files(p_path.path_join(file), false); |
| 316 |
for (int i = 0; i < directory_files.size(); ++i) { |
| 317 |
dir_files.push_back(file.path_join(directory_files[i])); |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
continue; |
| 322 |
} |
| 323 |
|
| 324 |
if (file.ends_with(PluginConfigAppleEmbedded::PLUGIN_CONFIG_EXT)) { |
| 325 |
dir_files.push_back(file); |
| 326 |
} |
| 327 |
} |
| 328 |
da->list_dir_end(); |
| 329 |
} |
| 330 |
|
| 331 |
return dir_files; |
| 332 |
} |
| 333 |
|
| 334 |
static Vector<PluginConfigAppleEmbedded> get_plugins(const String &p_platform_name) { |
| 335 |
Vector<PluginConfigAppleEmbedded> loaded_plugins; |
| 336 |
|
| 337 |
String plugins_dir = ProjectSettings::get_singleton()->get_resource_path().path_join(p_platform_name + "/plugins"); |
| 338 |
|
| 339 |
if (DirAccess::exists(plugins_dir)) { |
| 340 |
Vector<String> plugins_filenames = list_plugin_config_files(plugins_dir, true); |
| 341 |
|
| 342 |
if (!plugins_filenames.is_empty()) { |
| 343 |
Ref<ConfigFile> config_file; |
| 344 |
config_file.instantiate(); |
| 345 |
for (int i = 0; i < plugins_filenames.size(); i++) { |
| 346 |
PluginConfigAppleEmbedded config = PluginConfigAppleEmbedded::load_plugin_config(config_file, plugins_dir.path_join(plugins_filenames[i])); |
| 347 |
if (config.valid_config) { |
| 348 |
loaded_plugins.push_back(config); |
| 349 |
} else { |
| 350 |
print_error("Invalid plugin config file " + plugins_filenames[i]); |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
return loaded_plugins; |
| 357 |
} |
| 358 |
|
| 359 |
static Vector<PluginConfigAppleEmbedded> get_enabled_plugins(const String &p_platform_name, const Ref<EditorExportPreset> &p_presets) { |
| 360 |
Vector<PluginConfigAppleEmbedded> enabled_plugins; |
| 361 |
Vector<PluginConfigAppleEmbedded> all_plugins = get_plugins(p_platform_name); |
| 362 |
for (int i = 0; i < all_plugins.size(); i++) { |
| 363 |
PluginConfigAppleEmbedded plugin = all_plugins[i]; |
| 364 |
bool enabled = p_presets->get("plugins/" + plugin.name); |
| 365 |
if (enabled) { |
| 366 |
enabled_plugins.push_back(plugin); |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
return enabled_plugins; |
| 371 |
} |
| 372 |
}; |