@@ -903,7 +903,7 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres
903903 return OK;
904904}
905905
906- Error EditorExportPlatformMacOS::_code_sign (const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_warn) {
906+ Error EditorExportPlatformMacOS::_code_sign (const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_warn, bool p_set_id ) {
907907 int codesign_tool = p_preset->get (" codesign/codesign" );
908908 switch (codesign_tool) {
909909 case 1 : { // built-in ad-hoc
@@ -947,6 +947,12 @@ Error EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_pre
947947 args.push_back (" --code-signature-flags" );
948948 args.push_back (" runtime" );
949949
950+ if (p_set_id) {
951+ String app_id = p_preset->get (" application/bundle_identifier" );
952+ args.push_back (" --binary-identifier" );
953+ args.push_back (app_id);
954+ }
955+
950956 args.push_back (" -v" ); /* provide some more feedback */
951957
952958 args.push_back (p_path);
@@ -1006,6 +1012,12 @@ Error EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_pre
10061012 args.push_back (p_preset->get (" codesign/identity" ));
10071013 }
10081014
1015+ if (p_set_id) {
1016+ String app_id = p_preset->get (" application/bundle_identifier" );
1017+ args.push_back (" -i" );
1018+ args.push_back (app_id);
1019+ }
1020+
10091021 args.push_back (" -v" ); /* provide some more feedback */
10101022 args.push_back (" -f" );
10111023
@@ -1037,7 +1049,7 @@ Error EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_pre
10371049}
10381050
10391051Error EditorExportPlatformMacOS::_code_sign_directory (const Ref<EditorExportPreset> &p_preset, const String &p_path,
1040- const String &p_ent_path, bool p_should_error_on_non_code) {
1052+ const String &p_ent_path, const String &p_helper_ent_path, bool p_should_error_on_non_code) {
10411053 static Vector<String> extensions_to_sign;
10421054
10431055 if (extensions_to_sign.is_empty ()) {
@@ -1064,7 +1076,8 @@ Error EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPres
10641076 }
10651077
10661078 if (extensions_to_sign.find (current_file.get_extension ()) > -1 ) {
1067- Error code_sign_error{ _code_sign (p_preset, current_file_path, p_ent_path, false ) };
1079+ int ftype = MachO::get_filetype (current_file_path);
1080+ Error code_sign_error{ _code_sign (p_preset, current_file_path, (ftype == 2 || ftype == 5 ) ? p_helper_ent_path : p_ent_path, false , (ftype == 2 || ftype == 5 )) };
10681081 if (code_sign_error != OK) {
10691082 return code_sign_error;
10701083 }
@@ -1073,7 +1086,7 @@ Error EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPres
10731086 FileAccess::set_unix_permissions (current_file_path, 0755 );
10741087 }
10751088 } else if (dir_access->current_is_dir ()) {
1076- Error code_sign_error{ _code_sign_directory (p_preset, current_file_path, p_ent_path, p_should_error_on_non_code) };
1089+ Error code_sign_error{ _code_sign_directory (p_preset, current_file_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code) };
10771090 if (code_sign_error != OK) {
10781091 return code_sign_error;
10791092 }
@@ -1091,6 +1104,7 @@ Error EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPres
10911104Error EditorExportPlatformMacOS::_copy_and_sign_files (Ref<DirAccess> &dir_access, const String &p_src_path,
10921105 const String &p_in_app_path, bool p_sign_enabled,
10931106 const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,
1107+ const String &p_helper_ent_path,
10941108 bool p_should_error_on_non_code_sign) {
10951109 static Vector<String> extensions_to_sign;
10961110
@@ -1180,10 +1194,11 @@ Error EditorExportPlatformMacOS::_copy_and_sign_files(Ref<DirAccess> &dir_access
11801194 if (err == OK && p_sign_enabled) {
11811195 if (dir_access->dir_exists (p_src_path) && p_src_path.get_extension ().is_empty ()) {
11821196 // If it is a directory, find and sign all dynamic libraries.
1183- err = _code_sign_directory (p_preset, p_in_app_path, p_ent_path, p_should_error_on_non_code_sign);
1197+ err = _code_sign_directory (p_preset, p_in_app_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code_sign);
11841198 } else {
11851199 if (extensions_to_sign.find (p_in_app_path.get_extension ()) > -1 ) {
1186- err = _code_sign (p_preset, p_in_app_path, p_ent_path, false );
1200+ int ftype = MachO::get_filetype (p_in_app_path);
1201+ err = _code_sign (p_preset, p_in_app_path, (ftype == 2 || ftype == 5 ) ? p_helper_ent_path : p_ent_path, false , (ftype == 2 || ftype == 5 ));
11871202 }
11881203 if (dir_access->file_exists (p_in_app_path) && is_executable (p_in_app_path)) {
11891204 // chmod with 0755 if the file is executable.
@@ -1197,13 +1212,13 @@ Error EditorExportPlatformMacOS::_copy_and_sign_files(Ref<DirAccess> &dir_access
11971212Error EditorExportPlatformMacOS::_export_macos_plugins_for (Ref<EditorExportPlugin> p_editor_export_plugin,
11981213 const String &p_app_path_name, Ref<DirAccess> &dir_access,
11991214 bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,
1200- const String &p_ent_path) {
1215+ const String &p_ent_path, const String &p_helper_ent_path ) {
12011216 Error error{ OK };
12021217 const Vector<String> &macos_plugins{ p_editor_export_plugin->get_macos_plugin_files () };
12031218 for (int i = 0 ; i < macos_plugins.size (); ++i) {
12041219 String src_path{ ProjectSettings::get_singleton ()->globalize_path (macos_plugins[i]) };
12051220 String path_in_app{ p_app_path_name + " /Contents/PlugIns/" + src_path.get_file () };
1206- error = _copy_and_sign_files (dir_access, src_path, path_in_app, p_sign_enabled, p_preset, p_ent_path, false );
1221+ error = _copy_and_sign_files (dir_access, src_path, path_in_app, p_sign_enabled, p_preset, p_ent_path, p_helper_ent_path, false );
12071222 if (error != OK) {
12081223 break ;
12091224 }
@@ -1780,8 +1795,9 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
17801795 add_message (EXPORT_MESSAGE_ERROR, TTR (" Code Signing" ), TTR (" 'rcodesign' doesn't support signing applications with embedded dynamic libraries." ));
17811796 }
17821797
1798+ bool sandbox = p_preset->get (" codesign/entitlements/app_sandbox/enabled" );
17831799 String ent_path = p_preset->get (" codesign/entitlements/custom_file" );
1784- String hlp_ent_path = EditorPaths::get_singleton ()->get_cache_dir ().path_join (pkg_name + " _helper.entitlements" );
1800+ String hlp_ent_path = sandbox ? EditorPaths::get_singleton ()->get_cache_dir ().path_join (pkg_name + " _helper.entitlements" ) : ent_path ;
17851801 if (sign_enabled && (ent_path.is_empty ())) {
17861802 ent_path = EditorPaths::get_singleton ()->get_cache_dir ().path_join (pkg_name + " .entitlements" );
17871803
@@ -1933,7 +1949,7 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
19331949 err = ERR_CANT_CREATE;
19341950 }
19351951
1936- if ((err == OK) && helpers.size () > 0 ) {
1952+ if ((err == OK) && sandbox && ( helpers.size () > 0 || shared_objects. size () > 0 ) ) {
19371953 ent_f = FileAccess::open (hlp_ent_path, FileAccess::WRITE);
19381954 if (ent_f.is_valid ()) {
19391955 ent_f->store_line (" <?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" );
@@ -1959,7 +1975,7 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
19591975 String hlp_path = helpers[i];
19601976 err = da->copy (hlp_path, tmp_app_path_name + " /Contents/Helpers/" + hlp_path.get_file ());
19611977 if (err == OK && sign_enabled) {
1962- err = _code_sign (p_preset, tmp_app_path_name + " /Contents/Helpers/" + hlp_path.get_file (), hlp_ent_path, false );
1978+ err = _code_sign (p_preset, tmp_app_path_name + " /Contents/Helpers/" + hlp_path.get_file (), hlp_ent_path, false , true );
19631979 }
19641980 FileAccess::set_unix_permissions (tmp_app_path_name + " /Contents/Helpers/" + hlp_path.get_file (), 0755 );
19651981 }
@@ -1971,11 +1987,11 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
19711987 String src_path = ProjectSettings::get_singleton ()->globalize_path (shared_objects[i].path );
19721988 if (shared_objects[i].target .is_empty ()) {
19731989 String path_in_app = tmp_app_path_name + " /Contents/Frameworks/" + src_path.get_file ();
1974- err = _copy_and_sign_files (da, src_path, path_in_app, sign_enabled, p_preset, ent_path, true );
1990+ err = _copy_and_sign_files (da, src_path, path_in_app, sign_enabled, p_preset, ent_path, hlp_ent_path, true );
19751991 } else {
19761992 String path_in_app = tmp_app_path_name.path_join (shared_objects[i].target );
19771993 tmp_app_dir->make_dir_recursive (path_in_app);
1978- err = _copy_and_sign_files (da, src_path, path_in_app.path_join (src_path.get_file ()), sign_enabled, p_preset, ent_path, false );
1994+ err = _copy_and_sign_files (da, src_path, path_in_app.path_join (src_path.get_file ()), sign_enabled, p_preset, ent_path, hlp_ent_path, false );
19791995 }
19801996 if (err != OK) {
19811997 break ;
@@ -1984,7 +2000,7 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
19842000
19852001 Vector<Ref<EditorExportPlugin>> export_plugins{ EditorExport::get_singleton ()->get_export_plugins () };
19862002 for (int i = 0 ; i < export_plugins.size (); ++i) {
1987- err = _export_macos_plugins_for (export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path);
2003+ err = _export_macos_plugins_for (export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path, hlp_ent_path );
19882004 if (err != OK) {
19892005 break ;
19902006 }
@@ -2004,7 +2020,7 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
20042020 if (ep.step (TTR (" Code signing bundle" ), 2 )) {
20052021 return ERR_SKIP;
20062022 }
2007- err = _code_sign (p_preset, tmp_app_path_name, ent_path);
2023+ err = _code_sign (p_preset, tmp_app_path_name, ent_path, true , false );
20082024 }
20092025
20102026 String noto_path = p_path;
@@ -2022,7 +2038,7 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
20222038 if (ep.step (TTR (" Code signing DMG" ), 3 )) {
20232039 return ERR_SKIP;
20242040 }
2025- err = _code_sign (p_preset, p_path, ent_path, false );
2041+ err = _code_sign (p_preset, p_path, ent_path, false , false );
20262042 }
20272043 } else if (export_format == " pkg" ) {
20282044 // Create a Installer.
0 commit comments