Skip to content

Commit 64b1e52

Browse files
committed
Make build profile project detection also set build options
1 parent a77a28c commit 64b1e52

File tree

9 files changed

+599
-48
lines changed

9 files changed

+599
-48
lines changed

core/io/resource.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
372372
get_property_list(&plist);
373373

374374
Ref<Resource> r = static_cast<Resource *>(ClassDB::instantiate(get_class()));
375+
if (r.is_null()) {
376+
print_line(get_class());
377+
}
375378
ERR_FAIL_COND_V(r.is_null(), Ref<Resource>());
376379

377380
for (const PropertyInfo &E : plist) {

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)