Skip to content

Commit b80de8a

Browse files
committed
Make build profile project detection also set build options
1 parent 1ba8565 commit b80de8a

10 files changed

+646
-59
lines changed

core/extension/gdextension.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,19 @@ String GDExtensionResourceLoader::get_resource_type(const String &p_path) const
864864
}
865865

866866
#ifdef TOOLS_ENABLED
867+
void GDExtensionResourceLoader::get_classes_used(const String &p_path, HashSet<StringName> *r_classes) {
868+
Ref<GDExtension> gdext = ResourceLoader::load(p_path);
869+
if (gdext.is_null()) {
870+
return;
871+
}
872+
873+
for (const StringName class_name : gdext->get_classes_used()) {
874+
if (ClassDB::class_exists(class_name)) {
875+
r_classes->insert(class_name);
876+
}
877+
}
878+
}
879+
867880
bool GDExtension::has_library_changed() const {
868881
return loader->has_library_changed();
869882
}

core/extension/gdextension.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ class GDExtensionResourceLoader : public ResourceFormatLoader {
184184
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
185185
virtual bool handles_type(const String &p_type) const override;
186186
virtual String get_resource_type(const String &p_path) const override;
187+
#ifdef TOOLS_ENABLED
188+
virtual void get_classes_used(const String &p_path, HashSet<StringName> *r_classes) override;
189+
#endif // TOOLS_ENABLED
187190
};
188191

189192
#ifdef TOOLS_ENABLED

core/io/resource_importer.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ Variant ResourceFormatImporter::get_resource_metadata(const String &p_path) cons
418418

419419
return pat.metadata;
420420
}
421+
421422
void ResourceFormatImporter::get_classes_used(const String &p_path, HashSet<StringName> *r_classes) {
422423
PathAndType pat;
423424
Error err = _get_path_and_type(p_path, pat);
@@ -440,6 +441,18 @@ void ResourceFormatImporter::get_dependencies(const String &p_path, List<String>
440441
ResourceLoader::get_dependencies(pat.path, p_dependencies, p_add_types);
441442
}
442443

444+
void ResourceFormatImporter::get_build_dependencies(const String &p_path, HashSet<String> *r_dependencies) {
445+
if (!exists(p_path)) {
446+
return;
447+
}
448+
449+
List<Ref<ResourceImporter>> valid_importers;
450+
get_importers_for_extension(p_path.get_extension(), &valid_importers);
451+
for (Ref<ResourceImporter> importer : valid_importers) {
452+
return importer->get_build_dependencies(p_path, r_dependencies);
453+
}
454+
}
455+
443456
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String &p_name) const {
444457
for (int i = 0; i < importers.size(); i++) {
445458
if (importers[i]->get_importer_name() == p_name) {
@@ -540,9 +553,21 @@ ResourceFormatImporter::ResourceFormatImporter() {
540553

541554
//////////////
542555

556+
void ResourceImporter::get_build_dependencies(const String &p_path, HashSet<String> *r_dependencies) {
557+
Vector<String> ret;
558+
if (GDVIRTUAL_CALL(_get_build_dependencies, p_path, ret)) {
559+
for (int i = 0; i < ret.size(); i++) {
560+
r_dependencies->insert(ret[i]);
561+
}
562+
return;
563+
}
564+
}
565+
543566
void ResourceImporter::_bind_methods() {
544567
BIND_ENUM_CONSTANT(IMPORT_ORDER_DEFAULT);
545568
BIND_ENUM_CONSTANT(IMPORT_ORDER_SCENE);
569+
570+
GDVIRTUAL_BIND(_get_build_dependencies, "path");
546571
}
547572

548573
/////

core/io/resource_importer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class ResourceFormatImporter : public ResourceFormatLoader {
7878
virtual void get_classes_used(const String &p_path, HashSet<StringName> *r_classes) override;
7979
virtual bool exists(const String &p_path) const override;
8080

81+
void get_build_dependencies(const String &p_path, HashSet<String> *r_dependencies);
82+
8183
virtual int get_import_order(const String &p_path) const override;
8284

8385
Error get_import_order_threads_and_importer(const String &p_path, int &r_order, bool &r_can_threads, String &r_importer) const;
@@ -106,6 +108,8 @@ class ResourceImporter : public RefCounted {
106108
GDCLASS(ResourceImporter, RefCounted);
107109

108110
protected:
111+
GDVIRTUAL1RC(Vector<String>, _get_build_dependencies, String)
112+
109113
static void _bind_methods();
110114

111115
public:
@@ -155,6 +159,8 @@ class ResourceImporter : public RefCounted {
155159
virtual Error import_group_file(const String &p_group_file, const HashMap<String, HashMap<StringName, Variant>> &p_source_file_options, const HashMap<String, String> &p_base_paths) { return ERR_UNAVAILABLE; }
156160
virtual bool are_import_settings_valid(const String &p_path, const Dictionary &p_meta) const { return true; }
157161
virtual String get_import_settings_string() const { return String(); }
162+
163+
virtual void get_build_dependencies(const String &p_path, HashSet<String> *r_build_dependencies);
158164
};
159165

160166
VARIANT_ENUM_CAST(ResourceImporter::ImportOrder);

doc/classes/ResourceImporter.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@
99
<tutorials>
1010
<link title="Import plugins">$DOCS_URL/tutorials/plugins/editor/import_plugins.html</link>
1111
</tutorials>
12+
<methods>
13+
<method name="_get_build_dependencies" qualifiers="virtual const">
14+
<return type="PackedStringArray" />
15+
<param index="0" name="path" type="String" />
16+
<description>
17+
Called when the engine compilation profile editor wants to check what build options an imported resource needs. For example, [ResourceImporterDynamicFont] has a property called [member ResourceImporterDynamicFont.multichannel_signed_distance_field], that depends on the engine to be build with the "msdfgen" module. If that resource happened to be a custom one, it would be handled like this:
18+
[codeblock]
19+
func _get_build_dependencies(path):
20+
var resource = load(path)
21+
var dependencies = PackedStringArray()
22+
23+
if resource.multichannel_signed_distance_field:
24+
dependencies.push_back("module_msdfgen_enabled")
25+
26+
return dependencies
27+
[/codeblock]
28+
</description>
29+
</method>
30+
</methods>
1231
<constants>
1332
<constant name="IMPORT_ORDER_DEFAULT" value="0" enum="ImportOrder">
1433
The default import order.

0 commit comments

Comments
 (0)