Skip to content

Commit 6f805de

Browse files
committed
Merge pull request godotengine#88365 from dalexeev/gds-fix-gdc-export
GDScript: Fix extension comparison for exported scripts
2 parents d48c450 + a2e3e31 commit 6f805de

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

modules/gdscript/gdscript.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,18 @@ String GDScript::debug_get_script_name(const Ref<Script> &p_script) {
14051405
}
14061406
#endif
14071407

1408+
bool GDScript::is_equal_gdscript_paths(const String &p_path_a, const String &p_path_b) {
1409+
String path_a = p_path_a;
1410+
if (path_a.get_extension() == "gdc") {
1411+
path_a = path_a.get_basename() + ".gd";
1412+
}
1413+
String path_b = p_path_b;
1414+
if (path_b.get_extension() == "gdc") {
1415+
path_b = path_b.get_basename() + ".gd";
1416+
}
1417+
return path_a == path_b;
1418+
}
1419+
14081420
GDScript::UpdatableFuncPtr::UpdatableFuncPtr(GDScriptFunction *p_function) {
14091421
if (p_function == nullptr) {
14101422
return;

modules/gdscript/gdscript.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ class GDScript : public Script {
230230
static String debug_get_script_name(const Ref<Script> &p_script);
231231
#endif
232232

233+
static bool is_equal_gdscript_paths(const String &p_path_a, const String &p_path_b);
234+
233235
_FORCE_INLINE_ StringName get_local_name() const { return local_name; }
234236

235237
void clear(GDScript::ClearData *p_clear_data = nullptr);

modules/gdscript/gdscript_analyzer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
361361
push_error(vformat(R"(Class "%s" hides a built-in type.)", class_name), p_class->identifier);
362362
} else if (class_exists(class_name)) {
363363
push_error(vformat(R"(Class "%s" hides a native class.)", class_name), p_class->identifier);
364-
} else if (ScriptServer::is_global_class(class_name) && (ScriptServer::get_global_class_path(class_name) != parser->script_path || p_class != parser->head)) {
364+
} else if (ScriptServer::is_global_class(class_name) && (!GDScript::is_equal_gdscript_paths(ScriptServer::get_global_class_path(class_name), parser->script_path) || p_class != parser->head)) {
365365
push_error(vformat(R"(Class "%s" hides a global script class.)", class_name), p_class->identifier);
366366
} else if (ProjectSettings::get_singleton()->has_autoload(class_name) && ProjectSettings::get_singleton()->get_autoload(class_name).is_singleton) {
367367
push_error(vformat(R"(Class "%s" hides an autoload singleton.)", class_name), p_class->identifier);
@@ -425,7 +425,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
425425
if (ScriptServer::is_global_class(name)) {
426426
String base_path = ScriptServer::get_global_class_path(name);
427427

428-
if (base_path == parser->script_path) {
428+
if (GDScript::is_equal_gdscript_paths(base_path, parser->script_path)) {
429429
base = parser->head->get_datatype();
430430
} else {
431431
Ref<GDScriptParserRef> base_parser = get_parser_for(base_path);
@@ -698,7 +698,7 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type
698698
result.builtin_type = Variant::OBJECT;
699699
result.native_type = first;
700700
} else if (ScriptServer::is_global_class(first)) {
701-
if (parser->script_path == ScriptServer::get_global_class_path(first)) {
701+
if (GDScript::is_equal_gdscript_paths(parser->script_path, ScriptServer::get_global_class_path(first))) {
702702
result = parser->head->get_datatype();
703703
} else {
704704
String path = ScriptServer::get_global_class_path(first);

modules/gdscript/language_server/gdscript_workspace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
641641
while (!stack.is_empty()) {
642642
current = Object::cast_to<Node>(stack.pop_back());
643643
Ref<GDScript> scr = current->get_script();
644-
if (scr.is_valid() && scr->get_path() == path) {
644+
if (scr.is_valid() && GDScript::is_equal_gdscript_paths(scr->get_path(), path)) {
645645
break;
646646
}
647647
for (int i = 0; i < current->get_child_count(); ++i) {
@@ -650,7 +650,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
650650
}
651651

652652
Ref<GDScript> scr = current->get_script();
653-
if (!scr.is_valid() || scr->get_path() != path) {
653+
if (!scr.is_valid() || !GDScript::is_equal_gdscript_paths(scr->get_path(), path)) {
654654
current = owner_scene_node;
655655
}
656656
}

modules/gdscript/register_types.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,21 @@ Ref<GDScriptEditorTranslationParserPlugin> gdscript_translation_parser_plugin;
8282
class EditorExportGDScript : public EditorExportPlugin {
8383
GDCLASS(EditorExportGDScript, EditorExportPlugin);
8484

85-
public:
86-
virtual void _export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) override {
87-
int script_mode = EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS_COMPRESSED;
85+
static constexpr int DEFAULT_SCRIPT_MODE = EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS_COMPRESSED;
86+
int script_mode = DEFAULT_SCRIPT_MODE;
8887

89-
const Ref<EditorExportPreset> &preset = get_export_preset();
88+
protected:
89+
virtual void _export_begin(const HashSet<String> &p_features, bool p_debug, const String &p_path, int p_flags) override {
90+
script_mode = DEFAULT_SCRIPT_MODE;
9091

92+
const Ref<EditorExportPreset> &preset = get_export_preset();
9193
if (preset.is_valid()) {
9294
script_mode = preset->get_script_export_mode();
9395
}
96+
}
9497

95-
if (!p_path.ends_with(".gd") || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) {
98+
virtual void _export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) override {
99+
if (p_path.get_extension() != "gd" || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) {
96100
return;
97101
}
98102

@@ -110,10 +114,9 @@ class EditorExportGDScript : public EditorExportPlugin {
110114
}
111115

112116
add_file(p_path.get_basename() + ".gdc", file, true);
113-
114-
return;
115117
}
116118

119+
public:
117120
virtual String get_name() const override { return "GDScript"; }
118121
};
119122

0 commit comments

Comments
 (0)