Skip to content

Commit 3d60ce9

Browse files
committed
[Export] Allow using ICU data from export templates instead of editor embedded data.
1 parent 4cf0231 commit 3d60ce9

File tree

9 files changed

+65
-50
lines changed

9 files changed

+65
-50
lines changed

doc/classes/EditorExportPlatform.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@
125125
Returns array of core file names that always should be exported regardless of preset config.
126126
</description>
127127
</method>
128-
<method name="get_internal_export_files" qualifiers="static">
128+
<method name="get_internal_export_files">
129129
<return type="Dictionary" />
130+
<param index="0" name="preset" type="EditorExportPreset" />
131+
<param index="1" name="debug" type="bool" />
130132
<description>
131133
Returns additional files that should always be exported regardless of preset configuration, and are not part of the project source. The returned [Dictionary] contains filename keys ([String]) and their corresponding raw data ([PackedByteArray]).
132134
</description>

editor/export/editor_export_platform.cpp

+38-18
Original file line numberDiff line numberDiff line change
@@ -900,19 +900,49 @@ String EditorExportPlatform::_get_script_encryption_key(const Ref<EditorExportPr
900900
return p_preset->get_script_encryption_key().to_lower();
901901
}
902902

903-
Dictionary EditorExportPlatform::get_internal_export_files() {
903+
Dictionary EditorExportPlatform::get_internal_export_files(const Ref<EditorExportPreset> &p_preset, bool p_debug) {
904904
Dictionary files;
905905

906906
// Text server support data.
907907
if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA) && (bool)GLOBAL_GET("internationalization/locale/include_text_server_data")) {
908908
String ts_name = TS->get_support_data_filename();
909+
String ts_target = "res://" + ts_name;
909910
if (!ts_name.is_empty()) {
910-
ts_name = "res://" + ts_name;
911-
if (!FileAccess::exists(ts_name)) { // Do not include if user supplied data file exist.
912-
const PackedByteArray &ts_data = TS->get_support_data();
911+
bool export_ok = false;
912+
if (FileAccess::exists(ts_target)) { // Include user supplied data file.
913+
const PackedByteArray &ts_data = FileAccess::get_file_as_bytes(ts_target);
913914
if (!ts_data.is_empty()) {
914-
files[ts_name] = ts_data;
915+
add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Using user provided text server data, text display in the exported project might be broken if export template was built with different ICU version!"));
916+
files[ts_target] = ts_data;
917+
export_ok = true;
915918
}
919+
} else {
920+
String current_version = VERSION_FULL_CONFIG;
921+
String template_path = EditorPaths::get_singleton()->get_export_templates_dir().path_join(current_version);
922+
if (p_debug && p_preset->has("custom_template/debug") && p_preset->get("custom_template/debug") != "") {
923+
template_path = p_preset->get("custom_template/debug").operator String().get_base_dir();
924+
} else if (!p_debug && p_preset->has("custom_template/release") && p_preset->get("custom_template/release") != "") {
925+
template_path = p_preset->get("custom_template/release").operator String().get_base_dir();
926+
}
927+
String data_file_name = template_path.path_join(ts_name);
928+
if (FileAccess::exists(data_file_name)) {
929+
const PackedByteArray &ts_data = FileAccess::get_file_as_bytes(data_file_name);
930+
if (!ts_data.is_empty()) {
931+
print_line("Using text server data from export templates.");
932+
files[ts_target] = ts_data;
933+
export_ok = true;
934+
}
935+
} else {
936+
const PackedByteArray &ts_data = TS->get_support_data();
937+
if (!ts_data.is_empty()) {
938+
add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Using editor embedded text server data, text display in the exported project might be broken if export template was built with different ICU version!"));
939+
files[ts_target] = ts_data;
940+
export_ok = true;
941+
}
942+
}
943+
}
944+
if (!export_ok) {
945+
add_message(EXPORT_MESSAGE_WARNING, TTR("Export"), TTR("Missing text server data, text display in the exported project might be broken!"));
916946
}
917947
}
918948
}
@@ -943,17 +973,6 @@ Vector<String> EditorExportPlatform::get_forced_export_files() {
943973
files.push_back(extension_list_config_file);
944974
}
945975

946-
// Text server support data.
947-
if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA) && (bool)GLOBAL_GET("internationalization/locale/include_text_server_data")) {
948-
String ts_name = TS->get_support_data_filename();
949-
if (!ts_name.is_empty()) {
950-
ts_name = "res://" + ts_name;
951-
if (FileAccess::exists(ts_name)) { // Include user supplied data file.
952-
files.push_back(ts_name);
953-
}
954-
}
955-
}
956-
957976
return files;
958977
}
959978

@@ -1518,7 +1537,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
15181537
}
15191538
}
15201539

1521-
Dictionary int_export = get_internal_export_files();
1540+
Dictionary int_export = get_internal_export_files(p_preset, p_debug);
15221541
for (const Variant &int_name : int_export.keys()) {
15231542
const PackedByteArray &array = int_export[int_name];
15241543
err = p_save_func(p_udata, int_name, array, idx, total, enc_in_filters, enc_ex_filters, key, seed);
@@ -2443,8 +2462,9 @@ void EditorExportPlatform::_bind_methods() {
24432462
ClassDB::bind_method(D_METHOD("ssh_run_on_remote_no_wait", "host", "port", "ssh_args", "cmd_args", "port_fwd"), &EditorExportPlatform::_ssh_run_on_remote_no_wait, DEFVAL(-1));
24442463
ClassDB::bind_method(D_METHOD("ssh_push_to_remote", "host", "port", "scp_args", "src_file", "dst_file"), &EditorExportPlatform::ssh_push_to_remote);
24452464

2465+
ClassDB::bind_method(D_METHOD("get_internal_export_files", "preset", "debug"), &EditorExportPlatform::get_internal_export_files);
2466+
24462467
ClassDB::bind_static_method("EditorExportPlatform", D_METHOD("get_forced_export_files"), &EditorExportPlatform::get_forced_export_files);
2447-
ClassDB::bind_static_method("EditorExportPlatform", D_METHOD("get_internal_export_files"), &EditorExportPlatform::get_internal_export_files);
24482468

24492469
BIND_ENUM_CONSTANT(EXPORT_MESSAGE_NONE);
24502470
BIND_ENUM_CONSTANT(EXPORT_MESSAGE_INFO);

editor/export/editor_export_platform.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ class EditorExportPlatform : public RefCounted {
277277
return worst_type;
278278
}
279279

280-
static Dictionary get_internal_export_files();
280+
Dictionary get_internal_export_files(const Ref<EditorExportPreset> &p_preset, bool p_debug);
281+
281282
static Vector<String> get_forced_export_files();
282283

283284
virtual bool fill_log_messages(RichTextLabel *p_log, Error p_err);

main/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2528,7 +2528,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
25282528
}
25292529
}
25302530

2531-
GLOBAL_DEF("internationalization/locale/include_text_server_data", false);
2531+
GLOBAL_DEF_BASIC("internationalization/locale/include_text_server_data", false);
25322532

25332533
OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", true);
25342534
OS::get_singleton()->_allow_layered = GLOBAL_DEF("display/window/per_pixel_transparency/allowed", false);

modules/text_server_adv/SCsub

+2-6
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,9 @@ if env["builtin_icu4c"]:
477477
]
478478
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
479479

480-
icu_data_name = "icudt76l.dat"
481-
482480
if env.editor_build:
483-
env_icu.Depends("#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/" + icu_data_name)
484-
env_icu.Command("#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/" + icu_data_name, make_icu_data)
481+
env_icu.Depends("#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/icudt_godot.dat")
482+
env_icu.Command("#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/icudt_godot.dat", make_icu_data)
485483
env_text_server_adv.Prepend(CPPPATH=["#thirdparty/icu4c/"])
486484
else:
487485
thirdparty_sources += ["icu_data/icudata_stub.cpp"]
@@ -503,15 +501,13 @@ if env["builtin_icu4c"]:
503501
"-DU_ENABLE_DYLOAD=0",
504502
"-DU_HAVE_LIB_SUFFIX=1",
505503
"-DU_LIB_SUFFIX_C_NAME=_godot",
506-
"-DICU_DATA_NAME=" + icu_data_name,
507504
]
508505
)
509506
env_text_server_adv.Append(
510507
CXXFLAGS=[
511508
"-DU_STATIC_IMPLEMENTATION",
512509
"-DU_HAVE_LIB_SUFFIX=1",
513510
"-DU_LIB_SUFFIX_C_NAME=_godot",
514-
"-DICU_DATA_NAME=" + icu_data_name,
515511
]
516512
)
517513
if env.editor_build:

modules/text_server_adv/gdextension_build/SConstruct

+2-6
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,10 @@ thirdparty_icu_sources = [
701701
]
702702
thirdparty_icu_sources = [thirdparty_icu_dir + file for file in thirdparty_icu_sources]
703703

704-
icu_data_name = "icudt76l.dat"
705-
706704
if env["static_icu_data"]:
707-
env_icu.Depends("../../../thirdparty/icu4c/icudata.gen.h", "../../../thirdparty/icu4c/" + icu_data_name)
705+
env_icu.Depends("../../../thirdparty/icu4c/icudata.gen.h", "../../../thirdparty/icu4c/icudt_godot.dat")
708706
env_icu.Command(
709-
"../../../thirdparty/icu4c/icudata.gen.h", "../../../thirdparty/icu4c/" + icu_data_name, methods.make_icu_data
707+
"../../../thirdparty/icu4c/icudata.gen.h", "../../../thirdparty/icu4c/icudt_godot.dat", methods.make_icu_data
710708
)
711709
env.Append(CXXFLAGS=["-DICU_STATIC_DATA"])
712710
env.Append(CPPPATH=["../../../thirdparty/icu4c/"])
@@ -729,15 +727,13 @@ env_icu.Append(
729727
"-DU_ENABLE_DYLOAD=0",
730728
"-DU_HAVE_LIB_SUFFIX=1",
731729
"-DU_LIB_SUFFIX_C_NAME=_godot",
732-
"-DICU_DATA_NAME=" + icu_data_name,
733730
]
734731
)
735732
env.Append(
736733
CXXFLAGS=[
737734
"-DU_STATIC_IMPLEMENTATION",
738735
"-DU_HAVE_LIB_SUFFIX=1",
739736
"-DU_LIB_SUFFIX_C_NAME=_godot",
740-
"-DICU_DATA_NAME=" + icu_data_name,
741737
]
742738
)
743739
env.Append(CPPPATH=["../../../thirdparty/icu4c/common/", "../../../thirdparty/icu4c/i18n/"])

modules/text_server_adv/text_server_adv.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -442,23 +442,23 @@ bool TextServerAdvanced::_load_support_data(const String &p_filename) {
442442
#else
443443
if (!icu_data_loaded) {
444444
UErrorCode err = U_ZERO_ERROR;
445-
#ifdef ICU_DATA_NAME
446-
String filename = (p_filename.is_empty()) ? String("res://") + _MKSTR(ICU_DATA_NAME) : p_filename;
445+
String filename = (p_filename.is_empty()) ? String("res://icudt_godot.dat") : p_filename;
446+
if (FileAccess::exists(filename)) {
447+
Ref<FileAccess> f = FileAccess::open(filename, FileAccess::READ);
448+
if (f.is_null()) {
449+
return false;
450+
}
451+
uint64_t len = f->get_length();
452+
icu_data = f->get_buffer(len);
447453

448-
Ref<FileAccess> f = FileAccess::open(filename, FileAccess::READ);
449-
if (f.is_null()) {
450-
return false;
451-
}
452-
uint64_t len = f->get_length();
453-
icu_data = f->get_buffer(len);
454+
udata_setCommonData(icu_data.ptr(), &err);
455+
if (U_FAILURE(err)) {
456+
ERR_FAIL_V_MSG(false, u_errorName(err));
457+
}
454458

455-
udata_setCommonData(icu_data.ptr(), &err);
456-
if (U_FAILURE(err)) {
457-
ERR_FAIL_V_MSG(false, u_errorName(err));
459+
err = U_ZERO_ERROR;
458460
}
459461

460-
err = U_ZERO_ERROR;
461-
#endif
462462
u_init(&err);
463463
if (U_FAILURE(err)) {
464464
ERR_FAIL_V_MSG(false, u_errorName(err));
@@ -470,11 +470,11 @@ bool TextServerAdvanced::_load_support_data(const String &p_filename) {
470470
}
471471

472472
String TextServerAdvanced::_get_support_data_filename() const {
473-
return _MKSTR(ICU_DATA_NAME);
473+
return String("icudt_godot.dat");
474474
}
475475

476476
String TextServerAdvanced::_get_support_data_info() const {
477-
return String("ICU break iteration data (") + _MKSTR(ICU_DATA_NAME) + String(").");
477+
return String("ICU break iteration data (\"icudt_godot.dat\").");
478478
}
479479

480480
bool TextServerAdvanced::_save_support_data(const String &p_filename) const {

thirdparty/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ Files extracted from upstream source:
420420

421421
Files generated from upstream source:
422422

423-
- The `icudt76l.dat` built with the provided `godot_data.json` config file (see
423+
- The `icudt_godot.dat` built with the provided `godot_data.json` config file (see
424424
https://github.com/unicode-org/icu/blob/master/docs/userguide/icu_data/buildtool.md
425425
for instructions).
426426

@@ -430,7 +430,7 @@ Files generated from upstream source:
430430
3. Reconfigure ICU with custom data config:
431431
`ICU_DATA_FILTER_FILE={GODOT_SOURCE}/thirdparty/icu4c/godot_data.json ./runConfigureICU {PLATFORM} --with-data-packaging=common`
432432
4. Delete `data/out` folder and rebuild data: `cd data && rm -rf ./out && make`
433-
5. Copy `source/data/out/icudt76l.dat` to the `{GODOT_SOURCE}/thirdparty/icu4c/icudt76l.dat`
433+
5. Copy `source/data/out/icudt{ICU_VERSION}l.dat` to the `{GODOT_SOURCE}/thirdparty/icu4c/icudt_godot.dat`
434434

435435

436436
## jolt_physics
File renamed without changes.

0 commit comments

Comments
 (0)