@@ -61,6 +61,20 @@ Error EditorExportPlatformLinuxBSD::_export_debug_script(const Ref<EditorExportP
61
61
}
62
62
63
63
Error EditorExportPlatformLinuxBSD::export_project (const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
64
+ String custom_debug = p_preset->get (" custom_template/debug" );
65
+ String custom_release = p_preset->get (" custom_template/release" );
66
+ String arch = p_preset->get (" binary_format/architecture" );
67
+
68
+ String template_path = p_debug ? custom_debug : custom_release;
69
+ template_path = template_path.strip_edges ();
70
+ if (!template_path.is_empty ()) {
71
+ String exe_arch = _get_exe_arch (template_path);
72
+ if (arch != exe_arch) {
73
+ add_message (EXPORT_MESSAGE_ERROR, TTR (" Prepare Templates" ), vformat (TTR (" Mismatching custom export template executable architecture, found \" %s\" , expected \" %s\" ." ), exe_arch, arch));
74
+ return ERR_CANT_CREATE;
75
+ }
76
+ }
77
+
64
78
bool export_as_zip = p_path.ends_with (" zip" );
65
79
66
80
String pkg_name;
@@ -205,16 +219,84 @@ bool EditorExportPlatformLinuxBSD::is_executable(const String &p_path) const {
205
219
return is_elf (p_path) || is_shebang (p_path);
206
220
}
207
221
222
+ bool EditorExportPlatformLinuxBSD::has_valid_export_configuration (const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {
223
+ String err;
224
+ bool valid = EditorExportPlatformPC::has_valid_export_configuration (p_preset, err, r_missing_templates, p_debug);
225
+
226
+ String custom_debug = p_preset->get (" custom_template/debug" ).operator String ().strip_edges ();
227
+ String custom_release = p_preset->get (" custom_template/release" ).operator String ().strip_edges ();
228
+ String arch = p_preset->get (" binary_format/architecture" );
229
+
230
+ if (!custom_debug.is_empty () && FileAccess::exists (custom_debug)) {
231
+ String exe_arch = _get_exe_arch (custom_debug);
232
+ if (arch != exe_arch) {
233
+ err += vformat (TTR (" Mismatching custom debug export template executable architecture: found \" %s\" , expected \" %s\" ." ), exe_arch, arch) + " \n " ;
234
+ }
235
+ }
236
+ if (!custom_release.is_empty () && FileAccess::exists (custom_release)) {
237
+ String exe_arch = _get_exe_arch (custom_release);
238
+ if (arch != exe_arch) {
239
+ err += vformat (TTR (" Mismatching custom release export template executable architecture: found \" %s\" , expected \" %s\" ." ), exe_arch, arch) + " \n " ;
240
+ }
241
+ }
242
+
243
+ if (!err.is_empty ()) {
244
+ r_error = err;
245
+ }
246
+
247
+ return valid;
248
+ }
249
+
250
+ String EditorExportPlatformLinuxBSD::_get_exe_arch (const String &p_path) const {
251
+ Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::READ);
252
+ if (f.is_null ()) {
253
+ return " invalid" ;
254
+ }
255
+
256
+ // Read and check ELF magic number.
257
+ {
258
+ uint32_t magic = f->get_32 ();
259
+ if (magic != 0x464c457f ) { // 0x7F + "ELF"
260
+ return " invalid" ;
261
+ }
262
+ }
263
+
264
+ // Process header.
265
+ int64_t header_pos = f->get_position ();
266
+ f->seek (header_pos + 14 );
267
+ uint16_t machine = f->get_16 ();
268
+ f->close ();
269
+
270
+ switch (machine) {
271
+ case 0x0003 :
272
+ return " x86_32" ;
273
+ case 0x003e :
274
+ return " x86_64" ;
275
+ case 0x0014 :
276
+ return " ppc32" ;
277
+ case 0x0015 :
278
+ return " ppc64" ;
279
+ case 0x0028 :
280
+ return " arm32" ;
281
+ case 0x00b7 :
282
+ return " arm64" ;
283
+ case 0x00f3 :
284
+ return " rv64" ;
285
+ default :
286
+ return " unknown" ;
287
+ }
288
+ }
289
+
208
290
Error EditorExportPlatformLinuxBSD::fixup_embedded_pck (const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) {
209
- // Patch the header of the "pck" section in the ELF file so that it corresponds to the embedded data
291
+ // Patch the header of the "pck" section in the ELF file so that it corresponds to the embedded data.
210
292
211
293
Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::READ_WRITE);
212
294
if (f.is_null ()) {
213
295
add_message (EXPORT_MESSAGE_ERROR, TTR (" PCK Embedding" ), vformat (TTR (" Failed to open executable file \" %s\" ." ), p_path));
214
296
return ERR_CANT_OPEN;
215
297
}
216
298
217
- // Read and check ELF magic number
299
+ // Read and check ELF magic number.
218
300
{
219
301
uint32_t magic = f->get_32 ();
220
302
if (magic != 0x464c457f ) { // 0x7F + "ELF"
@@ -223,15 +305,15 @@ Error EditorExportPlatformLinuxBSD::fixup_embedded_pck(const String &p_path, int
223
305
}
224
306
}
225
307
226
- // Read program architecture bits from class field
308
+ // Read program architecture bits from class field.
227
309
228
310
int bits = f->get_8 () * 32 ;
229
311
230
312
if (bits == 32 && p_embedded_size >= 0x100000000 ) {
231
313
add_message (EXPORT_MESSAGE_ERROR, TTR (" PCK Embedding" ), TTR (" 32-bit executables cannot have embedded data >= 4 GiB." ));
232
314
}
233
315
234
- // Get info about the section header table
316
+ // Get info about the section header table.
235
317
236
318
int64_t section_table_pos;
237
319
int64_t section_header_size;
@@ -249,13 +331,13 @@ Error EditorExportPlatformLinuxBSD::fixup_embedded_pck(const String &p_path, int
249
331
int num_sections = f->get_16 ();
250
332
int string_section_idx = f->get_16 ();
251
333
252
- // Load the strings table
334
+ // Load the strings table.
253
335
uint8_t *strings;
254
336
{
255
- // Jump to the strings section header
337
+ // Jump to the strings section header.
256
338
f->seek (section_table_pos + string_section_idx * section_header_size);
257
339
258
- // Read strings data size and offset
340
+ // Read strings data size and offset.
259
341
int64_t string_data_pos;
260
342
int64_t string_data_size;
261
343
if (bits == 32 ) {
@@ -268,7 +350,7 @@ Error EditorExportPlatformLinuxBSD::fixup_embedded_pck(const String &p_path, int
268
350
string_data_size = f->get_64 ();
269
351
}
270
352
271
- // Read strings data
353
+ // Read strings data.
272
354
f->seek (string_data_pos);
273
355
strings = (uint8_t *)memalloc (string_data_size);
274
356
if (!strings) {
@@ -277,7 +359,7 @@ Error EditorExportPlatformLinuxBSD::fixup_embedded_pck(const String &p_path, int
277
359
f->get_buffer (strings, string_data_size);
278
360
}
279
361
280
- // Search for the "pck" section
362
+ // Search for the "pck" section.
281
363
282
364
bool found = false ;
283
365
for (int i = 0 ; i < num_sections; ++i) {
0 commit comments