From 1c1036567ae491a6d9510a41bcd6fd1792acbab0 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Sat, 3 Feb 2024 19:48:21 +0200 Subject: [PATCH] [macOS] Generate min. Info.plist for frameworks if it's missing. Validate framework bundle ID characters. --- platform/ios/export/export_plugin.cpp | 10 +++- platform/macos/export/export_plugin.cpp | 63 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/platform/ios/export/export_plugin.cpp b/platform/ios/export/export_plugin.cpp index d35819c34dd..f518d7607b1 100644 --- a/platform/ios/export/export_plugin.cpp +++ b/platform/ios/export/export_plugin.cpp @@ -1007,6 +1007,12 @@ Error EditorExportPlatformIOS::_convert_to_framework(const String &p_source, con // Creating Info.plist { + String lib_clean_name = file_name; + for (int i = 0; i < lib_clean_name.length(); i++) { + if (!is_ascii_alphanumeric_char(lib_clean_name[i]) && lib_clean_name[i] != '.' && lib_clean_name[i] != '-') { + lib_clean_name[i] = '-'; + } + } String info_plist_format = "\n" "\n" "\n" @@ -1014,7 +1020,7 @@ Error EditorExportPlatformIOS::_convert_to_framework(const String &p_source, con " CFBundleShortVersionString\n" " 1.0\n" " CFBundleIdentifier\n" - " $id.framework.$name\n" + " $id.framework.$cl_name\n" " CFBundleName\n" " $name\n" " CFBundleExecutable\n" @@ -1032,7 +1038,7 @@ Error EditorExportPlatformIOS::_convert_to_framework(const String &p_source, con " \n" ""; - String info_plist = info_plist_format.replace("$id", p_id).replace("$name", file_name); + String info_plist = info_plist_format.replace("$id", p_id).replace("$name", file_name).replace("$cl_name", lib_clean_name); Ref f = FileAccess::open(p_destination.path_join("Info.plist"), FileAccess::WRITE); if (f.is_valid()) { diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp index 7ed78db6f89..e31af806c95 100644 --- a/platform/macos/export/export_plugin.cpp +++ b/platform/macos/export/export_plugin.cpp @@ -1116,10 +1116,73 @@ Error EditorExportPlatformMacOS::_copy_and_sign_files(Ref &dir_access add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Relative symlinks are not supported, exported \"%s\" might be broken!"), p_src_path.get_file())); #endif print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path); + + bool plist_misssing = false; + Ref plist; + plist.instantiate(); + plist->load_file(p_src_path.path_join("Resources").path_join("Info.plist")); + + Ref root_node = plist->get_root(); + if (root_node.is_null()) { + plist_misssing = true; + } else { + Dictionary root = root_node->get_value(); + if (!root.has("CFBundleExecutable") || !root.has("CFBundleIdentifier") || !root.has("CFBundlePackageType") || !root.has("CFBundleInfoDictionaryVersion") || !root.has("CFBundleName") || !root.has("CFBundleSupportedPlatforms")) { + plist_misssing = true; + } + } + err = dir_access->make_dir_recursive(p_in_app_path); if (err == OK) { err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true); } + if (err == OK && plist_misssing) { + add_message(EXPORT_MESSAGE_WARNING, TTR("Export"), vformat(TTR("\"%s\": Info.plist missing or invalid, new Info.plist generated."), p_src_path.get_file())); + // Generate Info.plist + String lib_name = p_src_path.get_basename().get_file(); + String lib_id = p_preset->get("application/bundle_identifier"); + String lib_clean_name = lib_name; + for (int i = 0; i < lib_clean_name.length(); i++) { + if (!is_ascii_alphanumeric_char(lib_clean_name[i]) && lib_clean_name[i] != '.' && lib_clean_name[i] != '-') { + lib_clean_name[i] = '-'; + } + } + + String info_plist_format = "\n" + "\n" + "\n" + " \n" + " CFBundleExecutable\n" + " $name\n" + " CFBundleIdentifier\n" + " $id.framework.$cl_name\n" + " CFBundleInfoDictionaryVersion\n" + " 6.0\n" + " CFBundleName\n" + " $name\n" + " CFBundlePackageType\n" + " FMWK\n" + " CFBundleShortVersionString\n" + " 1.0.0\n" + " CFBundleSupportedPlatforms\n" + " \n" + " MacOSX\n" + " \n" + " CFBundleVersion\n" + " 1.0.0\n" + " LSMinimumSystemVersion\n" + " 10.12\n" + " \n" + ""; + + String info_plist = info_plist_format.replace("$id", lib_id).replace("$name", lib_name).replace("$cl_name", lib_clean_name); + + err = dir_access->make_dir_recursive(p_in_app_path.path_join("Resources")); + Ref f = FileAccess::open(p_in_app_path.path_join("Resources").path_join("Info.plist"), FileAccess::WRITE); + if (f.is_valid()) { + f->store_string(info_plist); + } + } } else { print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path); err = dir_access->copy(p_src_path, p_in_app_path);