Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/macos/export/export_plugin.cpp
11353 views
1
/**************************************************************************/
2
/* export_plugin.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "export_plugin.h"
32
33
#include "logo_svg.gen.h"
34
#include "run_icon_svg.gen.h"
35
36
#include "core/io/image_loader.h"
37
#include "core/io/plist.h"
38
#include "core/string/translation.h"
39
#include "drivers/png/png_driver_common.h"
40
#include "editor/editor_node.h"
41
#include "editor/editor_string_names.h"
42
#include "editor/export/codesign.h"
43
#include "editor/export/lipo.h"
44
#include "editor/export/macho.h"
45
#include "editor/file_system/editor_paths.h"
46
#include "editor/import/resource_importer_texture_settings.h"
47
#include "editor/themes/editor_scale.h"
48
#include "scene/resources/image_texture.h"
49
50
#include "modules/svg/image_loader_svg.h"
51
52
void EditorExportPlatformMacOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
53
r_features->push_back(p_preset->get("binary_format/architecture"));
54
String architecture = p_preset->get("binary_format/architecture");
55
56
if (architecture == "universal" || architecture == "x86_64") {
57
r_features->push_back("s3tc");
58
r_features->push_back("bptc");
59
} else if (architecture == "arm64") {
60
r_features->push_back("etc2");
61
r_features->push_back("astc");
62
} else {
63
ERR_PRINT("Invalid architecture");
64
}
65
66
if (p_preset->get("shader_baker/enabled")) {
67
r_features->push_back("shader_baker");
68
}
69
70
if (architecture == "universal") {
71
r_features->push_back("x86_64");
72
r_features->push_back("arm64");
73
}
74
}
75
76
String EditorExportPlatformMacOS::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const {
77
if (p_preset) {
78
int dist_type = p_preset->get("export/distribution_type");
79
bool ad_hoc = false;
80
int codesign_tool = p_preset->get("codesign/codesign");
81
int notary_tool = p_preset->get("notarization/notarization");
82
switch (codesign_tool) {
83
case 1: { // built-in ad-hoc
84
ad_hoc = true;
85
} break;
86
case 2: { // "rcodesign"
87
ad_hoc = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty() || p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty();
88
} break;
89
#ifdef MACOS_ENABLED
90
case 3: { // "codesign"
91
ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
92
} break;
93
#endif
94
default: {
95
};
96
}
97
98
if (p_name == "application/bundle_identifier") {
99
String identifier = p_preset->get("application/bundle_identifier");
100
String pn_err;
101
if (!is_package_name_valid(identifier, &pn_err)) {
102
return TTR("Invalid bundle identifier:") + " " + pn_err;
103
}
104
}
105
106
if (p_name == "shader_baker/enabled" && bool(p_preset->get("shader_baker/enabled"))) {
107
String export_renderer = GLOBAL_GET("rendering/renderer/rendering_method");
108
if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
109
return TTR("\"Shader Baker\" is not supported when using the Compatibility renderer.");
110
} else if (OS::get_singleton()->get_current_rendering_method() != export_renderer) {
111
return vformat(TTR("The editor is currently using a different renderer than what the target platform will use. \"Shader Baker\" won't be able to include core shaders. Switch to the \"%s\" renderer temporarily to fix this."), export_renderer);
112
}
113
}
114
115
if (p_name == "codesign/certificate_file" || p_name == "codesign/certificate_password" || p_name == "codesign/identity") {
116
if (dist_type == 2) {
117
if (ad_hoc) {
118
return TTR("App Store distribution with ad-hoc code signing is not supported.");
119
}
120
} else if (notary_tool > 0 && ad_hoc) {
121
return TTR("Notarization with an ad-hoc signature is not supported.");
122
}
123
}
124
125
if (p_name == "codesign/apple_team_id") {
126
String team_id = p_preset->get("codesign/apple_team_id");
127
if (team_id.is_empty()) {
128
if (dist_type == 2) {
129
return TTR("Apple Team ID is required for App Store distribution.");
130
} else if (notary_tool > 0) {
131
return TTR("Apple Team ID is required for notarization.");
132
}
133
}
134
}
135
136
if (p_name == "codesign/provisioning_profile" && dist_type == 2) {
137
String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE);
138
if (pprof.is_empty()) {
139
return TTR("Provisioning profile is required for App Store distribution.");
140
}
141
}
142
143
if (p_name == "codesign/installer_identity" && dist_type == 2) {
144
String ident = p_preset->get("codesign/installer_identity");
145
if (ident.is_empty()) {
146
return TTR("Installer signing identity is required for App Store distribution.");
147
}
148
}
149
150
if (p_name == "codesign/entitlements/app_sandbox/enabled" && dist_type == 2) {
151
bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");
152
if (!sandbox) {
153
return TTR("App sandbox is required for App Store distribution.");
154
}
155
}
156
157
if (p_name == "codesign/codesign") {
158
if (dist_type == 2) {
159
if (codesign_tool == 2 && ClassDB::class_exists("CSharpScript")) {
160
return TTR("'rcodesign' doesn't support signing applications with embedded dynamic libraries (GDExtension or .NET).");
161
}
162
if (codesign_tool == 0) {
163
return TTR("Code signing is required for App Store distribution.");
164
}
165
if (codesign_tool == 1) {
166
return TTR("App Store distribution with ad-hoc code signing is not supported.");
167
}
168
} else if (notary_tool > 0) {
169
if (codesign_tool == 0) {
170
return TTR("Code signing is required for notarization.");
171
}
172
if (codesign_tool == 1) {
173
return TTR("Notarization with an ad-hoc signature is not supported.");
174
}
175
}
176
}
177
178
if (notary_tool == 2 || notary_tool == 3) {
179
if (p_name == "notarization/apple_id_name" || p_name == "notarization/api_uuid") {
180
String apple_id = p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID);
181
String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);
182
if (apple_id.is_empty() && api_uuid.is_empty()) {
183
return TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified.");
184
}
185
if (!apple_id.is_empty() && !api_uuid.is_empty()) {
186
return TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.");
187
}
188
}
189
if (p_name == "notarization/apple_id_password") {
190
String apple_id = p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID);
191
String apple_pass = p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS);
192
if (!apple_id.is_empty() && apple_pass.is_empty()) {
193
return TTR("Apple ID password not specified.");
194
}
195
}
196
if (p_name == "notarization/api_key_id") {
197
String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);
198
String api_key = p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID);
199
if (!api_uuid.is_empty() && api_key.is_empty()) {
200
return TTR("App Store Connect API key ID not specified.");
201
}
202
}
203
} else if (notary_tool == 1) {
204
if (p_name == "notarization/api_uuid") {
205
String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);
206
if (api_uuid.is_empty()) {
207
return TTR("App Store Connect issuer ID name not specified.");
208
}
209
}
210
if (p_name == "notarization/api_key_id") {
211
String api_key = p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID);
212
if (api_key.is_empty()) {
213
return TTR("App Store Connect API key ID not specified.");
214
}
215
}
216
}
217
218
if (codesign_tool > 0) {
219
if (p_name == "privacy/microphone_usage_description") {
220
String discr = p_preset->get("privacy/microphone_usage_description");
221
bool enabled = p_preset->get("codesign/entitlements/audio_input");
222
if (enabled && discr.is_empty()) {
223
return TTR("Microphone access is enabled, but usage description is not specified.");
224
}
225
}
226
if (p_name == "privacy/camera_usage_description") {
227
String discr = p_preset->get("privacy/camera_usage_description");
228
bool enabled = p_preset->get("codesign/entitlements/camera");
229
if (enabled && discr.is_empty()) {
230
return TTR("Camera access is enabled, but usage description is not specified.");
231
}
232
}
233
if (p_name == "privacy/location_usage_description") {
234
String discr = p_preset->get("privacy/location_usage_description");
235
bool enabled = p_preset->get("codesign/entitlements/location");
236
if (enabled && discr.is_empty()) {
237
return TTR("Location information access is enabled, but usage description is not specified.");
238
}
239
}
240
if (p_name == "privacy/address_book_usage_description") {
241
String discr = p_preset->get("privacy/address_book_usage_description");
242
bool enabled = p_preset->get("codesign/entitlements/address_book");
243
if (enabled && discr.is_empty()) {
244
return TTR("Address book access is enabled, but usage description is not specified.");
245
}
246
}
247
if (p_name == "privacy/calendar_usage_description") {
248
String discr = p_preset->get("privacy/calendar_usage_description");
249
bool enabled = p_preset->get("codesign/entitlements/calendars");
250
if (enabled && discr.is_empty()) {
251
return TTR("Calendar access is enabled, but usage description is not specified.");
252
}
253
}
254
if (p_name == "privacy/photos_library_usage_description") {
255
String discr = p_preset->get("privacy/photos_library_usage_description");
256
bool enabled = p_preset->get("codesign/entitlements/photos_library");
257
if (enabled && discr.is_empty()) {
258
return TTR("Photo library access is enabled, but usage description is not specified.");
259
}
260
}
261
}
262
}
263
return String();
264
}
265
266
bool EditorExportPlatformMacOS::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {
267
// Hide irrelevant code signing options.
268
if (p_preset) {
269
int codesign_tool = p_preset->get("codesign/codesign");
270
switch (codesign_tool) {
271
case 1: { // built-in ad-hoc
272
if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options" || p_option == "codesign/team_id") {
273
return false;
274
}
275
} break;
276
case 2: { // "rcodesign"
277
if (p_option == "codesign/identity") {
278
return false;
279
}
280
} break;
281
#ifdef MACOS_ENABLED
282
case 3: { // "codesign"
283
if (p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password") {
284
return false;
285
}
286
} break;
287
#endif
288
default: { // disabled
289
if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options" || p_option.begins_with("codesign/entitlements") || p_option == "codesign/team_id") {
290
return false;
291
}
292
} break;
293
}
294
295
// Distribution type.
296
int dist_type = p_preset->get("export/distribution_type");
297
if (dist_type != 2 && p_option == "codesign/installer_identity") {
298
return false;
299
}
300
301
if (dist_type == 2 && p_option.begins_with("notarization/")) {
302
return false;
303
}
304
305
if (dist_type != 2 && p_option == "codesign/provisioning_profile") {
306
return false;
307
}
308
309
#ifndef MACOS_ENABLED
310
if (p_option == "application/liquid_glass_icon") {
311
return false;
312
}
313
#endif
314
315
String custom_prof = p_preset->get("codesign/entitlements/custom_file");
316
if (!custom_prof.is_empty() && p_option != "codesign/entitlements/custom_file" && p_option.begins_with("codesign/entitlements/")) {
317
return false;
318
}
319
320
// Hide sandbox entitlements.
321
bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");
322
if (!sandbox && p_option != "codesign/entitlements/app_sandbox/enabled" && p_option.begins_with("codesign/entitlements/app_sandbox/")) {
323
return false;
324
}
325
326
// Hide SSH options.
327
bool ssh = p_preset->get("ssh_remote_deploy/enabled");
328
if (!ssh && p_option != "ssh_remote_deploy/enabled" && p_option.begins_with("ssh_remote_deploy/")) {
329
return false;
330
}
331
332
// Hide irrelevant notarization options.
333
int notary_tool = p_preset->get("notarization/notarization");
334
switch (notary_tool) {
335
case 1: { // "rcodesign"
336
if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password") {
337
return false;
338
}
339
} break;
340
case 2: { // "notarytool"
341
// All options are visible.
342
} break;
343
default: { // disabled
344
if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/api_uuid" || p_option == "notarization/api_key" || p_option == "notarization/api_key_id") {
345
return false;
346
}
347
} break;
348
}
349
350
bool advanced_options_enabled = p_preset->are_advanced_options_enabled();
351
if (p_option.begins_with("privacy") ||
352
p_option == "codesign/entitlements/additional" ||
353
p_option == "custom_template/debug" ||
354
p_option == "custom_template/release" ||
355
p_option == "application/additional_plist_content" ||
356
p_option == "application/export_angle" ||
357
p_option == "application/icon_interpolation" ||
358
p_option == "application/signature" ||
359
p_option == "display/high_res" ||
360
p_option == "xcode/platform_build" ||
361
p_option == "xcode/sdk_build" ||
362
p_option == "xcode/sdk_name" ||
363
p_option == "xcode/sdk_version" ||
364
p_option == "xcode/xcode_build" ||
365
p_option == "xcode/xcode_version") {
366
return advanced_options_enabled;
367
}
368
}
369
370
// These entitlements are required to run managed code, and are always enabled in Mono builds.
371
if (ClassDB::class_exists("CSharpScript")) {
372
if (p_option == "codesign/entitlements/allow_jit_code_execution" || p_option == "codesign/entitlements/allow_unsigned_executable_memory" || p_option == "codesign/entitlements/allow_dyld_environment_variables") {
373
return false;
374
}
375
}
376
377
// Hide unsupported .NET embedding option.
378
if (p_option == "dotnet/embed_build_outputs") {
379
return false;
380
}
381
382
return true;
383
}
384
385
List<String> EditorExportPlatformMacOS::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
386
List<String> list;
387
388
if (p_preset.is_valid()) {
389
int dist_type = p_preset->get("export/distribution_type");
390
if (dist_type == 0) {
391
#ifdef MACOS_ENABLED
392
list.push_back("dmg");
393
#endif
394
list.push_back("zip");
395
list.push_back("app");
396
} else if (dist_type == 1) {
397
#ifdef MACOS_ENABLED
398
list.push_back("dmg");
399
#endif
400
list.push_back("zip");
401
list.push_back("app");
402
} else if (dist_type == 2) {
403
#ifdef MACOS_ENABLED
404
list.push_back("pkg");
405
#endif
406
}
407
}
408
409
return list;
410
}
411
412
struct DataCollectionInfo {
413
String prop_name;
414
String type_name;
415
};
416
417
static const DataCollectionInfo data_collect_type_info[] = {
418
{ "name", "NSPrivacyCollectedDataTypeName" },
419
{ "email_address", "NSPrivacyCollectedDataTypeEmailAddress" },
420
{ "phone_number", "NSPrivacyCollectedDataTypePhoneNumber" },
421
{ "physical_address", "NSPrivacyCollectedDataTypePhysicalAddress" },
422
{ "other_contact_info", "NSPrivacyCollectedDataTypeOtherUserContactInfo" },
423
{ "health", "NSPrivacyCollectedDataTypeHealth" },
424
{ "fitness", "NSPrivacyCollectedDataTypeFitness" },
425
{ "payment_info", "NSPrivacyCollectedDataTypePaymentInfo" },
426
{ "credit_info", "NSPrivacyCollectedDataTypeCreditInfo" },
427
{ "other_financial_info", "NSPrivacyCollectedDataTypeOtherFinancialInfo" },
428
{ "precise_location", "NSPrivacyCollectedDataTypePreciseLocation" },
429
{ "coarse_location", "NSPrivacyCollectedDataTypeCoarseLocation" },
430
{ "sensitive_info", "NSPrivacyCollectedDataTypeSensitiveInfo" },
431
{ "contacts", "NSPrivacyCollectedDataTypeContacts" },
432
{ "emails_or_text_messages", "NSPrivacyCollectedDataTypeEmailsOrTextMessages" },
433
{ "photos_or_videos", "NSPrivacyCollectedDataTypePhotosorVideos" },
434
{ "audio_data", "NSPrivacyCollectedDataTypeAudioData" },
435
{ "gameplay_content", "NSPrivacyCollectedDataTypeGameplayContent" },
436
{ "customer_support", "NSPrivacyCollectedDataTypeCustomerSupport" },
437
{ "other_user_content", "NSPrivacyCollectedDataTypeOtherUserContent" },
438
{ "browsing_history", "NSPrivacyCollectedDataTypeBrowsingHistory" },
439
{ "search_hhistory", "NSPrivacyCollectedDataTypeSearchHistory" },
440
{ "user_id", "NSPrivacyCollectedDataTypeUserID" },
441
{ "device_id", "NSPrivacyCollectedDataTypeDeviceID" },
442
{ "purchase_history", "NSPrivacyCollectedDataTypePurchaseHistory" },
443
{ "product_interaction", "NSPrivacyCollectedDataTypeProductInteraction" },
444
{ "advertising_data", "NSPrivacyCollectedDataTypeAdvertisingData" },
445
{ "other_usage_data", "NSPrivacyCollectedDataTypeOtherUsageData" },
446
{ "crash_data", "NSPrivacyCollectedDataTypeCrashData" },
447
{ "performance_data", "NSPrivacyCollectedDataTypePerformanceData" },
448
{ "other_diagnostic_data", "NSPrivacyCollectedDataTypeOtherDiagnosticData" },
449
{ "environment_scanning", "NSPrivacyCollectedDataTypeEnvironmentScanning" },
450
{ "hands", "NSPrivacyCollectedDataTypeHands" },
451
{ "head", "NSPrivacyCollectedDataTypeHead" },
452
{ "other_data_types", "NSPrivacyCollectedDataTypeOtherDataTypes" },
453
};
454
455
static const DataCollectionInfo data_collect_purpose_info[] = {
456
{ "Analytics", "NSPrivacyCollectedDataTypePurposeAnalytics" },
457
{ "App Functionality", "NSPrivacyCollectedDataTypePurposeAppFunctionality" },
458
{ "Developer Advertising", "NSPrivacyCollectedDataTypePurposeDeveloperAdvertising" },
459
{ "Third-party Advertising", "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising" },
460
{ "Product Personalization", "NSPrivacyCollectedDataTypePurposeProductPersonalization" },
461
{ "Other", "NSPrivacyCollectedDataTypePurposeOther" },
462
};
463
464
void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options) const {
465
#ifdef MACOS_ENABLED
466
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution,App Store"), 1, true));
467
#else
468
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution"), 1, true));
469
#endif
470
471
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "binary_format/architecture", PROPERTY_HINT_ENUM, "universal,x86_64,arm64", PROPERTY_USAGE_STORAGE), "universal"));
472
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
473
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
474
475
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "debug/export_console_wrapper", PROPERTY_HINT_ENUM, "No,Debug Only,Debug and Release"), 1));
476
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/liquid_glass_icon", PROPERTY_HINT_FILE, "*.icon"), ""));
477
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.icns,*.png,*.webp,*.svg"), ""));
478
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
479
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "", false, true));
480
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
481
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_category", PROPERTY_HINT_ENUM, "Business,Developer-tools,Education,Entertainment,Finance,Games,Action-games,Adventure-games,Arcade-games,Board-games,Card-games,Casino-games,Dice-games,Educational-games,Family-games,Kids-games,Music-games,Puzzle-games,Racing-games,Role-playing-games,Simulation-games,Sports-games,Strategy-games,Trivia-games,Word-games,Graphics-design,Healthcare-fitness,Lifestyle,Medical,Music,News,Photography,Productivity,Reference,Social-networking,Sports,Travel,Utilities,Video,Weather"), "Games"));
482
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
483
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
484
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
485
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "application/copyright_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
486
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version_x86_64"), "10.12"));
487
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version_arm64"), "11.00"));
488
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_angle", PROPERTY_HINT_ENUM, "Auto,Yes,No"), 0, true));
489
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), true));
490
491
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "shader_baker/enabled"), false));
492
493
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/additional_plist_content", PROPERTY_HINT_MULTILINE_TEXT), ""));
494
495
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/platform_build"), "14C18"));
496
// TODO(sgc): Need to set appropriate version when using Metal
497
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_version"), "13.1"));
498
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_build"), "22C55"));
499
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_name"), "macosx13.1"));
500
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_version"), "1420"));
501
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_build"), "14C18"));
502
503
#ifdef MACOS_ENABLED
504
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign,Xcode codesign"), 3, true));
505
#else
506
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign"), 1, true, true));
507
#endif
508
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/installer_identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "3rd Party Mac Developer Installer: (ID)"), "", false, true));
509
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/apple_team_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "ID"), "", false, true));
510
// "codesign" only options:
511
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), ""));
512
// "rcodesign" only options:
513
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_file", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
514
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_password", PROPERTY_HINT_PASSWORD, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
515
// "codesign" and "rcodesign" only options:
516
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/provisioning_profile", PROPERTY_HINT_GLOBAL_FILE, "*.provisionprofile", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
517
518
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), "", true));
519
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false));
520
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false));
521
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false));
522
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false));
523
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false));
524
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false));
525
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/location"), false));
526
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/address_book"), false));
527
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/calendars"), false));
528
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/photos_library"), false));
529
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/apple_events"), false));
530
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/debugging"), false));
531
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/enabled"), false, true, true));
532
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_server"), false));
533
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_client"), false));
534
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_usb"), false));
535
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_bluetooth"), false));
536
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_downloads", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
537
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_pictures", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
538
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_music", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
539
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_movies", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
540
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_user_selected", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
541
r_options->push_back(ExportOption(PropertyInfo(Variant::ARRAY, "codesign/entitlements/app_sandbox/helper_executables", PROPERTY_HINT_ARRAY_TYPE, itos(Variant::STRING) + "/" + itos(PROPERTY_HINT_GLOBAL_FILE) + ":"), Array()));
542
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/additional", PROPERTY_HINT_MULTILINE_TEXT), ""));
543
r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
544
545
#ifdef MACOS_ENABLED
546
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign,Xcode notarytool"), 0, true));
547
#else
548
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign"), 0, true));
549
#endif
550
// "notarytool" only options:
551
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple ID email", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
552
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_password", PROPERTY_HINT_PASSWORD, "Enable two-factor authentication and provide app-specific password", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
553
// "notarytool" and "rcodesign" only options:
554
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_uuid", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect issuer ID UUID", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
555
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_GLOBAL_FILE, "*.p8", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
556
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect API key ID", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
557
558
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/microphone_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the microphone"), "", false, true));
559
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
560
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/camera_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the camera"), "", false, true));
561
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
562
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/location_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the location information"), "", false, true));
563
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/location_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
564
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/address_book_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the address book"), "", false, true));
565
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/address_book_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
566
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/calendar_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the calendar"), "", false, true));
567
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/calendar_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
568
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/photos_library_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the photo library"), "", false, true));
569
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photos_library_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
570
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/desktop_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Desktop folder"), "", false, true));
571
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/desktop_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
572
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/documents_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Documents folder"), "", false, true));
573
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/documents_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
574
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/downloads_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Downloads folder"), "", false, true));
575
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/downloads_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
576
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/network_volumes_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use network volumes"), "", false, true));
577
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/network_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
578
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/removable_volumes_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use removable volumes"), "", false, true));
579
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/removable_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
580
581
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "privacy/tracking_enabled"), false));
582
r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "privacy/tracking_domains"), Vector<String>()));
583
584
{
585
String hint;
586
for (uint64_t i = 0; i < std_size(data_collect_purpose_info); ++i) {
587
if (i != 0) {
588
hint += ",";
589
}
590
hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i));
591
}
592
for (uint64_t i = 0; i < std_size(data_collect_type_info); ++i) {
593
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false));
594
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false));
595
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false));
596
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[i].prop_name), PROPERTY_HINT_FLAGS, hint), 0));
597
}
598
}
599
600
String run_script = "#!/usr/bin/env bash\n"
601
"unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"\n"
602
"open \"{temp_dir}/{exe_name}.app\" --args {cmd_args}";
603
604
String cleanup_script = "#!/usr/bin/env bash\n"
605
"kill $(pgrep -x -f \"{temp_dir}/{exe_name}.app/Contents/MacOS/{exe_name} {cmd_args}\")\n"
606
"rm -rf \"{temp_dir}\"";
607
608
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true));
609
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/host"), "user@host_ip"));
610
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/port"), "22"));
611
612
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_ssh", PROPERTY_HINT_MULTILINE_TEXT), ""));
613
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_scp", PROPERTY_HINT_MULTILINE_TEXT), ""));
614
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/run_script", PROPERTY_HINT_MULTILINE_TEXT), run_script));
615
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/cleanup_script", PROPERTY_HINT_MULTILINE_TEXT), cleanup_script));
616
}
617
618
void _rgba8_to_packbits_encode(int p_ch, int p_size, Vector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {
619
int src_len = p_size * p_size;
620
621
Vector<uint8_t> result;
622
623
int i = 0;
624
const uint8_t *src = p_source.ptr();
625
while (i < src_len) {
626
Vector<uint8_t> seq;
627
628
uint8_t count = 0;
629
while (count <= 0x7f && i < src_len) {
630
if (i + 2 < src_len && src[i * 4 + p_ch] == src[(i + 1) * 4 + p_ch] && src[i] == src[(i + 2) * 4 + p_ch]) {
631
break;
632
}
633
seq.push_back(src[i * 4 + p_ch]);
634
i++;
635
count++;
636
}
637
if (!seq.is_empty()) {
638
result.push_back(count - 1);
639
result.append_array(seq);
640
}
641
if (i >= src_len) {
642
break;
643
}
644
645
uint8_t rep = src[i * 4 + p_ch];
646
count = 0;
647
while (count <= 0x7f && i < src_len && src[i * 4 + p_ch] == rep) {
648
i++;
649
count++;
650
}
651
if (count >= 3) {
652
result.push_back(0x80 + count - 3);
653
result.push_back(rep);
654
} else {
655
result.push_back(count - 1);
656
for (int j = 0; j < count; j++) {
657
result.push_back(rep);
658
}
659
}
660
}
661
662
int ofs = p_dest.size();
663
p_dest.resize(p_dest.size() + result.size());
664
memcpy(&p_dest.write[ofs], result.ptr(), result.size());
665
}
666
667
void EditorExportPlatformMacOS::_make_icon(const Ref<EditorExportPreset> &p_preset, const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
668
Vector<uint8_t> data;
669
670
data.resize(8);
671
data.write[0] = 'i';
672
data.write[1] = 'c';
673
data.write[2] = 'n';
674
data.write[3] = 's';
675
676
struct MacOSIconInfo {
677
const char *name;
678
const char *mask_name;
679
bool is_png;
680
int size;
681
};
682
683
static const MacOSIconInfo icon_infos[] = {
684
{ "ic10", "", true, 1024 }, //1024×1024 32-bit PNG and 512×512@2x 32-bit "retina" PNG
685
{ "ic09", "", true, 512 }, //512×512 32-bit PNG
686
{ "ic14", "", true, 512 }, //256×256@2x 32-bit "retina" PNG
687
{ "ic08", "", true, 256 }, //256×256 32-bit PNG
688
{ "ic13", "", true, 256 }, //128×128@2x 32-bit "retina" PNG
689
{ "ic07", "", true, 128 }, //128×128 32-bit PNG
690
{ "ic12", "", true, 64 }, //32×32@2× 32-bit "retina" PNG
691
{ "ic11", "", true, 32 }, //16×16@2× 32-bit "retina" PNG
692
{ "il32", "l8mk", false, 32 }, //32×32 24-bit RLE + 8-bit uncompressed mask
693
{ "is32", "s8mk", false, 16 } //16×16 24-bit RLE + 8-bit uncompressed mask
694
};
695
696
for (uint64_t i = 0; i < std_size(icon_infos); ++i) {
697
Ref<Image> copy = p_icon->duplicate();
698
copy->convert(Image::FORMAT_RGBA8);
699
copy->resize(icon_infos[i].size, icon_infos[i].size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
700
701
if (icon_infos[i].is_png) {
702
// Encode PNG icon.
703
Vector<uint8_t> png_buffer;
704
Error err = PNGDriverCommon::image_to_png(copy, png_buffer);
705
if (err == OK) {
706
int ofs = data.size();
707
uint64_t len = png_buffer.size();
708
data.resize(data.size() + len + 8);
709
memcpy(&data.write[ofs + 8], png_buffer.ptr(), len);
710
len += 8;
711
len = BSWAP32(len);
712
memcpy(&data.write[ofs], icon_infos[i].name, 4);
713
encode_uint32(len, &data.write[ofs + 4]);
714
}
715
} else {
716
Vector<uint8_t> src_data = copy->get_data();
717
718
// Encode 24-bit RGB RLE icon.
719
{
720
int ofs = data.size();
721
data.resize(data.size() + 8);
722
723
_rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // Encode R.
724
_rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // Encode G.
725
_rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // Encode B.
726
727
// Note: workaround for macOS icon decoder bug corrupting last RLE encoded value.
728
data.push_back(0x00);
729
730
int len = data.size() - ofs;
731
len = BSWAP32(len);
732
memcpy(&data.write[ofs], icon_infos[i].name, 4);
733
encode_uint32(len, &data.write[ofs + 4]);
734
}
735
736
// Encode 8-bit mask uncompressed icon.
737
{
738
int ofs = data.size();
739
int len = copy->get_width() * copy->get_height();
740
data.resize(data.size() + len + 8);
741
742
for (int j = 0; j < len; j++) {
743
data.write[ofs + 8 + j] = src_data.ptr()[j * 4 + 3];
744
}
745
len += 8;
746
len = BSWAP32(len);
747
memcpy(&data.write[ofs], icon_infos[i].mask_name, 4);
748
encode_uint32(len, &data.write[ofs + 4]);
749
}
750
}
751
}
752
753
uint32_t total_len = data.size();
754
total_len = BSWAP32(total_len);
755
encode_uint32(total_len, &data.write[4]);
756
757
p_data = data;
758
}
759
760
void EditorExportPlatformMacOS::_fix_privacy_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist) {
761
String str = String::utf8((const char *)plist.ptr(), plist.size());
762
String strnew;
763
Vector<String> lines = str.split("\n");
764
for (int i = 0; i < lines.size(); i++) {
765
if (lines[i].find("$priv_collection") != -1) {
766
bool section_opened = false;
767
for (uint64_t j = 0; j < std_size(data_collect_type_info); ++j) {
768
bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name));
769
bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name));
770
bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name));
771
int purposes = p_preset->get(vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[j].prop_name));
772
if (data_collected) {
773
if (!section_opened) {
774
section_opened = true;
775
strnew += "\t<key>NSPrivacyCollectedDataTypes</key>\n";
776
strnew += "\t<array>\n";
777
}
778
strnew += "\t\t<dict>\n";
779
strnew += "\t\t\t<key>NSPrivacyCollectedDataType</key>\n";
780
strnew += vformat("\t\t\t<string>%s</string>\n", data_collect_type_info[j].type_name);
781
strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeLinked</key>\n";
782
if (linked) {
783
strnew += "\t\t\t\t<true/>\n";
784
} else {
785
strnew += "\t\t\t\t<false/>\n";
786
}
787
strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeTracking</key>\n";
788
if (tracking) {
789
strnew += "\t\t\t\t<true/>\n";
790
} else {
791
strnew += "\t\t\t\t<false/>\n";
792
}
793
if (purposes != 0) {
794
strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n";
795
strnew += "\t\t\t\t<array>\n";
796
for (uint64_t k = 0; k < std_size(data_collect_purpose_info); ++k) {
797
if (purposes & (1 << k)) {
798
strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name);
799
}
800
}
801
strnew += "\t\t\t\t</array>\n";
802
}
803
strnew += "\t\t\t</dict>\n";
804
}
805
}
806
if (section_opened) {
807
strnew += "\t</array>\n";
808
}
809
} else if (lines[i].find("$priv_tracking") != -1) {
810
bool tracking = p_preset->get("privacy/tracking_enabled");
811
strnew += "\t<key>NSPrivacyTracking</key>\n";
812
if (tracking) {
813
strnew += "\t<true/>\n";
814
} else {
815
strnew += "\t<false/>\n";
816
}
817
Vector<String> tracking_domains = p_preset->get("privacy/tracking_domains");
818
if (!tracking_domains.is_empty()) {
819
strnew += "\t<key>NSPrivacyTrackingDomains</key>\n";
820
strnew += "\t<array>\n";
821
for (const String &E : tracking_domains) {
822
strnew += "\t\t<string>" + E + "</string>\n";
823
}
824
strnew += "\t</array>\n";
825
}
826
} else {
827
strnew += lines[i] + "\n";
828
}
829
}
830
831
CharString cs = strnew.utf8();
832
plist.resize(cs.size() - 1);
833
for (int i = 0; i < cs.size() - 1; i++) {
834
plist.write[i] = cs[i];
835
}
836
}
837
838
void EditorExportPlatformMacOS::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary, bool p_lg_icon_exported, const String &p_lg_icon) {
839
String str = String::utf8((const char *)plist.ptr(), plist.size());
840
String strnew;
841
Vector<String> lines = str.split("\n");
842
for (int i = 0; i < lines.size(); i++) {
843
if (lines[i].contains("$binary")) {
844
strnew += lines[i].replace("$binary", p_binary) + "\n";
845
} else if (lines[i].contains("$name")) {
846
strnew += lines[i].replace("$name", get_project_setting(p_preset, "application/config/name")) + "\n";
847
} else if (lines[i].contains("$bundle_identifier")) {
848
strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
849
} else if (lines[i].contains("$short_version")) {
850
strnew += lines[i].replace("$short_version", p_preset->get_version("application/short_version")) + "\n";
851
} else if (lines[i].contains("$version")) {
852
strnew += lines[i].replace("$version", p_preset->get_version("application/version")) + "\n";
853
} else if (lines[i].contains("$signature")) {
854
strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
855
} else if (lines[i].contains("$app_category")) {
856
String cat = p_preset->get("application/app_category");
857
strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n";
858
} else if (lines[i].contains("$copyright")) {
859
strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
860
} else if (lines[i].contains("$min_version_arm64")) {
861
strnew += lines[i].replace("$min_version_arm64", p_preset->get("application/min_macos_version_arm64")) + "\n";
862
} else if (lines[i].contains("$min_version_x86_64")) {
863
strnew += lines[i].replace("$min_version_x86_64", p_preset->get("application/min_macos_version_x86_64")) + "\n";
864
} else if (lines[i].contains("$min_version")) {
865
strnew += lines[i].replace("$min_version", p_preset->get("application/min_macos_version_x86_64")) + "\n"; // Old template, use x86-64 version for both.
866
} else if (lines[i].contains("$highres")) {
867
strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "\t<true/>" : "\t<false/>") + "\n";
868
} else if (lines[i].contains("$additional_plist_content")) {
869
strnew += lines[i].replace("$additional_plist_content", p_preset->get("application/additional_plist_content")) + "\n";
870
} else if (lines[i].contains("$platfbuild")) {
871
strnew += lines[i].replace("$platfbuild", p_preset->get("xcode/platform_build")) + "\n";
872
} else if (lines[i].contains("$sdkver")) {
873
strnew += lines[i].replace("$sdkver", p_preset->get("xcode/sdk_version")) + "\n";
874
} else if (lines[i].contains("$sdkname")) {
875
strnew += lines[i].replace("$sdkname", p_preset->get("xcode/sdk_name")) + "\n";
876
} else if (lines[i].contains("$sdkbuild")) {
877
strnew += lines[i].replace("$sdkbuild", p_preset->get("xcode/sdk_build")) + "\n";
878
} else if (lines[i].contains("$xcodever")) {
879
strnew += lines[i].replace("$xcodever", p_preset->get("xcode/xcode_version")) + "\n";
880
} else if (lines[i].contains("$xcodebuild")) {
881
strnew += lines[i].replace("$xcodebuild", p_preset->get("xcode/xcode_build")) + "\n";
882
} else if (lines[i].contains("$liquid_glass_icon")) {
883
if (p_lg_icon_exported) {
884
strnew += lines[i].replace("$liquid_glass_icon", "\t<key>CFBundleIconName</key>\n\t<string>" + p_lg_icon + "</string>\n");
885
} else {
886
strnew += lines[i].replace("$liquid_glass_icon", "");
887
}
888
} else if (lines[i].contains("$usage_descriptions")) {
889
String descriptions;
890
if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
891
descriptions += "\t<key>NSMicrophoneUsageDescription</key>\n";
892
descriptions += "\t<string>" + (String)p_preset->get("privacy/microphone_usage_description") + "</string>\n";
893
}
894
if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
895
descriptions += "\t<key>NSCameraUsageDescription</key>\n";
896
descriptions += "\t<string>" + (String)p_preset->get("privacy/camera_usage_description") + "</string>\n";
897
}
898
if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
899
descriptions += "\t<key>NSLocationUsageDescription</key>\n";
900
descriptions += "\t<string>" + (String)p_preset->get("privacy/location_usage_description") + "</string>\n";
901
}
902
if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
903
descriptions += "\t<key>NSContactsUsageDescription</key>\n";
904
descriptions += "\t<string>" + (String)p_preset->get("privacy/address_book_usage_description") + "</string>\n";
905
}
906
if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
907
descriptions += "\t<key>NSCalendarsUsageDescription</key>\n";
908
descriptions += "\t<string>" + (String)p_preset->get("privacy/calendar_usage_description") + "</string>\n";
909
}
910
if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
911
descriptions += "\t<key>NSPhotoLibraryUsageDescription</key>\n";
912
descriptions += "\t<string>" + (String)p_preset->get("privacy/photos_library_usage_description") + "</string>\n";
913
}
914
if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {
915
descriptions += "\t<key>NSDesktopFolderUsageDescription</key>\n";
916
descriptions += "\t<string>" + (String)p_preset->get("privacy/desktop_folder_usage_description") + "</string>\n";
917
}
918
if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {
919
descriptions += "\t<key>NSDocumentsFolderUsageDescription</key>\n";
920
descriptions += "\t<string>" + (String)p_preset->get("privacy/documents_folder_usage_description") + "</string>\n";
921
}
922
if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {
923
descriptions += "\t<key>NSDownloadsFolderUsageDescription</key>\n";
924
descriptions += "\t<string>" + (String)p_preset->get("privacy/downloads_folder_usage_description") + "</string>\n";
925
}
926
if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {
927
descriptions += "\t<key>NSNetworkVolumesUsageDescription</key>\n";
928
descriptions += "\t<string>" + (String)p_preset->get("privacy/network_volumes_usage_description") + "</string>\n";
929
}
930
if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {
931
descriptions += "\t<key>NSRemovableVolumesUsageDescription</key>\n";
932
descriptions += "\t<string>" + (String)p_preset->get("privacy/removable_volumes_usage_description") + "</string>\n";
933
}
934
if (!descriptions.is_empty()) {
935
strnew += lines[i].replace("$usage_descriptions", descriptions);
936
}
937
} else {
938
strnew += lines[i] + "\n";
939
}
940
}
941
942
CharString cs = strnew.utf8();
943
plist.resize(cs.size() - 1);
944
for (int i = 0; i < cs.size() - 1; i++) {
945
plist.write[i] = cs[i];
946
}
947
}
948
949
Error EditorExportPlatformMacOS::_export_liquid_glass_icon(const Ref<EditorExportPreset> &p_preset, const String &p_app_path, const String &p_icon_path) {
950
String actool = EDITOR_GET("export/macos/actool").operator String();
951
if (actool.is_empty()) {
952
actool = "actool";
953
}
954
955
List<String> args;
956
args.push_back("--version");
957
String str;
958
String err_str;
959
int exitcode = 0;
960
961
Error err = OS::get_singleton()->execute(actool, args, &str, &exitcode, true);
962
if (err != OK) {
963
add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not start 'actool' executable."));
964
return err;
965
}
966
PList info_plist;
967
if (!info_plist.load_string(str, err_str)) {
968
print_verbose(str);
969
add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not read 'actool' version."));
970
return err;
971
}
972
if (info_plist.get_root()->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && info_plist.get_root()->data_dict.has("com.apple.actool.version")) {
973
Ref<PListNode> dict = info_plist.get_root()->data_dict["com.apple.actool.version"];
974
if (dict->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && dict->data_dict.has("short-bundle-version")) {
975
float version = String::utf8(dict->data_dict["short-bundle-version"]->data_string.get_data()).to_float();
976
if (version < 26.0) {
977
add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), vformat(TTR("At least version 26.0 of 'actool' is required (version %f found)."), version));
978
return ERR_UNAVAILABLE;
979
}
980
}
981
}
982
str.clear();
983
984
String plist = EditorPaths::get_singleton()->get_temp_dir().path_join("assetcatalog.plist");
985
args.clear();
986
args.push_back(ProjectSettings::get_singleton()->globalize_path(p_icon_path));
987
args.push_back("--compile");
988
args.push_back(p_app_path + "/Contents/Resources/");
989
args.push_back("--output-format");
990
args.push_back("human-readable-text");
991
args.push_back("--lightweight-asset-runtime-mode");
992
args.push_back("enabled");
993
args.push_back("--app-icon");
994
args.push_back(p_icon_path.get_file().get_basename());
995
args.push_back("--include-all-app-icons");
996
args.push_back("--enable-on-demand-resources");
997
args.push_back("NO");
998
args.push_back("--development-region");
999
args.push_back("en");
1000
args.push_back("--target-device");
1001
args.push_back("mac");
1002
args.push_back("--minimum-deployment-target");
1003
args.push_back("26");
1004
args.push_back("--platform");
1005
args.push_back("macosx");
1006
args.push_back("--output-partial-info-plist");
1007
args.push_back(plist);
1008
1009
err = OS::get_singleton()->execute(actool, args, &str, &exitcode, true);
1010
if (err != OK || str.contains("error:") || !FileAccess::exists(p_app_path + "/Contents/Resources/Assets.car") || !FileAccess::exists(plist)) {
1011
print_verbose(str);
1012
add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not export liquid glass icon:") + "\n" + str);
1013
return err;
1014
}
1015
1016
return OK;
1017
}
1018
1019
/**
1020
* If we're running the macOS version of the Godot editor we'll:
1021
* - export our application bundle to a temporary folder
1022
* - attempt to code sign it
1023
* - and then wrap it up in a DMG
1024
*/
1025
1026
Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
1027
int notary_tool = p_preset->get("notarization/notarization");
1028
switch (notary_tool) {
1029
case 1: { // "rcodesign"
1030
print_verbose("using rcodesign notarization...");
1031
1032
String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
1033
if (rcodesign.is_empty()) {
1034
add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));
1035
return Error::FAILED;
1036
}
1037
1038
List<String> args;
1039
1040
args.push_back("notary-submit");
1041
1042
if (p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) == "") {
1043
add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect issuer ID name not specified."));
1044
return Error::FAILED;
1045
}
1046
if (p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY) == "") {
1047
add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));
1048
return Error::FAILED;
1049
}
1050
1051
args.push_back("--api-issuer");
1052
args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID));
1053
1054
args.push_back("--api-key");
1055
args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID));
1056
1057
if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) {
1058
args.push_back("--api-key-path");
1059
args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY));
1060
}
1061
1062
args.push_back(p_path);
1063
1064
String str;
1065
int exitcode = 0;
1066
1067
Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);
1068
if (err != OK) {
1069
add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start rcodesign executable."));
1070
return err;
1071
}
1072
1073
int rq_offset = str.find("created submission ID:");
1074
if (exitcode != 0 || rq_offset == -1) {
1075
print_line("rcodesign (" + p_path + "):\n" + str);
1076
add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));
1077
return Error::FAILED;
1078
} else {
1079
print_verbose("rcodesign (" + p_path + "):\n" + str);
1080
int next_nl = str.find_char('\n', rq_offset);
1081
String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 23) : str.substr(rq_offset + 23, next_nl - rq_offset - 23);
1082
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));
1083
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour."));
1084
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check the progress manually by opening a Terminal and running the following command:"));
1085
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign notary-log --api-issuer <API UUID> --api-key <API key> <request UUID>\"");
1086
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));
1087
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign staple <app path>\"");
1088
}
1089
} break;
1090
#ifdef MACOS_ENABLED
1091
case 2: { // "notarytool"
1092
print_verbose("using notarytool notarization...");
1093
1094
if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {
1095
add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed."));
1096
return Error::FAILED;
1097
}
1098
1099
List<String> args;
1100
1101
args.push_back("notarytool");
1102
args.push_back("submit");
1103
1104
args.push_back(p_path);
1105
1106
if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) == "" && p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) == "") {
1107
add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified."));
1108
return Error::FAILED;
1109
}
1110
if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) != "" && p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) != "") {
1111
add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time."));
1112
return Error::FAILED;
1113
}
1114
1115
if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) != "") {
1116
if (p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS) == "") {
1117
add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified."));
1118
return Error::FAILED;
1119
}
1120
args.push_back("--apple-id");
1121
args.push_back(p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID));
1122
1123
args.push_back("--password");
1124
args.push_back(p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS));
1125
} else {
1126
if (p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID) == "") {
1127
add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));
1128
return Error::FAILED;
1129
}
1130
args.push_back("--issuer");
1131
args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID));
1132
1133
if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) {
1134
args.push_back("--key");
1135
args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY));
1136
}
1137
1138
args.push_back("--key-id");
1139
args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID));
1140
}
1141
1142
args.push_back("--no-progress");
1143
1144
if (p_preset->get("codesign/apple_team_id")) {
1145
args.push_back("--team-id");
1146
args.push_back(p_preset->get("codesign/apple_team_id"));
1147
}
1148
1149
String str;
1150
int exitcode = 0;
1151
Error err = OS::get_singleton()->execute("xcrun", args, &str, &exitcode, true);
1152
if (err != OK) {
1153
add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable."));
1154
return err;
1155
}
1156
1157
int rq_offset = str.find("id:");
1158
if (exitcode != 0 || rq_offset == -1) {
1159
print_line("notarytool (" + p_path + "):\n" + str);
1160
add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));
1161
return Error::FAILED;
1162
} else {
1163
print_verbose("notarytool (" + p_path + "):\n" + str);
1164
int next_nl = str.find_char('\n', rq_offset);
1165
String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 4) : str.substr(rq_offset + 4, next_nl - rq_offset - 4);
1166
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));
1167
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour."));
1168
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("See instructions on finding your team ID: https://developer.apple.com/help/glossary/team-id"));
1169
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check the progress manually by opening a Terminal and running the following command:"));
1170
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request UUID> --issuer <API UUID> --key-id <API key ID> --key <API key path>\" or");
1171
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request UUID> --team-id <team ID> --apple-id <your email> --password <app-specific password>\"");
1172
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));
1173
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple <app path>\"");
1174
}
1175
} break;
1176
#endif
1177
default: {
1178
};
1179
}
1180
return OK;
1181
}
1182
1183
void EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_warn, bool p_set_id) {
1184
int codesign_tool = p_preset->get("codesign/codesign");
1185
switch (codesign_tool) {
1186
case 1: { // built-in ad-hoc
1187
print_verbose("using built-in codesign...");
1188
String error_msg;
1189
Error err = CodeSign::codesign(false, true, p_path, p_ent_path, error_msg);
1190
if (err != OK) {
1191
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Built-in CodeSign failed with error \"%s\"."), error_msg));
1192
return;
1193
}
1194
} break;
1195
case 2: { // "rcodesign"
1196
print_verbose("using rcodesign codesign...");
1197
1198
String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
1199
if (rcodesign.is_empty()) {
1200
add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xrcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));
1201
return;
1202
}
1203
1204
List<String> args;
1205
args.push_back("sign");
1206
1207
if (!p_ent_path.is_empty()) {
1208
args.push_back("--entitlements-xml-path");
1209
args.push_back(p_ent_path);
1210
}
1211
1212
String certificate_file = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE);
1213
String certificate_pass = p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS);
1214
if (!certificate_file.is_empty() && !certificate_pass.is_empty()) {
1215
args.push_back("--p12-file");
1216
args.push_back(certificate_file);
1217
args.push_back("--p12-password");
1218
args.push_back(certificate_pass);
1219
}
1220
args.push_back("--code-signature-flags");
1221
args.push_back("runtime");
1222
1223
if (p_set_id) {
1224
String app_id = p_preset->get("application/bundle_identifier");
1225
args.push_back("--binary-identifier");
1226
args.push_back(app_id);
1227
}
1228
1229
args.push_back("-v"); /* provide some more feedback */
1230
1231
args.push_back(p_path);
1232
1233
String str;
1234
int exitcode = 0;
1235
1236
Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);
1237
if (err != OK) {
1238
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start rcodesign executable."));
1239
return;
1240
}
1241
1242
if (exitcode != 0) {
1243
print_line("rcodesign (" + p_path + "):\n" + str);
1244
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
1245
return;
1246
} else {
1247
print_verbose("rcodesign (" + p_path + "):\n" + str);
1248
}
1249
} break;
1250
#ifdef MACOS_ENABLED
1251
case 3: { // "codesign"
1252
print_verbose("using xcode codesign...");
1253
1254
if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
1255
add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xcode command line tools are not installed."));
1256
return;
1257
}
1258
1259
bool ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
1260
1261
List<String> args;
1262
if (!ad_hoc) {
1263
args.push_back("--timestamp");
1264
args.push_back("--options");
1265
args.push_back("runtime");
1266
}
1267
1268
if (!p_ent_path.is_empty()) {
1269
args.push_back("--entitlements");
1270
args.push_back(p_ent_path);
1271
}
1272
1273
PackedStringArray user_args = p_preset->get("codesign/custom_options");
1274
for (int i = 0; i < user_args.size(); i++) {
1275
String user_arg = user_args[i].strip_edges();
1276
if (!user_arg.is_empty()) {
1277
args.push_back(user_arg);
1278
}
1279
}
1280
1281
args.push_back("-s");
1282
if (ad_hoc) {
1283
args.push_back("-");
1284
} else {
1285
args.push_back(p_preset->get("codesign/identity"));
1286
}
1287
1288
if (p_set_id) {
1289
String app_id = p_preset->get("application/bundle_identifier");
1290
args.push_back("-i");
1291
args.push_back(app_id);
1292
}
1293
1294
args.push_back("-v"); /* provide some more feedback */
1295
args.push_back("-f");
1296
1297
args.push_back(p_path);
1298
1299
String str;
1300
int exitcode = 0;
1301
1302
Error err = OS::get_singleton()->execute("codesign", args, &str, &exitcode, true);
1303
if (err != OK) {
1304
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start codesign executable, make sure Xcode command line tools are installed."));
1305
return;
1306
}
1307
1308
if (exitcode != 0) {
1309
print_line("codesign (" + p_path + "):\n" + str);
1310
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
1311
return;
1312
} else {
1313
print_verbose("codesign (" + p_path + "):\n" + str);
1314
}
1315
} break;
1316
#endif
1317
default: {
1318
};
1319
}
1320
}
1321
1322
void EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path,
1323
const String &p_ent_path, const String &p_helper_ent_path, bool p_should_error_on_non_code) {
1324
static Vector<String> extensions_to_sign;
1325
1326
bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");
1327
if (extensions_to_sign.is_empty()) {
1328
extensions_to_sign.push_back("dylib");
1329
extensions_to_sign.push_back("framework");
1330
extensions_to_sign.push_back("");
1331
}
1332
1333
Error dir_access_error;
1334
Ref<DirAccess> dir_access{ DirAccess::open(p_path, &dir_access_error) };
1335
1336
if (dir_access_error != OK) {
1337
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign directory %s."), p_path));
1338
return;
1339
}
1340
1341
dir_access->list_dir_begin();
1342
String current_file{ dir_access->get_next() };
1343
while (!current_file.is_empty()) {
1344
String current_file_path{ p_path.path_join(current_file) };
1345
1346
if (current_file == ".." || current_file == ".") {
1347
current_file = dir_access->get_next();
1348
continue;
1349
}
1350
1351
if (extensions_to_sign.has(current_file.get_extension())) {
1352
String ent_path;
1353
bool set_bundle_id = false;
1354
if (sandbox && FileAccess::exists(current_file_path)) {
1355
int ftype = MachO::get_filetype(current_file_path);
1356
if (ftype == 2 || ftype == 5) {
1357
ent_path = p_helper_ent_path;
1358
set_bundle_id = true;
1359
}
1360
}
1361
_code_sign(p_preset, current_file_path, ent_path, false, set_bundle_id);
1362
if (is_executable(current_file_path)) {
1363
// chmod with 0755 if the file is executable.
1364
FileAccess::set_unix_permissions(current_file_path, 0755);
1365
}
1366
} else if (dir_access->current_is_dir()) {
1367
_code_sign_directory(p_preset, current_file_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code);
1368
} else if (p_should_error_on_non_code) {
1369
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign file %s."), current_file));
1370
}
1371
1372
current_file = dir_access->get_next();
1373
}
1374
}
1375
1376
Error EditorExportPlatformMacOS::_copy_and_sign_files(Ref<DirAccess> &dir_access, const String &p_src_path,
1377
const String &p_in_app_path, bool p_sign_enabled,
1378
const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,
1379
const String &p_helper_ent_path,
1380
bool p_should_error_on_non_code_sign, bool p_sandbox) {
1381
static Vector<String> extensions_to_sign;
1382
1383
if (extensions_to_sign.is_empty()) {
1384
extensions_to_sign.push_back("dylib");
1385
extensions_to_sign.push_back("framework");
1386
extensions_to_sign.push_back("");
1387
}
1388
1389
Error err{ OK };
1390
if (dir_access->dir_exists(p_src_path)) {
1391
#ifndef UNIX_ENABLED
1392
add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Relative symlinks are not supported, exported \"%s\" might be broken!"), p_src_path.get_file()));
1393
#endif
1394
print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path);
1395
1396
bool plist_missing = false;
1397
Ref<PList> plist;
1398
plist.instantiate();
1399
plist->load_file(p_src_path.path_join("Resources").path_join("Info.plist"));
1400
1401
Ref<PListNode> root_node = plist->get_root();
1402
if (root_node.is_null()) {
1403
plist_missing = true;
1404
} else {
1405
Dictionary root = root_node->get_value();
1406
if (!root.has("CFBundleExecutable") || !root.has("CFBundleIdentifier") || !root.has("CFBundlePackageType") || !root.has("CFBundleInfoDictionaryVersion") || !root.has("CFBundleName") || !root.has("CFBundleSupportedPlatforms")) {
1407
plist_missing = true;
1408
}
1409
}
1410
1411
err = dir_access->make_dir_recursive(p_in_app_path);
1412
if (err == OK) {
1413
err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true);
1414
}
1415
if (err == OK && plist_missing) {
1416
add_message(EXPORT_MESSAGE_WARNING, TTR("Export"), vformat(TTR("\"%s\": Info.plist missing or invalid, new Info.plist generated."), p_src_path.get_file()));
1417
// Generate Info.plist
1418
String lib_name = p_src_path.get_basename().get_file();
1419
String lib_id = p_preset->get("application/bundle_identifier");
1420
String lib_clean_name = lib_name;
1421
for (int i = 0; i < lib_clean_name.length(); i++) {
1422
if (!is_ascii_alphanumeric_char(lib_clean_name[i]) && lib_clean_name[i] != '.' && lib_clean_name[i] != '-') {
1423
lib_clean_name[i] = '-';
1424
}
1425
}
1426
1427
String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1428
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
1429
"<plist version=\"1.0\">\n"
1430
" <dict>\n"
1431
" <key>CFBundleExecutable</key>\n"
1432
" <string>$name</string>\n"
1433
" <key>CFBundleIdentifier</key>\n"
1434
" <string>$id.framework.$cl_name</string>\n"
1435
" <key>CFBundleInfoDictionaryVersion</key>\n"
1436
" <string>6.0</string>\n"
1437
" <key>CFBundleName</key>\n"
1438
" <string>$name</string>\n"
1439
" <key>CFBundlePackageType</key>\n"
1440
" <string>FMWK</string>\n"
1441
" <key>CFBundleShortVersionString</key>\n"
1442
" <string>1.0.0</string>\n"
1443
" <key>CFBundleSupportedPlatforms</key>\n"
1444
" <array>\n"
1445
" <string>MacOSX</string>\n"
1446
" </array>\n"
1447
" <key>CFBundleVersion</key>\n"
1448
" <string>1.0.0</string>\n"
1449
" <key>LSMinimumSystemVersion</key>\n"
1450
" <string>10.12</string>\n"
1451
" </dict>\n"
1452
"</plist>";
1453
1454
String info_plist = info_plist_format.replace("$id", lib_id).replace("$name", lib_name).replace("$cl_name", lib_clean_name);
1455
1456
err = dir_access->make_dir_recursive(p_in_app_path.path_join("Resources"));
1457
Ref<FileAccess> f = FileAccess::open(p_in_app_path.path_join("Resources").path_join("Info.plist"), FileAccess::WRITE);
1458
if (f.is_valid()) {
1459
f->store_string(info_plist);
1460
}
1461
}
1462
} else {
1463
print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path);
1464
err = dir_access->copy(p_src_path, p_in_app_path);
1465
}
1466
if (err == OK && p_sign_enabled) {
1467
if (dir_access->dir_exists(p_src_path) && p_src_path.get_extension().is_empty()) {
1468
// If it is a directory, find and sign all dynamic libraries.
1469
_code_sign_directory(p_preset, p_in_app_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code_sign);
1470
} else {
1471
if (extensions_to_sign.has(p_in_app_path.get_extension())) {
1472
String ent_path;
1473
bool set_bundle_id = false;
1474
if (p_sandbox && FileAccess::exists(p_in_app_path)) {
1475
int ftype = MachO::get_filetype(p_in_app_path);
1476
if (ftype == 2 || ftype == 5) {
1477
ent_path = p_helper_ent_path;
1478
set_bundle_id = true;
1479
}
1480
}
1481
_code_sign(p_preset, p_in_app_path, ent_path, false, set_bundle_id);
1482
}
1483
if (dir_access->file_exists(p_in_app_path) && is_executable(p_in_app_path)) {
1484
// chmod with 0755 if the file is executable.
1485
FileAccess::set_unix_permissions(p_in_app_path, 0755);
1486
}
1487
}
1488
}
1489
return err;
1490
}
1491
1492
Error EditorExportPlatformMacOS::_export_macos_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin,
1493
const String &p_app_path_name, Ref<DirAccess> &dir_access,
1494
bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,
1495
const String &p_ent_path, const String &p_helper_ent_path, bool p_sandbox) {
1496
Error error{ OK };
1497
const Vector<String> &macos_plugins{ p_editor_export_plugin->get_macos_plugin_files() };
1498
for (int i = 0; i < macos_plugins.size(); ++i) {
1499
String src_path{ ProjectSettings::get_singleton()->globalize_path(macos_plugins[i]) };
1500
String path_in_app{ p_app_path_name + "/Contents/PlugIns/" + src_path.get_file() };
1501
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, p_sandbox);
1502
if (error != OK) {
1503
break;
1504
}
1505
}
1506
return error;
1507
}
1508
1509
Error EditorExportPlatformMacOS::_create_pkg(const Ref<EditorExportPreset> &p_preset, const String &p_pkg_path, const String &p_app_path_name) {
1510
List<String> args;
1511
1512
if (FileAccess::exists(p_pkg_path)) {
1513
OS::get_singleton()->move_to_trash(p_pkg_path);
1514
}
1515
1516
args.push_back("productbuild");
1517
args.push_back("--component");
1518
args.push_back(p_app_path_name);
1519
args.push_back("/Applications");
1520
String ident = p_preset->get("codesign/installer_identity");
1521
if (!ident.is_empty()) {
1522
args.push_back("--timestamp");
1523
args.push_back("--sign");
1524
args.push_back(ident);
1525
}
1526
args.push_back("--quiet");
1527
args.push_back(p_pkg_path);
1528
1529
String str;
1530
Error err = OS::get_singleton()->execute("xcrun", args, &str, nullptr, true);
1531
if (err != OK) {
1532
add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("Could not start productbuild executable."));
1533
return err;
1534
}
1535
1536
print_verbose("productbuild returned: " + str);
1537
if (str.contains("productbuild: error:")) {
1538
add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("`productbuild` failed."));
1539
return FAILED;
1540
}
1541
1542
return OK;
1543
}
1544
1545
Error EditorExportPlatformMacOS::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
1546
List<String> args;
1547
1548
if (FileAccess::exists(p_dmg_path)) {
1549
OS::get_singleton()->move_to_trash(p_dmg_path);
1550
}
1551
1552
args.push_back("create");
1553
args.push_back(p_dmg_path);
1554
args.push_back("-volname");
1555
args.push_back(p_pkg_name);
1556
args.push_back("-fs");
1557
args.push_back("HFS+");
1558
args.push_back("-srcfolder");
1559
args.push_back(p_app_path_name);
1560
1561
String str;
1562
Error err = OS::get_singleton()->execute("hdiutil", args, &str, nullptr, true);
1563
if (err != OK) {
1564
add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("Could not start hdiutil executable."));
1565
return err;
1566
}
1567
1568
print_verbose("hdiutil returned: " + str);
1569
if (str.contains("create failed")) {
1570
if (str.contains("File exists")) {
1571
add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed - file exists."));
1572
} else {
1573
add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed."));
1574
}
1575
return FAILED;
1576
}
1577
1578
return OK;
1579
}
1580
1581
bool EditorExportPlatformMacOS::is_shebang(const String &p_path) const {
1582
Ref<FileAccess> fb = FileAccess::open(p_path, FileAccess::READ);
1583
ERR_FAIL_COND_V_MSG(fb.is_null(), false, vformat("Can't open file: \"%s\".", p_path));
1584
uint16_t magic = fb->get_16();
1585
return (magic == 0x2123);
1586
}
1587
1588
bool EditorExportPlatformMacOS::is_executable(const String &p_path) const {
1589
return MachO::is_macho(p_path) || LipO::is_lipo(p_path) || is_shebang(p_path);
1590
}
1591
1592
Error EditorExportPlatformMacOS::_export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path) {
1593
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE);
1594
if (f.is_null()) {
1595
add_message(EXPORT_MESSAGE_ERROR, TTR("Debug Script Export"), vformat(TTR("Could not open file \"%s\"."), p_path));
1596
return ERR_CANT_CREATE;
1597
}
1598
1599
f->store_line("#!/bin/sh");
1600
f->store_line("printf '\\033c\\033]0;%s\\a' " + p_app_name);
1601
f->store_line("");
1602
f->store_line("function app_realpath() {");
1603
f->store_line(" SOURCE=$1");
1604
f->store_line(" while [ -h \"$SOURCE\" ]; do");
1605
f->store_line(" DIR=$(dirname \"$SOURCE\")");
1606
f->store_line(" SOURCE=$(readlink \"$SOURCE\")");
1607
f->store_line(" [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE");
1608
f->store_line(" done");
1609
f->store_line(" echo \"$( cd -P \"$( dirname \"$SOURCE\" )\" >/dev/null 2>&1 && pwd )\"");
1610
f->store_line("}");
1611
f->store_line("");
1612
f->store_line("BASE_PATH=\"$(app_realpath \"${BASH_SOURCE[0]}\")\"");
1613
f->store_line("\"$BASE_PATH/" + p_pkg_name + "\" \"$@\"");
1614
f->store_line("");
1615
1616
return OK;
1617
}
1618
1619
Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) {
1620
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
1621
1622
const String base_dir = p_path.get_base_dir();
1623
1624
if (!DirAccess::exists(base_dir)) {
1625
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Target folder does not exist or is inaccessible: \"%s\""), base_dir));
1626
return ERR_FILE_BAD_PATH;
1627
}
1628
1629
EditorProgress ep("export", TTR("Exporting for macOS"), 3, true);
1630
1631
String src_pkg_name;
1632
if (p_debug) {
1633
src_pkg_name = p_preset->get("custom_template/debug");
1634
} else {
1635
src_pkg_name = p_preset->get("custom_template/release");
1636
}
1637
1638
if (src_pkg_name.is_empty()) {
1639
String err;
1640
src_pkg_name = find_export_template("macos.zip", &err);
1641
if (src_pkg_name.is_empty()) {
1642
add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found.") + "\n" + err);
1643
return ERR_FILE_NOT_FOUND;
1644
}
1645
}
1646
1647
Ref<FileAccess> io_fa;
1648
zlib_filefunc_def io = zipio_create_io(&io_fa);
1649
1650
if (ep.step(TTR("Creating app bundle"), 0)) {
1651
return ERR_SKIP;
1652
}
1653
1654
unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
1655
if (!src_pkg_zip) {
1656
add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not find template app to export: \"%s\"."), src_pkg_name));
1657
return ERR_FILE_NOT_FOUND;
1658
}
1659
1660
int ret = unzGoToFirstFile(src_pkg_zip);
1661
1662
String architecture = p_preset->get("binary_format/architecture");
1663
String binary_to_use = "godot_macos_" + String(p_debug ? "debug" : "release") + "." + architecture;
1664
1665
String pkg_name;
1666
if (String(get_project_setting(p_preset, "application/config/name")) != "") {
1667
pkg_name = String(get_project_setting(p_preset, "application/config/name"));
1668
} else {
1669
pkg_name = "Unnamed";
1670
}
1671
pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
1672
1673
String export_format;
1674
if (p_path.ends_with("zip")) {
1675
export_format = "zip";
1676
} else if (p_path.ends_with("app")) {
1677
export_format = "app";
1678
#ifdef MACOS_ENABLED
1679
} else if (p_path.ends_with("dmg")) {
1680
export_format = "dmg";
1681
} else if (p_path.ends_with("pkg")) {
1682
export_format = "pkg";
1683
#endif
1684
} else {
1685
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Invalid export format."));
1686
return ERR_CANT_CREATE;
1687
}
1688
1689
// Create our application bundle.
1690
String tmp_app_dir_name = pkg_name + ".app";
1691
String tmp_base_path_name;
1692
String tmp_app_path_name;
1693
String scr_path;
1694
if (export_format == "app") {
1695
tmp_base_path_name = p_path.get_base_dir();
1696
tmp_app_path_name = p_path;
1697
scr_path = p_path.get_basename() + ".command";
1698
} else {
1699
tmp_base_path_name = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name);
1700
tmp_app_path_name = tmp_base_path_name.path_join(tmp_app_dir_name);
1701
scr_path = tmp_base_path_name.path_join(pkg_name + ".command");
1702
}
1703
1704
print_verbose("Exporting to " + tmp_app_path_name);
1705
1706
Error err = OK;
1707
1708
Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_base_path_name);
1709
if (tmp_app_dir.is_null()) {
1710
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory: \"%s\"."), tmp_base_path_name));
1711
err = ERR_CANT_CREATE;
1712
}
1713
1714
if (FileAccess::exists(scr_path)) {
1715
DirAccess::remove_file_or_error(scr_path);
1716
}
1717
if (DirAccess::exists(tmp_app_path_name)) {
1718
String old_dir = tmp_app_dir->get_current_dir();
1719
if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {
1720
tmp_app_dir->erase_contents_recursive();
1721
tmp_app_dir->change_dir(old_dir);
1722
}
1723
}
1724
1725
Array helpers = p_preset->get("codesign/entitlements/app_sandbox/helper_executables");
1726
1727
// Create our folder structure.
1728
if (err == OK) {
1729
print_verbose("Creating " + tmp_app_path_name + "/Contents/MacOS");
1730
err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
1731
if (err != OK) {
1732
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/MacOS"));
1733
}
1734
}
1735
1736
if (err == OK) {
1737
print_verbose("Creating " + tmp_app_path_name + "/Contents/Frameworks");
1738
err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");
1739
if (err != OK) {
1740
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Frameworks"));
1741
}
1742
}
1743
1744
if ((err == OK) && helpers.size() > 0) {
1745
print_line("Creating " + tmp_app_path_name + "/Contents/Helpers");
1746
err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Helpers");
1747
if (err != OK) {
1748
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Helpers"));
1749
}
1750
}
1751
1752
if (err == OK) {
1753
print_verbose("Creating " + tmp_app_path_name + "/Contents/Resources");
1754
err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
1755
if (err != OK) {
1756
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Resources"));
1757
}
1758
}
1759
1760
Dictionary appnames = get_project_setting(p_preset, "application/config/name_localized");
1761
Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");
1762
Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");
1763
Dictionary location_usage_descriptions = p_preset->get("privacy/location_usage_description_localized");
1764
Dictionary address_book_usage_descriptions = p_preset->get("privacy/address_book_usage_description_localized");
1765
Dictionary calendar_usage_descriptions = p_preset->get("privacy/calendar_usage_description_localized");
1766
Dictionary photos_library_usage_descriptions = p_preset->get("privacy/photos_library_usage_description_localized");
1767
Dictionary desktop_folder_usage_descriptions = p_preset->get("privacy/desktop_folder_usage_description_localized");
1768
Dictionary documents_folder_usage_descriptions = p_preset->get("privacy/documents_folder_usage_description_localized");
1769
Dictionary downloads_folder_usage_descriptions = p_preset->get("privacy/downloads_folder_usage_description_localized");
1770
Dictionary network_volumes_usage_descriptions = p_preset->get("privacy/network_volumes_usage_description_localized");
1771
Dictionary removable_volumes_usage_descriptions = p_preset->get("privacy/removable_volumes_usage_description_localized");
1772
Dictionary copyrights = p_preset->get("application/copyright_localized");
1773
1774
Vector<String> translations = get_project_setting(p_preset, "internationalization/locale/translations");
1775
if (translations.size() > 0) {
1776
{
1777
String fname = tmp_app_path_name + "/Contents/Resources/en.lproj";
1778
tmp_app_dir->make_dir_recursive(fname);
1779
Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
1780
f->store_line("/* Localized versions of Info.plist keys */");
1781
f->store_line("");
1782
f->store_line("CFBundleDisplayName = \"" + get_project_setting(p_preset, "application/config/name").operator String() + "\";");
1783
if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
1784
f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String() + "\";");
1785
}
1786
if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
1787
f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String() + "\";");
1788
}
1789
if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
1790
f->store_line("NSLocationUsageDescription = \"" + p_preset->get("privacy/location_usage_description").operator String() + "\";");
1791
}
1792
if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
1793
f->store_line("NSContactsUsageDescription = \"" + p_preset->get("privacy/address_book_usage_description").operator String() + "\";");
1794
}
1795
if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
1796
f->store_line("NSCalendarsUsageDescription = \"" + p_preset->get("privacy/calendar_usage_description").operator String() + "\";");
1797
}
1798
if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
1799
f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photos_library_usage_description").operator String() + "\";");
1800
}
1801
if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {
1802
f->store_line("NSDesktopFolderUsageDescription = \"" + p_preset->get("privacy/desktop_folder_usage_description").operator String() + "\";");
1803
}
1804
if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {
1805
f->store_line("NSDocumentsFolderUsageDescription = \"" + p_preset->get("privacy/documents_folder_usage_description").operator String() + "\";");
1806
}
1807
if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {
1808
f->store_line("NSDownloadsFolderUsageDescription = \"" + p_preset->get("privacy/downloads_folder_usage_description").operator String() + "\";");
1809
}
1810
if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {
1811
f->store_line("NSNetworkVolumesUsageDescription = \"" + p_preset->get("privacy/network_volumes_usage_description").operator String() + "\";");
1812
}
1813
if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {
1814
f->store_line("NSRemovableVolumesUsageDescription = \"" + p_preset->get("privacy/removable_volumes_usage_description").operator String() + "\";");
1815
}
1816
f->store_line("NSHumanReadableCopyright = \"" + p_preset->get("application/copyright").operator String() + "\";");
1817
}
1818
1819
HashSet<String> languages;
1820
for (const String &E : translations) {
1821
Ref<Translation> tr = ResourceLoader::load(E);
1822
if (tr.is_valid() && tr->get_locale() != "en") {
1823
languages.insert(tr->get_locale());
1824
}
1825
}
1826
1827
for (const String &lang : languages) {
1828
String fname = tmp_app_path_name + "/Contents/Resources/" + lang + ".lproj";
1829
tmp_app_dir->make_dir_recursive(fname);
1830
Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
1831
f->store_line("/* Localized versions of Info.plist keys */");
1832
f->store_line("");
1833
if (appnames.has(lang)) {
1834
f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String() + "\";");
1835
}
1836
if (microphone_usage_descriptions.has(lang)) {
1837
f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String() + "\";");
1838
}
1839
if (camera_usage_descriptions.has(lang)) {
1840
f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String() + "\";");
1841
}
1842
if (location_usage_descriptions.has(lang)) {
1843
f->store_line("NSLocationUsageDescription = \"" + location_usage_descriptions[lang].operator String() + "\";");
1844
}
1845
if (address_book_usage_descriptions.has(lang)) {
1846
f->store_line("NSContactsUsageDescription = \"" + address_book_usage_descriptions[lang].operator String() + "\";");
1847
}
1848
if (calendar_usage_descriptions.has(lang)) {
1849
f->store_line("NSCalendarsUsageDescription = \"" + calendar_usage_descriptions[lang].operator String() + "\";");
1850
}
1851
if (photos_library_usage_descriptions.has(lang)) {
1852
f->store_line("NSPhotoLibraryUsageDescription = \"" + photos_library_usage_descriptions[lang].operator String() + "\";");
1853
}
1854
if (desktop_folder_usage_descriptions.has(lang)) {
1855
f->store_line("NSDesktopFolderUsageDescription = \"" + desktop_folder_usage_descriptions[lang].operator String() + "\";");
1856
}
1857
if (documents_folder_usage_descriptions.has(lang)) {
1858
f->store_line("NSDocumentsFolderUsageDescription = \"" + documents_folder_usage_descriptions[lang].operator String() + "\";");
1859
}
1860
if (downloads_folder_usage_descriptions.has(lang)) {
1861
f->store_line("NSDownloadsFolderUsageDescription = \"" + downloads_folder_usage_descriptions[lang].operator String() + "\";");
1862
}
1863
if (network_volumes_usage_descriptions.has(lang)) {
1864
f->store_line("NSNetworkVolumesUsageDescription = \"" + network_volumes_usage_descriptions[lang].operator String() + "\";");
1865
}
1866
if (removable_volumes_usage_descriptions.has(lang)) {
1867
f->store_line("NSRemovableVolumesUsageDescription = \"" + removable_volumes_usage_descriptions[lang].operator String() + "\";");
1868
}
1869
if (copyrights.has(lang)) {
1870
f->store_line("NSHumanReadableCopyright = \"" + copyrights[lang].operator String() + "\";");
1871
}
1872
}
1873
}
1874
1875
// Now process our template.
1876
bool found_binary = false;
1877
1878
int export_angle = p_preset->get("application/export_angle");
1879
bool include_angle_libs = false;
1880
if (export_angle == 0) {
1881
include_angle_libs = String(get_project_setting(p_preset, "rendering/gl_compatibility/driver.macos")) == "opengl3_angle";
1882
} else if (export_angle == 1) {
1883
include_angle_libs = true;
1884
}
1885
1886
while (ret == UNZ_OK && err == OK) {
1887
// Get filename.
1888
unz_file_info info;
1889
char fname[16384];
1890
ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
1891
if (ret != UNZ_OK) {
1892
break;
1893
}
1894
1895
String file = String::utf8(fname);
1896
1897
Vector<uint8_t> data;
1898
data.resize(info.uncompressed_size);
1899
1900
// Read.
1901
unzOpenCurrentFile(src_pkg_zip);
1902
unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
1903
unzCloseCurrentFile(src_pkg_zip);
1904
1905
// Write.
1906
file = file.replace_first("macos_template.app/", "");
1907
1908
if (((info.external_fa >> 16L) & 0120000) == 0120000) {
1909
#ifndef UNIX_ENABLED
1910
add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Relative symlinks are not supported on this OS, the exported project might be broken!"));
1911
#endif
1912
// Handle symlinks in the archive.
1913
file = tmp_app_path_name.path_join(file);
1914
if (err == OK) {
1915
err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
1916
if (err != OK) {
1917
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));
1918
}
1919
}
1920
if (err == OK) {
1921
String lnk_data = String::utf8((const char *)data.ptr(), data.size());
1922
err = tmp_app_dir->create_link(lnk_data, file);
1923
if (err != OK) {
1924
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not created symlink \"%s\" -> \"%s\"."), lnk_data, file));
1925
}
1926
print_verbose(vformat("ADDING SYMLINK %s => %s\n", file, lnk_data));
1927
}
1928
1929
ret = unzGoToNextFile(src_pkg_zip);
1930
continue; // next
1931
}
1932
1933
if (file == "Contents/Frameworks/libEGL.dylib") {
1934
if (!include_angle_libs) {
1935
ret = unzGoToNextFile(src_pkg_zip);
1936
continue; // skip
1937
}
1938
}
1939
1940
if (file == "Contents/Frameworks/libGLESv2.dylib") {
1941
if (!include_angle_libs) {
1942
ret = unzGoToNextFile(src_pkg_zip);
1943
continue; // skip
1944
}
1945
}
1946
1947
if (file == "Contents/Info.plist") {
1948
bool lg_icon_expored = false;
1949
String lg_icon = p_preset->get("application/liquid_glass_icon");
1950
#ifdef MACOS_ENABLED
1951
// Export liquid glass.
1952
if (!lg_icon.is_empty()) {
1953
lg_icon_expored = (_export_liquid_glass_icon(p_preset, tmp_app_path_name, lg_icon) == OK);
1954
}
1955
#endif
1956
// Modify plist.
1957
_fix_plist(p_preset, data, pkg_name, lg_icon_expored, lg_icon.get_file().get_basename());
1958
}
1959
1960
if (file == "Contents/Resources/PrivacyInfo.xcprivacy") {
1961
_fix_privacy_manifest(p_preset, data);
1962
}
1963
1964
if (file.begins_with("Contents/MacOS/godot_")) {
1965
if (file != "Contents/MacOS/" + binary_to_use) {
1966
ret = unzGoToNextFile(src_pkg_zip);
1967
continue; // skip
1968
}
1969
found_binary = true;
1970
file = "Contents/MacOS/" + pkg_name;
1971
}
1972
1973
if (file == "Contents/Resources/icon.icns") {
1974
// See if there is an icon.
1975
String icon_path;
1976
if (p_preset->get("application/icon") != "") {
1977
icon_path = p_preset->get("application/icon");
1978
} else if (get_project_setting(p_preset, "application/config/macos_native_icon") != "") {
1979
icon_path = get_project_setting(p_preset, "application/config/macos_native_icon");
1980
} else {
1981
icon_path = get_project_setting(p_preset, "application/config/icon");
1982
}
1983
1984
if (!icon_path.is_empty()) {
1985
if (icon_path.get_extension() == "icns") {
1986
Ref<FileAccess> icon = FileAccess::open(icon_path, FileAccess::READ);
1987
if (icon.is_valid()) {
1988
data.resize(icon->get_length());
1989
icon->get_buffer(&data.write[0], icon->get_length());
1990
}
1991
} else {
1992
Ref<Image> icon = _load_icon_or_splash_image(icon_path, &err);
1993
if (err == OK && icon.is_valid() && !icon->is_empty()) {
1994
_make_icon(p_preset, icon, data);
1995
}
1996
}
1997
}
1998
}
1999
2000
if (data.size() > 0) {
2001
print_verbose("ADDING: " + file + " size: " + itos(data.size()));
2002
2003
// Write it into our application bundle.
2004
file = tmp_app_path_name.path_join(file);
2005
if (err == OK) {
2006
err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
2007
if (err != OK) {
2008
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));
2009
}
2010
}
2011
if (err == OK) {
2012
Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);
2013
if (f.is_valid()) {
2014
f->store_buffer(data.ptr(), data.size());
2015
f.unref();
2016
if (is_executable(file)) {
2017
// chmod with 0755 if the file is executable.
2018
FileAccess::set_unix_permissions(file, 0755);
2019
#ifndef UNIX_ENABLED
2020
if (export_format == "app") {
2021
add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Unable to set Unix permissions for executable \"%s\". Use \"chmod +x\" to set it after transferring the exported .app to macOS or Linux."), "Contents/MacOS/" + file.get_file()));
2022
}
2023
#endif
2024
}
2025
} else {
2026
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not open \"%s\"."), file));
2027
err = ERR_CANT_CREATE;
2028
}
2029
}
2030
}
2031
2032
ret = unzGoToNextFile(src_pkg_zip);
2033
}
2034
2035
// We're done with our source zip.
2036
unzClose(src_pkg_zip);
2037
2038
if (!found_binary) {
2039
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Requested template binary \"%s\" not found. It might be missing from your template archive."), binary_to_use));
2040
err = ERR_FILE_NOT_FOUND;
2041
}
2042
2043
// Save console wrapper.
2044
if (err == OK) {
2045
int con_scr = p_preset->get("debug/export_console_wrapper");
2046
if ((con_scr == 1 && p_debug) || (con_scr == 2)) {
2047
err = _export_debug_script(p_preset, pkg_name, tmp_app_path_name.get_file() + "/Contents/MacOS/" + pkg_name, scr_path);
2048
FileAccess::set_unix_permissions(scr_path, 0755);
2049
#ifndef UNIX_ENABLED
2050
if (export_format == "app") {
2051
add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Unable to set Unix permissions for executable \"%s\". Use \"chmod +x\" to set it after transferring the exported .app to macOS or Linux."), scr_path.get_file()));
2052
}
2053
#endif
2054
if (err != OK) {
2055
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not create console wrapper."));
2056
}
2057
}
2058
}
2059
2060
if (err == OK) {
2061
if (ep.step(TTR("Making PKG"), 1)) {
2062
return ERR_SKIP;
2063
}
2064
2065
// See if we can code sign our new package.
2066
bool sign_enabled = (p_preset->get("codesign/codesign").operator int() > 0);
2067
bool ad_hoc = false;
2068
int codesign_tool = p_preset->get("codesign/codesign");
2069
switch (codesign_tool) {
2070
case 1: { // built-in ad-hoc
2071
ad_hoc = true;
2072
} break;
2073
case 2: { // "rcodesign"
2074
ad_hoc = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty() || p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS).operator String().is_empty();
2075
} break;
2076
#ifdef MACOS_ENABLED
2077
case 3: { // "codesign"
2078
ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
2079
} break;
2080
#endif
2081
default: {
2082
};
2083
}
2084
2085
String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
2086
Vector<SharedObject> shared_objects;
2087
err = save_pack(p_preset, p_debug, pack_path, &shared_objects);
2088
2089
bool lib_validation = p_preset->get("codesign/entitlements/disable_library_validation");
2090
if (!shared_objects.is_empty() && sign_enabled && ad_hoc && !lib_validation) {
2091
add_message(EXPORT_MESSAGE_INFO, TTR("Entitlements Modified"), TTR("Ad-hoc signed applications require the 'Disable Library Validation' entitlement to load dynamic libraries."));
2092
lib_validation = true;
2093
}
2094
2095
if (!shared_objects.is_empty() && sign_enabled && codesign_tool == 2) {
2096
add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("'rcodesign' doesn't support signing applications with embedded dynamic libraries."));
2097
}
2098
2099
bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");
2100
String ent_path = p_preset->get("codesign/entitlements/custom_file");
2101
String hlp_ent_path = sandbox ? EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + "_helper.entitlements") : ent_path;
2102
if (sign_enabled && (ent_path.is_empty())) {
2103
ent_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".entitlements");
2104
2105
Ref<FileAccess> ent_f = FileAccess::open(ent_path, FileAccess::WRITE);
2106
if (ent_f.is_valid()) {
2107
ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
2108
ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
2109
ent_f->store_line("<plist version=\"1.0\">");
2110
ent_f->store_line("<dict>");
2111
if (ClassDB::class_exists("CSharpScript")) {
2112
// These entitlements are required to run managed code, and are always enabled in Mono builds.
2113
ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
2114
ent_f->store_line("<true/>");
2115
ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
2116
ent_f->store_line("<true/>");
2117
ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
2118
ent_f->store_line("<true/>");
2119
} else {
2120
if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) {
2121
ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
2122
ent_f->store_line("<true/>");
2123
}
2124
if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) {
2125
ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
2126
ent_f->store_line("<true/>");
2127
}
2128
if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) {
2129
ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
2130
ent_f->store_line("<true/>");
2131
}
2132
}
2133
2134
if (lib_validation) {
2135
ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>");
2136
ent_f->store_line("<true/>");
2137
}
2138
if ((bool)p_preset->get("codesign/entitlements/audio_input")) {
2139
ent_f->store_line("<key>com.apple.security.device.audio-input</key>");
2140
ent_f->store_line("<true/>");
2141
}
2142
if ((bool)p_preset->get("codesign/entitlements/camera")) {
2143
ent_f->store_line("<key>com.apple.security.device.camera</key>");
2144
ent_f->store_line("<true/>");
2145
}
2146
if ((bool)p_preset->get("codesign/entitlements/location")) {
2147
ent_f->store_line("<key>com.apple.security.personal-information.location</key>");
2148
ent_f->store_line("<true/>");
2149
}
2150
if ((bool)p_preset->get("codesign/entitlements/address_book")) {
2151
ent_f->store_line("<key>com.apple.security.personal-information.addressbook</key>");
2152
ent_f->store_line("<true/>");
2153
}
2154
if ((bool)p_preset->get("codesign/entitlements/calendars")) {
2155
ent_f->store_line("<key>com.apple.security.personal-information.calendars</key>");
2156
ent_f->store_line("<true/>");
2157
}
2158
if ((bool)p_preset->get("codesign/entitlements/photos_library")) {
2159
ent_f->store_line("<key>com.apple.security.personal-information.photos-library</key>");
2160
ent_f->store_line("<true/>");
2161
}
2162
if ((bool)p_preset->get("codesign/entitlements/apple_events")) {
2163
ent_f->store_line("<key>com.apple.security.automation.apple-events</key>");
2164
ent_f->store_line("<true/>");
2165
}
2166
if ((bool)p_preset->get("codesign/entitlements/debugging")) {
2167
ent_f->store_line("<key>com.apple.security.get-task-allow</key>");
2168
ent_f->store_line("<true/>");
2169
}
2170
2171
int dist_type = p_preset->get("export/distribution_type");
2172
if (dist_type == 2) {
2173
String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE);
2174
String teamid = p_preset->get("codesign/apple_team_id");
2175
String bid = p_preset->get("application/bundle_identifier");
2176
if (!pprof.is_empty() && !teamid.is_empty()) {
2177
ent_f->store_line("<key>com.apple.developer.team-identifier</key>");
2178
ent_f->store_line("<string>" + teamid + "</string>");
2179
ent_f->store_line("<key>com.apple.application-identifier</key>");
2180
ent_f->store_line("<string>" + teamid + "." + bid + "</string>");
2181
}
2182
}
2183
2184
if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) {
2185
ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
2186
ent_f->store_line("<true/>");
2187
2188
if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) {
2189
ent_f->store_line("<key>com.apple.security.network.server</key>");
2190
ent_f->store_line("<true/>");
2191
}
2192
if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) {
2193
ent_f->store_line("<key>com.apple.security.network.client</key>");
2194
ent_f->store_line("<true/>");
2195
}
2196
if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) {
2197
ent_f->store_line("<key>com.apple.security.device.usb</key>");
2198
ent_f->store_line("<true/>");
2199
}
2200
if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) {
2201
ent_f->store_line("<key>com.apple.security.device.bluetooth</key>");
2202
ent_f->store_line("<true/>");
2203
}
2204
if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) {
2205
ent_f->store_line("<key>com.apple.security.files.downloads.read-only</key>");
2206
ent_f->store_line("<true/>");
2207
}
2208
if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) {
2209
ent_f->store_line("<key>com.apple.security.files.downloads.read-write</key>");
2210
ent_f->store_line("<true/>");
2211
}
2212
if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) {
2213
ent_f->store_line("<key>com.apple.security.files.pictures.read-only</key>");
2214
ent_f->store_line("<true/>");
2215
}
2216
if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) {
2217
ent_f->store_line("<key>com.apple.security.files.pictures.read-write</key>");
2218
ent_f->store_line("<true/>");
2219
}
2220
if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) {
2221
ent_f->store_line("<key>com.apple.security.files.music.read-only</key>");
2222
ent_f->store_line("<true/>");
2223
}
2224
if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) {
2225
ent_f->store_line("<key>com.apple.security.files.music.read-write</key>");
2226
ent_f->store_line("<true/>");
2227
}
2228
if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) {
2229
ent_f->store_line("<key>com.apple.security.files.movies.read-only</key>");
2230
ent_f->store_line("<true/>");
2231
}
2232
if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) {
2233
ent_f->store_line("<key>com.apple.security.files.movies.read-write</key>");
2234
ent_f->store_line("<true/>");
2235
}
2236
if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 1) {
2237
ent_f->store_line("<key>com.apple.security.files.user-selected.read-only</key>");
2238
ent_f->store_line("<true/>");
2239
}
2240
if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 2) {
2241
ent_f->store_line("<key>com.apple.security.files.user-selected.read-write</key>");
2242
ent_f->store_line("<true/>");
2243
}
2244
}
2245
2246
const String &additional_entitlements = p_preset->get("codesign/entitlements/additional");
2247
if (!additional_entitlements.is_empty()) {
2248
ent_f->store_line(additional_entitlements);
2249
}
2250
2251
ent_f->store_line("</dict>");
2252
ent_f->store_line("</plist>");
2253
} else {
2254
add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create entitlements file."));
2255
err = ERR_CANT_CREATE;
2256
}
2257
2258
if ((err == OK) && sandbox && (helpers.size() > 0 || shared_objects.size() > 0)) {
2259
ent_f = FileAccess::open(hlp_ent_path, FileAccess::WRITE);
2260
if (ent_f.is_valid()) {
2261
ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
2262
ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
2263
ent_f->store_line("<plist version=\"1.0\">");
2264
ent_f->store_line("<dict>");
2265
ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
2266
ent_f->store_line("<true/>");
2267
ent_f->store_line("<key>com.apple.security.inherit</key>");
2268
ent_f->store_line("<true/>");
2269
ent_f->store_line("</dict>");
2270
ent_f->store_line("</plist>");
2271
} else {
2272
add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create helper entitlements file."));
2273
err = ERR_CANT_CREATE;
2274
}
2275
}
2276
}
2277
2278
if ((err == OK) && helpers.size() > 0) {
2279
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
2280
for (int i = 0; i < helpers.size(); i++) {
2281
String hlp_path = helpers[i];
2282
err = da->copy(hlp_path, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file());
2283
if (err == OK && sign_enabled) {
2284
_code_sign(p_preset, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), hlp_ent_path, false, true);
2285
}
2286
FileAccess::set_unix_permissions(tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), 0755);
2287
#ifndef UNIX_ENABLED
2288
if (export_format == "app") {
2289
add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Unable to set Unix permissions for executable \"%s\". Use \"chmod +x\" to set it after transferring the exported .app to macOS or Linux."), "Contents/Helpers/" + hlp_path.get_file()));
2290
}
2291
#endif
2292
}
2293
}
2294
2295
if (err == OK) {
2296
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
2297
for (int i = 0; i < shared_objects.size(); i++) {
2298
String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path);
2299
if (shared_objects[i].target.is_empty()) {
2300
String path_in_app = tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file();
2301
err = _copy_and_sign_files(da, src_path, path_in_app, sign_enabled, p_preset, ent_path, hlp_ent_path, true, sandbox);
2302
} else {
2303
String path_in_app = tmp_app_path_name.path_join(shared_objects[i].target);
2304
tmp_app_dir->make_dir_recursive(path_in_app);
2305
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, sandbox);
2306
}
2307
if (err != OK) {
2308
break;
2309
}
2310
}
2311
2312
Vector<Ref<EditorExportPlugin>> export_plugins{ EditorExport::get_singleton()->get_export_plugins() };
2313
for (int i = 0; i < export_plugins.size(); ++i) {
2314
err = _export_macos_plugins_for(export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path, hlp_ent_path, sandbox);
2315
if (err != OK) {
2316
break;
2317
}
2318
}
2319
}
2320
2321
if (err == OK && sign_enabled) {
2322
int dist_type = p_preset->get("export/distribution_type");
2323
if (dist_type == 2) {
2324
String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE).operator String();
2325
if (!pprof.is_empty()) {
2326
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
2327
err = da->copy(pprof, tmp_app_path_name + "/Contents/embedded.provisionprofile");
2328
}
2329
}
2330
2331
if (ep.step(TTR("Code signing bundle"), 2)) {
2332
return ERR_SKIP;
2333
}
2334
_code_sign(p_preset, tmp_app_path_name, ent_path, true, false);
2335
}
2336
2337
String noto_path = p_path;
2338
bool noto_enabled = (p_preset->get("notarization/notarization").operator int() > 0);
2339
if (export_format == "dmg") {
2340
// Create a DMG.
2341
if (err == OK) {
2342
if (ep.step(TTR("Making DMG"), 3)) {
2343
return ERR_SKIP;
2344
}
2345
err = _create_dmg(p_path, pkg_name, tmp_base_path_name);
2346
}
2347
// Sign DMG.
2348
if (err == OK && sign_enabled && !ad_hoc) {
2349
if (ep.step(TTR("Code signing DMG"), 3)) {
2350
return ERR_SKIP;
2351
}
2352
_code_sign(p_preset, p_path, ent_path, false, false);
2353
}
2354
} else if (export_format == "pkg") {
2355
// Create a Installer.
2356
if (err == OK) {
2357
if (ep.step(TTR("Making PKG installer"), 3)) {
2358
return ERR_SKIP;
2359
}
2360
err = _create_pkg(p_preset, p_path, tmp_app_path_name);
2361
}
2362
} else if (export_format == "zip") {
2363
// Create ZIP.
2364
if (err == OK) {
2365
if (ep.step(TTR("Making ZIP"), 3)) {
2366
return ERR_SKIP;
2367
}
2368
if (FileAccess::exists(p_path)) {
2369
OS::get_singleton()->move_to_trash(p_path);
2370
}
2371
2372
Ref<FileAccess> io_fa_dst;
2373
zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);
2374
zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
2375
2376
zip_folder_recursive(zip, tmp_base_path_name, "", pkg_name);
2377
2378
zipClose(zip, nullptr);
2379
}
2380
} else if (export_format == "app" && noto_enabled) {
2381
// Create temporary ZIP.
2382
if (err == OK) {
2383
noto_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".zip");
2384
2385
if (ep.step(TTR("Making ZIP"), 3)) {
2386
return ERR_SKIP;
2387
}
2388
if (FileAccess::exists(noto_path)) {
2389
OS::get_singleton()->move_to_trash(noto_path);
2390
}
2391
2392
Ref<FileAccess> io_fa_dst;
2393
zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);
2394
zipFile zip = zipOpen2(noto_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
2395
2396
zip_folder_recursive(zip, tmp_base_path_name, tmp_app_dir_name, pkg_name);
2397
2398
zipClose(zip, nullptr);
2399
}
2400
}
2401
2402
if (err == OK && noto_enabled) {
2403
if (export_format == "pkg") {
2404
add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("Notarization requires the app to be archived first, select the DMG or ZIP export format instead."));
2405
} else {
2406
if (ep.step(TTR("Sending archive for notarization"), 4)) {
2407
return ERR_SKIP;
2408
}
2409
err = _notarize(p_preset, noto_path);
2410
}
2411
}
2412
2413
if (FileAccess::exists(ent_path)) {
2414
print_verbose("entitlements:\n" + FileAccess::get_file_as_string(ent_path));
2415
}
2416
2417
if (FileAccess::exists(hlp_ent_path)) {
2418
print_verbose("helper entitlements:\n" + FileAccess::get_file_as_string(hlp_ent_path));
2419
}
2420
2421
// Clean up temporary entitlements files.
2422
if (FileAccess::exists(hlp_ent_path)) {
2423
DirAccess::remove_file_or_error(hlp_ent_path);
2424
}
2425
2426
// Clean up temporary .app dir and generated entitlements.
2427
if ((String)(p_preset->get("codesign/entitlements/custom_file")) == "") {
2428
tmp_app_dir->remove(ent_path);
2429
}
2430
if (export_format != "app") {
2431
if (tmp_app_dir->change_dir(tmp_base_path_name) == OK) {
2432
tmp_app_dir->erase_contents_recursive();
2433
tmp_app_dir->change_dir("..");
2434
tmp_app_dir->remove(pkg_name);
2435
}
2436
} else if (noto_path != p_path) {
2437
if (FileAccess::exists(noto_path)) {
2438
DirAccess::remove_file_or_error(noto_path);
2439
}
2440
}
2441
}
2442
2443
return err;
2444
}
2445
2446
bool EditorExportPlatformMacOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {
2447
String err;
2448
// Look for export templates (official templates first, then custom).
2449
bool dvalid = exists_export_template("macos.zip", &err);
2450
bool rvalid = dvalid; // Both in the same ZIP.
2451
2452
if (p_preset->get("custom_template/debug") != "") {
2453
dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
2454
if (!dvalid) {
2455
err += TTR("Custom debug template not found.") + "\n";
2456
}
2457
}
2458
if (p_preset->get("custom_template/release") != "") {
2459
rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
2460
if (!rvalid) {
2461
err += TTR("Custom release template not found.") + "\n";
2462
}
2463
}
2464
2465
bool valid = dvalid || rvalid;
2466
r_missing_templates = !valid;
2467
2468
// Check the texture formats, which vary depending on the target architecture.
2469
String architecture = p_preset->get("binary_format/architecture");
2470
if (architecture == "universal" || architecture == "x86_64") {
2471
if (!ResourceImporterTextureSettings::should_import_s3tc_bptc()) {
2472
err += TTR("Cannot export for universal or x86_64 if S3TC BPTC texture format is disabled. Enable it in the Project Settings (Rendering > Textures > VRAM Compression > Import S3TC BPTC).") + "\n";
2473
valid = false;
2474
}
2475
}
2476
if (architecture == "universal" || architecture == "arm64") {
2477
if (!ResourceImporterTextureSettings::should_import_etc2_astc()) {
2478
err += TTR("Cannot export for universal or arm64 if ETC2 ASTC texture format is disabled. Enable it in the Project Settings (Rendering > Textures > VRAM Compression > Import ETC2 ASTC).") + "\n";
2479
valid = false;
2480
}
2481
}
2482
if (architecture != "universal" && architecture != "x86_64" && architecture != "arm64") {
2483
ERR_PRINT("Invalid architecture");
2484
}
2485
2486
if (!err.is_empty()) {
2487
r_error = err;
2488
}
2489
return valid;
2490
}
2491
2492
bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
2493
String err;
2494
bool valid = true;
2495
2496
int dist_type = p_preset->get("export/distribution_type");
2497
bool ad_hoc = false;
2498
int codesign_tool = p_preset->get("codesign/codesign");
2499
int notary_tool = p_preset->get("notarization/notarization");
2500
switch (codesign_tool) {
2501
case 1: { // built-in ad-hoc
2502
ad_hoc = true;
2503
} break;
2504
case 2: { // "rcodesign"
2505
ad_hoc = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty() || p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS).operator String().is_empty();
2506
} break;
2507
#ifdef MACOS_ENABLED
2508
case 3: { // "codesign"
2509
ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
2510
} break;
2511
#endif
2512
default: {
2513
};
2514
}
2515
2516
const String &additional_plist_content = p_preset->get("application/additional_plist_content");
2517
if (!additional_plist_content.is_empty()) {
2518
const String &plist = vformat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
2519
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
2520
"<plist version=\"1.0\">"
2521
"<dict>\n"
2522
"%s\n"
2523
"</dict>\n"
2524
"</plist>\n",
2525
additional_plist_content);
2526
2527
String plist_err;
2528
Ref<PList> plist_parser;
2529
plist_parser.instantiate();
2530
if (!plist_parser->load_string(plist, plist_err)) {
2531
err += TTR("Invalid additional PList content: ") + plist_err + "\n";
2532
valid = false;
2533
}
2534
}
2535
2536
List<ExportOption> options;
2537
get_export_options(&options);
2538
for (const EditorExportPlatform::ExportOption &E : options) {
2539
if (get_export_option_visibility(p_preset.ptr(), E.option.name)) {
2540
String warn = get_export_option_warning(p_preset.ptr(), E.option.name);
2541
if (!warn.is_empty()) {
2542
err += warn + "\n";
2543
if (E.required) {
2544
valid = false;
2545
}
2546
}
2547
}
2548
}
2549
2550
if (dist_type != 2) {
2551
if (notary_tool > 0) {
2552
if (notary_tool == 2 || notary_tool == 3) {
2553
if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {
2554
err += TTR("Notarization: Xcode command line tools are not installed.") + "\n";
2555
valid = false;
2556
}
2557
} else if (notary_tool == 1) {
2558
String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
2559
if (rcodesign.is_empty()) {
2560
err += TTR("Notarization: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";
2561
valid = false;
2562
}
2563
}
2564
} else {
2565
err += TTR("Warning: Notarization is disabled. The exported project will be blocked by Gatekeeper if it's downloaded from an unknown source.") + "\n";
2566
if (codesign_tool == 0) {
2567
err += TTR("Code signing is disabled. The exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n";
2568
}
2569
}
2570
}
2571
2572
if (codesign_tool > 0) {
2573
if (ad_hoc) {
2574
err += TTR("Code signing: Using ad-hoc signature. The exported project will be blocked by Gatekeeper") + "\n";
2575
}
2576
if (codesign_tool == 3) {
2577
if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
2578
err += TTR("Code signing: Xcode command line tools are not installed.") + "\n";
2579
valid = false;
2580
}
2581
} else if (codesign_tool == 2) {
2582
String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
2583
if (rcodesign.is_empty()) {
2584
err += TTR("Code signing: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";
2585
valid = false;
2586
}
2587
}
2588
}
2589
2590
if (!err.is_empty()) {
2591
r_error = err;
2592
}
2593
return valid;
2594
}
2595
2596
Ref<Texture2D> EditorExportPlatformMacOS::get_run_icon() const {
2597
return run_icon;
2598
}
2599
2600
bool EditorExportPlatformMacOS::poll_export() {
2601
Ref<EditorExportPreset> preset;
2602
2603
for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
2604
Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
2605
if (ep->is_runnable() && ep->get_platform() == this) {
2606
preset = ep;
2607
break;
2608
}
2609
}
2610
2611
int prev = menu_options;
2612
menu_options = (preset.is_valid() && preset->get("ssh_remote_deploy/enabled").operator bool());
2613
if (ssh_pid != 0 || !cleanup_commands.is_empty()) {
2614
if (menu_options == 0) {
2615
cleanup();
2616
} else {
2617
menu_options += 1;
2618
}
2619
}
2620
return menu_options != prev;
2621
}
2622
2623
Ref<Texture2D> EditorExportPlatformMacOS::get_option_icon(int p_index) const {
2624
if (p_index == 1) {
2625
return stop_icon;
2626
} else {
2627
return EditorExportPlatform::get_option_icon(p_index);
2628
}
2629
}
2630
2631
int EditorExportPlatformMacOS::get_options_count() const {
2632
return menu_options;
2633
}
2634
2635
String EditorExportPlatformMacOS::get_option_label(int p_index) const {
2636
return (p_index) ? TTR("Stop and uninstall") : TTR("Run on remote macOS system");
2637
}
2638
2639
String EditorExportPlatformMacOS::get_option_tooltip(int p_index) const {
2640
return (p_index) ? TTR("Stop and uninstall running project from the remote system") : TTR("Run exported project on remote macOS system");
2641
}
2642
2643
void EditorExportPlatformMacOS::cleanup() {
2644
if (ssh_pid != 0 && OS::get_singleton()->is_process_running(ssh_pid)) {
2645
print_line("Terminating connection...");
2646
OS::get_singleton()->kill(ssh_pid);
2647
OS::get_singleton()->delay_usec(1000);
2648
}
2649
2650
if (!cleanup_commands.is_empty()) {
2651
print_line("Stopping and deleting previous version...");
2652
for (const SSHCleanupCommand &cmd : cleanup_commands) {
2653
if (cmd.wait) {
2654
ssh_run_on_remote(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
2655
} else {
2656
ssh_run_on_remote_no_wait(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
2657
}
2658
}
2659
}
2660
ssh_pid = 0;
2661
cleanup_commands.clear();
2662
}
2663
2664
Error EditorExportPlatformMacOS::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) {
2665
cleanup();
2666
if (p_device) { // Stop command, cleanup only.
2667
return OK;
2668
}
2669
2670
EditorProgress ep("run", TTR("Running..."), 5);
2671
2672
const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("macos");
2673
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
2674
if (!da->dir_exists(dest)) {
2675
Error err = da->make_dir_recursive(dest);
2676
if (err != OK) {
2677
EditorNode::get_singleton()->show_warning(TTR("Could not create temp directory:") + "\n" + dest);
2678
return err;
2679
}
2680
}
2681
2682
String pkg_name;
2683
if (String(get_project_setting(p_preset, "application/config/name")) != "") {
2684
pkg_name = String(get_project_setting(p_preset, "application/config/name"));
2685
} else {
2686
pkg_name = "Unnamed";
2687
}
2688
pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
2689
2690
String host = p_preset->get("ssh_remote_deploy/host").operator String();
2691
String port = p_preset->get("ssh_remote_deploy/port").operator String();
2692
if (port.is_empty()) {
2693
port = "22";
2694
}
2695
Vector<String> extra_args_ssh = p_preset->get("ssh_remote_deploy/extra_args_ssh").operator String().split(" ", false);
2696
Vector<String> extra_args_scp = p_preset->get("ssh_remote_deploy/extra_args_scp").operator String().split(" ", false);
2697
2698
const String basepath = dest.path_join("tmp_macos_export");
2699
2700
#define CLEANUP_AND_RETURN(m_err) \
2701
{ \
2702
if (da->file_exists(basepath + ".zip")) { \
2703
da->remove(basepath + ".zip"); \
2704
} \
2705
if (da->file_exists(basepath + "_start.sh")) { \
2706
da->remove(basepath + "_start.sh"); \
2707
} \
2708
if (da->file_exists(basepath + "_clean.sh")) { \
2709
da->remove(basepath + "_clean.sh"); \
2710
} \
2711
return m_err; \
2712
} \
2713
((void)0)
2714
2715
if (ep.step(TTR("Exporting project..."), 1)) {
2716
return ERR_SKIP;
2717
}
2718
Error err = export_project(p_preset, true, basepath + ".zip", p_debug_flags);
2719
if (err != OK) {
2720
DirAccess::remove_file_or_error(basepath + ".zip");
2721
return err;
2722
}
2723
2724
String cmd_args;
2725
{
2726
Vector<String> cmd_args_list = gen_export_flags(p_debug_flags);
2727
for (int i = 0; i < cmd_args_list.size(); i++) {
2728
if (i != 0) {
2729
cmd_args += " ";
2730
}
2731
cmd_args += cmd_args_list[i];
2732
}
2733
}
2734
2735
const bool use_remote = p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG) || p_debug_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT);
2736
int dbg_port = EDITOR_GET("network/debug/remote_port");
2737
2738
print_line("Creating temporary directory...");
2739
ep.step(TTR("Creating temporary directory..."), 2);
2740
String temp_dir;
2741
err = ssh_run_on_remote(host, port, extra_args_ssh, "mktemp -d", &temp_dir);
2742
if (err != OK || temp_dir.is_empty()) {
2743
CLEANUP_AND_RETURN(err);
2744
}
2745
2746
print_line("Uploading archive...");
2747
ep.step(TTR("Uploading archive..."), 3);
2748
err = ssh_push_to_remote(host, port, extra_args_scp, basepath + ".zip", temp_dir);
2749
if (err != OK) {
2750
CLEANUP_AND_RETURN(err);
2751
}
2752
2753
{
2754
String run_script = p_preset->get("ssh_remote_deploy/run_script");
2755
run_script = run_script.replace("{temp_dir}", temp_dir);
2756
run_script = run_script.replace("{archive_name}", basepath.get_file() + ".zip");
2757
run_script = run_script.replace("{exe_name}", pkg_name);
2758
run_script = run_script.replace("{cmd_args}", cmd_args);
2759
2760
Ref<FileAccess> f = FileAccess::open(basepath + "_start.sh", FileAccess::WRITE);
2761
if (f.is_null()) {
2762
CLEANUP_AND_RETURN(err);
2763
}
2764
2765
f->store_string(run_script);
2766
}
2767
2768
{
2769
String clean_script = p_preset->get("ssh_remote_deploy/cleanup_script");
2770
clean_script = clean_script.replace("{temp_dir}", temp_dir);
2771
clean_script = clean_script.replace("{archive_name}", basepath.get_file() + ".zip");
2772
clean_script = clean_script.replace("{exe_name}", pkg_name);
2773
clean_script = clean_script.replace("{cmd_args}", cmd_args);
2774
2775
Ref<FileAccess> f = FileAccess::open(basepath + "_clean.sh", FileAccess::WRITE);
2776
if (f.is_null()) {
2777
CLEANUP_AND_RETURN(err);
2778
}
2779
2780
f->store_string(clean_script);
2781
}
2782
2783
print_line("Uploading scripts...");
2784
ep.step(TTR("Uploading scripts..."), 4);
2785
err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_start.sh", temp_dir);
2786
if (err != OK) {
2787
CLEANUP_AND_RETURN(err);
2788
}
2789
err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_start.sh"));
2790
if (err != OK || temp_dir.is_empty()) {
2791
CLEANUP_AND_RETURN(err);
2792
}
2793
err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_clean.sh", temp_dir);
2794
if (err != OK) {
2795
CLEANUP_AND_RETURN(err);
2796
}
2797
err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh"));
2798
if (err != OK || temp_dir.is_empty()) {
2799
CLEANUP_AND_RETURN(err);
2800
}
2801
2802
print_line("Starting project...");
2803
ep.step(TTR("Starting project..."), 5);
2804
err = ssh_run_on_remote_no_wait(host, port, extra_args_ssh, vformat("\"%s/%s\"", temp_dir, basepath.get_file() + "_start.sh"), &ssh_pid, (use_remote) ? dbg_port : -1);
2805
if (err != OK) {
2806
CLEANUP_AND_RETURN(err);
2807
}
2808
2809
cleanup_commands.clear();
2810
cleanup_commands.push_back(SSHCleanupCommand(host, port, extra_args_ssh, vformat("\"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh")));
2811
2812
print_line("Project started.");
2813
2814
CLEANUP_AND_RETURN(OK);
2815
#undef CLEANUP_AND_RETURN
2816
}
2817
2818
void EditorExportPlatformMacOS::initialize() {
2819
if (EditorNode::get_singleton()) {
2820
Ref<Image> img = memnew(Image);
2821
const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
2822
2823
ImageLoaderSVG::create_image_from_string(img, _macos_logo_svg, EDSCALE, upsample, false);
2824
logo = ImageTexture::create_from_image(img);
2825
2826
ImageLoaderSVG::create_image_from_string(img, _macos_run_icon_svg, EDSCALE, upsample, false);
2827
run_icon = ImageTexture::create_from_image(img);
2828
2829
Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
2830
if (theme.is_valid()) {
2831
stop_icon = theme->get_icon(SNAME("Stop"), EditorStringName(EditorIcons));
2832
} else {
2833
stop_icon.instantiate();
2834
}
2835
}
2836
}
2837
2838