Debian Codegraph @

editor/settings/editor_build_profile.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_build_profile.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #include "editor_build_profile.h"
32
33 #include "core/config/project_settings.h"
34 #include "core/io/json.h"
35 #include "editor/editor_node.h"
36 #include "editor/editor_string_names.h"
37 #include "editor/file_system/editor_file_system.h"
38 #include "editor/file_system/editor_paths.h"
39 #include "editor/gui/editor_file_dialog.h"
40 #include "editor/settings/editor_settings.h"
41 #include "editor/themes/editor_scale.h"
42 #include "scene/gui/line_edit.h"
43 #include "scene/gui/margin_container.h"
44 #include "scene/gui/separator.h"
45
46 #include "modules/modules_enabled.gen.h" // For mono.
47
48 const char *EditorBuildProfile::build_option_identifiers[BUILD_OPTION_MAX] = {
49 // This maps to SCons build options.
50 "disable_3d",
51 "disable_navigation_2d",
52 "disable_navigation_3d",
53 "disable_xr",
54 "module_openxr_enabled",
55 "wayland",
56 "x11",
57 "rendering_device", // FIXME: There's no scons option to disable rendering device.
58 "forward_plus_renderer",
59 "forward_mobile_renderer",
60 "vulkan",
61 "d3d12",
62 "metal",
63 "opengl3",
64 "disable_physics_2d",
65 "module_godot_physics_2d_enabled",
66 "disable_physics_3d",
67 "module_godot_physics_3d_enabled",
68 "module_jolt_physics_enabled",
69 "module_text_server_fb_enabled",
70 "module_text_server_adv_enabled",
71 "module_freetype_enabled",
72 "brotli",
73 "graphite",
74 "module_msdfgen_enabled",
75 };
76
77 const bool EditorBuildProfile::build_option_disabled_by_default[BUILD_OPTION_MAX] = {
78 // This maps to SCons build options.
79 false, // 3D
80 false, // NAVIGATION_2D
81 false, // NAVIGATION_3D
82 false, // XR
83 false, // OPENXR
84 false, // WAYLAND
85 false, // X11
86 false, // RENDERING_DEVICE
87 false, // FORWARD_RENDERER
88 false, // MOBILE_RENDERER
89 false, // VULKAN
90 false, // D3D12
91 false, // METAL
92 false, // OPENGL
93 false, // PHYSICS_2D
94 false, // PHYSICS_GODOT_2D
95 false, // PHYSICS_3D
96 false, // PHYSICS_GODOT_3D
97 false, // PHYSICS_JOLT
98 true, // TEXT_SERVER_FALLBACK
99 false, // TEXT_SERVER_ADVANCED
100 false, // DYNAMIC_FONTS
101 false, // WOFF2_FONTS
102 false, // GRAPHITE_FONTS
103 false, // MSDFGEN
104 };
105
106 const bool EditorBuildProfile::build_option_disable_values[BUILD_OPTION_MAX] = {
107 // This maps to SCons build options.
108 true, // 3D
109 true, // NAVIGATION_2D
110 true, // NAVIGATION_3D
111 true, // XR
112 false, // OPENXR
113 false, // WAYLAND
114 false, // X11
115 false, // RENDERING_DEVICE
116 false, // FORWARD_RENDERER
117 false, // MOBILE_RENDERER
118 false, // VULKAN
119 false, // D3D12
120 false, // METAL
121 false, // OPENGL
122 true, // PHYSICS_2D
123 false, // PHYSICS_GODOT_2D
124 true, // PHYSICS_3D
125 false, // PHYSICS_GODOT_3D
126 false, // PHYSICS_JOLT
127 false, // TEXT_SERVER_FALLBACK
128 false, // TEXT_SERVER_ADVANCED
129 false, // DYNAMIC_FONTS
130 false, // WOFF2_FONTS
131 false, // GRAPHITE_FONTS
132 false, // MSDFGEN
133 };
134
135 // Options that require some resource explicitly asking for them when detecting from the project.
136 const bool EditorBuildProfile::build_option_explicit_use[BUILD_OPTION_MAX] = {
137 false, // 3D
138 false, // NAVIGATION_2D
139 false, // NAVIGATION_3D
140 false, // XR
141 false, // OPENXR
142 false, // WAYLAND
143 false, // X11
144 false, // RENDERING_DEVICE
145 false, // FORWARD_RENDERER
146 false, // MOBILE_RENDERER
147 false, // VULKAN
148 false, // D3D12
149 false, // METAL
150 false, // OPENGL
151 false, // PHYSICS_2D
152 false, // PHYSICS_GODOT_2D
153 false, // PHYSICS_3D
154 false, // PHYSICS_GODOT_3D
155 false, // PHYSICS_JOLT
156 false, // TEXT_SERVER_FALLBACK
157 false, // TEXT_SERVER_ADVANCED
158 false, // DYNAMIC_FONTS
159 false, // WOFF2_FONTS
160 false, // GRAPHITE_FONTS
161 true, // MSDFGEN
162 };
163
164 const EditorBuildProfile::BuildOptionCategory EditorBuildProfile::build_option_category[BUILD_OPTION_MAX] = {
165 BUILD_OPTION_CATEGORY_GENERAL, // 3D
166 BUILD_OPTION_CATEGORY_GENERAL, // NAVIGATION_2D
167 BUILD_OPTION_CATEGORY_GENERAL, // NAVIGATION_3D
168 BUILD_OPTION_CATEGORY_GENERAL, // XR
169 BUILD_OPTION_CATEGORY_GENERAL, // OPENXR
170 BUILD_OPTION_CATEGORY_GENERAL, // WAYLAND
171 BUILD_OPTION_CATEGORY_GENERAL, // X11
172 BUILD_OPTION_CATEGORY_GRAPHICS, // RENDERING_DEVICE
173 BUILD_OPTION_CATEGORY_GRAPHICS, // FORWARD_RENDERER
174 BUILD_OPTION_CATEGORY_GRAPHICS, // MOBILE_RENDERER
175 BUILD_OPTION_CATEGORY_GRAPHICS, // VULKAN
176 BUILD_OPTION_CATEGORY_GRAPHICS, // D3D12
177 BUILD_OPTION_CATEGORY_GRAPHICS, // METAL
178 BUILD_OPTION_CATEGORY_GRAPHICS, // OPENGL
179 BUILD_OPTION_CATEGORY_PHYSICS, // PHYSICS_2D
180 BUILD_OPTION_CATEGORY_PHYSICS, // PHYSICS_GODOT_2D
181 BUILD_OPTION_CATEGORY_PHYSICS, // PHYSICS_3D
182 BUILD_OPTION_CATEGORY_PHYSICS, // PHYSICS_GODOT_3D
183 BUILD_OPTION_CATEGORY_PHYSICS, // PHYSICS_JOLT
184 BUILD_OPTION_CATEGORY_TEXT_SERVER, // TEXT_SERVER_FALLBACK
185 BUILD_OPTION_CATEGORY_TEXT_SERVER, // TEXT_SERVER_ADVANCED
186 BUILD_OPTION_CATEGORY_TEXT_SERVER, // DYNAMIC_FONTS
187 BUILD_OPTION_CATEGORY_TEXT_SERVER, // WOFF2_FONTS
188 BUILD_OPTION_CATEGORY_TEXT_SERVER, // GRAPHITE_FONTS
189 BUILD_OPTION_CATEGORY_TEXT_SERVER, // MSDFGEN
190 };
191
192 // Can't assign HashMaps to a HashMap at declaration, so do it in the class' constructor.
193 HashMap<EditorBuildProfile::BuildOption, HashMap<String, LocalVector<Variant>>> EditorBuildProfile::build_option_settings = {};
194
195 /* clang-format off */
196
197 const HashMap<EditorBuildProfile::BuildOption, LocalVector<EditorBuildProfile::BuildOption>> EditorBuildProfile::build_option_dependencies = {
198 { BUILD_OPTION_OPENXR, {
199 BUILD_OPTION_XR,
200 } },
201 { BUILD_OPTION_FORWARD_RENDERER, {
202 BUILD_OPTION_RENDERING_DEVICE,
203 } },
204 { BUILD_OPTION_MOBILE_RENDERER, {
205 BUILD_OPTION_RENDERING_DEVICE,
206 } },
207 { BUILD_OPTION_VULKAN, {
208 BUILD_OPTION_FORWARD_RENDERER,
209 BUILD_OPTION_MOBILE_RENDERER,
210 } },
211 { BUILD_OPTION_D3D12, {
212 BUILD_OPTION_FORWARD_RENDERER,
213 BUILD_OPTION_MOBILE_RENDERER,
214 } },
215 { BUILD_OPTION_METAL, {
216 BUILD_OPTION_FORWARD_RENDERER,
217 BUILD_OPTION_MOBILE_RENDERER,
218 } },
219 { BUILD_OPTION_PHYSICS_GODOT_2D, {
220 BUILD_OPTION_PHYSICS_2D,
221 } },
222 { BUILD_OPTION_PHYSICS_GODOT_3D, {
223 BUILD_OPTION_PHYSICS_3D,
224 } },
225 { BUILD_OPTION_PHYSICS_JOLT, {
226 BUILD_OPTION_PHYSICS_3D,
227 } },
228 { BUILD_OPTION_DYNAMIC_FONTS, {
229 BUILD_OPTION_TEXT_SERVER_ADVANCED,
230 } },
231 { BUILD_OPTION_WOFF2_FONTS, {
232 BUILD_OPTION_TEXT_SERVER_ADVANCED,
233 } },
234 { BUILD_OPTION_GRAPHITE_FONTS, {
235 BUILD_OPTION_TEXT_SERVER_ADVANCED,
236 } },
237 };
238
239 // Should also contain classes not derived from either `Resource` or `Node`.
240 const HashMap<EditorBuildProfile::BuildOption, LocalVector<String>> EditorBuildProfile::build_option_classes = {
241 { BUILD_OPTION_3D, {
242 "Node3D",
243 } },
244 { BUILD_OPTION_NAVIGATION_2D, {
245 "NavigationAgent2D",
246 "NavigationLink2D",
247 "NavigationMeshSourceGeometryData2D",
248 "NavigationObstacle2D",
249 "NavigationPolygon",
250 "NavigationRegion2D",
251 } },
252 { BUILD_OPTION_NAVIGATION_3D, {
253 "NavigationAgent3D",
254 "NavigationLink3D",
255 "NavigationMeshSourceGeometryData3D",
256 "NavigationObstacle3D",
257 "NavigationRegion3D",
258 } },
259 { BUILD_OPTION_XR, {
260 "XRBodyModifier3D",
261 "XRBodyTracker",
262 "XRControllerTracker",
263 "XRFaceModifier3D",
264 "XRFaceTracker",
265 "XRHandModifier3D",
266 "XRHandTracker",
267 "XRInterface",
268 "XRInterfaceExtension",
269 "XRNode3D",
270 "XROrigin3D",
271 "XRPose",
272 "XRPositionalTracker",
273 "XRServer",
274 "XRTracker",
275 "XRVRS",
276 } },
277 { BUILD_OPTION_RENDERING_DEVICE, {
278 "RenderingDevice",
279 } },
280 { BUILD_OPTION_PHYSICS_2D, {
281 "CollisionObject2D",
282 "CollisionPolygon2D",
283 "CollisionShape2D",
284 "Joint2D",
285 "PhysicsServer2D",
286 "PhysicsServer2DManager",
287 "ShapeCast2D",
288 "RayCast2D",
289 "TouchScreenButton",
290 } },
291 { BUILD_OPTION_PHYSICS_3D, {
292 "CollisionObject3D",
293 "CollisionPolygon3D",
294 "CollisionShape3D",
295 "CSGShape3D",
296 "GPUParticlesAttractor3D",
297 "GPUParticlesCollision3D",
298 "Joint3D",
299 "PhysicalBoneSimulator3D",
300 "PhysicsServer3D",
301 "PhysicsServer3DManager",
302 "PhysicsServer3DRenderingServerHandler",
303 "RayCast3D",
304 "SoftBody3D",
305 "SpringArm3D",
306 "VehicleWheel3D",
307 } },
308 { BUILD_OPTION_TEXT_SERVER_ADVANCED, {
309 "CanvasItem",
310 "Label3D",
311 "TextServerAdvanced",
312 } },
313 };
314
315 /* clang-format on */
316
317 void EditorBuildProfile::set_disable_class(const StringName &p_class, bool p_disabled) {
318 if (p_disabled) {
319 disabled_classes.insert(p_class);
320 } else {
321 disabled_classes.erase(p_class);
322 }
323 }
324
325 bool EditorBuildProfile::is_class_disabled(const StringName &p_class) const {
326 if (p_class == StringName()) {
327 return false;
328 }
329 return disabled_classes.has(p_class) || is_class_disabled(ClassDB::get_parent_class_nocheck(p_class));
330 }
331
332 void EditorBuildProfile::set_item_collapsed(const StringName &p_class, bool p_collapsed) {
333 if (p_collapsed) {
334 collapsed_classes.insert(p_class);
335 } else {
336 collapsed_classes.erase(p_class);
337 }
338 }
339
340 bool EditorBuildProfile::is_item_collapsed(const StringName &p_class) const {
341 return collapsed_classes.has(p_class);
342 }
343
344 void EditorBuildProfile::set_disable_build_option(BuildOption p_build_option, bool p_disable) {
345 ERR_FAIL_INDEX(p_build_option, BUILD_OPTION_MAX);
346 build_options_disabled[p_build_option] = p_disable;
347 }
348
349 void EditorBuildProfile::clear_disabled_classes() {
350 disabled_classes.clear();
351 collapsed_classes.clear();
352 }
353
354 bool EditorBuildProfile::is_build_option_disabled(BuildOption p_build_option) const {
355 ERR_FAIL_INDEX_V(p_build_option, BUILD_OPTION_MAX, false);
356 return build_options_disabled[p_build_option];
357 }
358
359 bool EditorBuildProfile::get_build_option_disable_value(BuildOption p_build_option) {
360 ERR_FAIL_INDEX_V(p_build_option, BUILD_OPTION_MAX, false);
361 return build_option_disable_values[p_build_option];
362 }
363
364 bool EditorBuildProfile::get_build_option_explicit_use(BuildOption p_build_option) {
365 ERR_FAIL_INDEX_V(p_build_option, BUILD_OPTION_MAX, false);
366 return build_option_explicit_use[p_build_option];
367 }
368
369 void EditorBuildProfile::reset_build_options() {
370 for (int i = 0; i < EditorBuildProfile::BUILD_OPTION_MAX; i++) {
371 build_options_disabled[i] = build_option_disabled_by_default[i];
372 }
373 }
374
375 void EditorBuildProfile::set_force_detect_classes(const String &p_classes) {
376 force_detect_classes = p_classes;
377 }
378
379 String EditorBuildProfile::get_force_detect_classes() const {
380 return force_detect_classes;
381 }
382
383 String EditorBuildProfile::get_build_option_name(BuildOption p_build_option) {
384 ERR_FAIL_INDEX_V(p_build_option, BUILD_OPTION_MAX, String());
385 const char *build_option_names[BUILD_OPTION_MAX] = {
386 TTRC("3D Engine"),
387 TTRC("Navigation (2D)"),
388 TTRC("Navigation (3D)"),
389 TTRC("XR"),
390 TTRC("OpenXR"),
391 TTRC("Wayland"),
392 TTRC("X11"),
393 TTRC("RenderingDevice"),
394 TTRC("Forward+ Renderer"),
395 TTRC("Mobile Renderer"),
396 TTRC("Vulkan"),
397 TTRC("D3D12"),
398 TTRC("Metal"),
399 TTRC("OpenGL"),
400 TTRC("Physics Server (2D)"),
401 TTRC("Godot Physics (2D)"),
402 TTRC("Physics Server (3D)"),
403 TTRC("Godot Physics (3D)"),
404 TTRC("Jolt Physics"),
405 TTRC("Text Server: Fallback"),
406 TTRC("Text Server: Advanced"),
407 TTRC("TTF, OTF, Type 1, WOFF1 Fonts"),
408 TTRC("WOFF2 Fonts"),
409 TTRC("SIL Graphite Fonts"),
410 TTRC("Multi-channel Signed Distance Field Font Rendering"),
411 };
412 return TTRGET(build_option_names[p_build_option]);
413 }
414
415 String EditorBuildProfile::get_build_option_description(BuildOption p_build_option) {
416 ERR_FAIL_INDEX_V(p_build_option, BUILD_OPTION_MAX, String());
417
418 const char *build_option_descriptions[BUILD_OPTION_MAX] = {
419 TTRC("3D Nodes as well as RenderingServer access to 3D features."),
420 TTRC("Navigation Server and capabilities for 2D."),
421 TTRC("Navigation Server and capabilities for 3D."),
422 TTRC("XR (AR and VR)."),
423 TTRC("OpenXR standard implementation (requires XR to be enabled)."),
424 TTRC("Wayland display (Linux only)."),
425 TTRC("X11 display (Linux only)."),
426 TTRC("RenderingDevice based rendering (if disabled, the OpenGL backend is required)."),
427 TTRC("Forward+ renderer for advanced 3D graphics."),
428 TTRC("Mobile renderer for less advanced 3D graphics."),
429 TTRC("Vulkan backend of RenderingDevice."),
430 TTRC("Direct3D 12 backend of RenderingDevice."),
431 TTRC("Metal backend of RenderingDevice (Apple arm64 only)."),
432 TTRC("OpenGL backend (if disabled, the RenderingDevice backend is required)."),
433 TTRC("Physics Server and capabilities for 2D."),
434 TTRC("Godot Physics backend (2D)."),
435 TTRC("Physics Server and capabilities for 3D."),
436 TTRC("Godot Physics backend (3D)."),
437 TTRC("Jolt Physics backend (3D only)."),
438 TTRC("Fallback implementation of Text Server\nSupports basic text layouts."),
439 TTRC("Text Server implementation powered by ICU and HarfBuzz libraries.\nSupports complex text layouts, BiDi, and contextual OpenType font features."),
440 TTRC("TrueType, OpenType, Type 1, and WOFF1 font format support using FreeType library (if disabled, WOFF2 support is also disabled)."),
441 TTRC("WOFF2 font format support using FreeType and Brotli libraries."),
442 TTRC("SIL Graphite smart font technology support (supported by Advanced Text Server only)."),
443 TTRC("Multi-channel signed distance field font rendering support using msdfgen library (pre-rendered MSDF fonts can be used even if this option disabled)."),
444 };
445
446 return TTRGET(build_option_descriptions[p_build_option]);
447 }
448
449 String EditorBuildProfile::get_build_option_identifier(BuildOption p_build_option) {
450 ERR_FAIL_INDEX_V(p_build_option, BUILD_OPTION_MAX, String());
451 return build_option_identifiers[p_build_option];
452 }
453
454 EditorBuildProfile::BuildOptionCategory EditorBuildProfile::get_build_option_category(BuildOption p_build_option) {
455 ERR_FAIL_INDEX_V(p_build_option, BUILD_OPTION_MAX, BUILD_OPTION_CATEGORY_GENERAL);
456 return build_option_category[p_build_option];
457 }
458
459 LocalVector<EditorBuildProfile::BuildOption> EditorBuildProfile::get_build_option_dependencies(BuildOption p_build_option) {
460 ERR_FAIL_INDEX_V(p_build_option, BUILD_OPTION_MAX, LocalVector<EditorBuildProfile::BuildOption>());
461 return build_option_dependencies.has(p_build_option) ? build_option_dependencies[p_build_option] : LocalVector<EditorBuildProfile::BuildOption>();
462 }
463
464 HashMap<String, LocalVector<Variant>> EditorBuildProfile::get_build_option_settings(BuildOption p_build_option) {
465 ERR_FAIL_INDEX_V(p_build_option, BUILD_OPTION_MAX, (HashMap<String, LocalVector<Variant>>()));
466 return build_option_settings.has(p_build_option) ? build_option_settings[p_build_option] : HashMap<String, LocalVector<Variant>>();
467 }
468
469 LocalVector<String> EditorBuildProfile::get_build_option_classes(BuildOption p_build_option) {
470 ERR_FAIL_INDEX_V(p_build_option, BUILD_OPTION_MAX, LocalVector<String>());
471 return build_option_classes.has(p_build_option) ? build_option_classes[p_build_option] : LocalVector<String>();
472 }
473
474 String EditorBuildProfile::get_build_option_category_name(BuildOptionCategory p_build_option_category) {
475 ERR_FAIL_INDEX_V(p_build_option_category, BUILD_OPTION_CATEGORY_MAX, String());
476
477 const char *build_option_subcategories[BUILD_OPTION_CATEGORY_MAX]{
478 TTRC("General Features:"),
479 TTRC("Graphics and Rendering:"),
480 TTRC("Physics Systems:"),
481 TTRC("Text Rendering and Font Options:"),
482 };
483
484 return TTRGET(build_option_subcategories[p_build_option_category]);
485 }
486
487 Error EditorBuildProfile::save_to_file(const String &p_path) {
488 Dictionary data;
489 data["type"] = "build_profile";
490 Array dis_classes;
491 for (const StringName &E : disabled_classes) {
492 dis_classes.push_back(String(E));
493 }
494 dis_classes.sort();
495 data["disabled_classes"] = dis_classes;
496
497 Dictionary dis_build_options;
498 for (int i = 0; i < BUILD_OPTION_MAX; i++) {
499 if (build_options_disabled[i] != build_option_disabled_by_default[i]) {
500 if (build_options_disabled[i]) {
501 dis_build_options[build_option_identifiers[i]] = build_option_disable_values[i];
502 } else {
503 dis_build_options[build_option_identifiers[i]] = !build_option_disable_values[i];
504 }
505 }
506 }
507
508 data["disabled_build_options"] = dis_build_options;
509
510 if (!force_detect_classes.is_empty()) {
511 data["force_detect_classes"] = force_detect_classes;
512 }
513
514 Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE);
515 ERR_FAIL_COND_V_MSG(f.is_null(), ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
516
517 String text = JSON::stringify(data, "\t");
518 f->store_string(text);
519 return OK;
520 }
521
522 Error EditorBuildProfile::load_from_file(const String &p_path) {
523 Error err;
524 String text = FileAccess::get_file_as_string(p_path, &err);
525 if (err != OK) {
526 return err;
527 }
528
529 JSON json;
530 err = json.parse(text);
531 if (err != OK) {
532 ERR_PRINT("Error parsing '" + p_path + "' on line " + itos(json.get_error_line()) + ": " + json.get_error_message());
533 return ERR_PARSE_ERROR;
534 }
535
536 Dictionary data = json.get_data();
537
538 if (!data.has("type") || String(data["type"]) != "build_profile") {
539 ERR_PRINT("Error parsing '" + p_path + "', it's not a build profile.");
540 return ERR_PARSE_ERROR;
541 }
542
543 disabled_classes.clear();
544
545 if (data.has("disabled_classes")) {
546 Array disabled_classes_arr = data["disabled_classes"];
547 for (int i = 0; i < disabled_classes_arr.size(); i++) {
548 disabled_classes.insert(disabled_classes_arr[i]);
549 }
550 }
551
552 for (int i = 0; i < BUILD_OPTION_MAX; i++) {
553 build_options_disabled[i] = build_option_disabled_by_default[i];
554 }
555
556 if (data.has("disabled_build_options")) {
557 Dictionary disabled_build_options_arr = data["disabled_build_options"];
558
559 for (const KeyValue<Variant, Variant> &kv : disabled_build_options_arr) {
560 String key = kv.key;
561
562 for (int i = 0; i < BUILD_OPTION_MAX; i++) {
563 String f = build_option_identifiers[i];
564 if (f == key) {
565 build_options_disabled[i] = true;
566 break;
567 }
568 }
569 }
570 }
571
572 if (data.has("force_detect_classes")) {
573 force_detect_classes = data["force_detect_classes"];
574 }
575
576 return OK;
577 }
578
579 void EditorBuildProfile::_bind_methods() {
580 ClassDB::bind_method(D_METHOD("set_disable_class", "class_name", "disable"), &EditorBuildProfile::set_disable_class);
581 ClassDB::bind_method(D_METHOD("is_class_disabled", "class_name"), &EditorBuildProfile::is_class_disabled);
582
583 ClassDB::bind_method(D_METHOD("set_disable_build_option", "build_option", "disable"), &EditorBuildProfile::set_disable_build_option);
584 ClassDB::bind_method(D_METHOD("is_build_option_disabled", "build_option"), &EditorBuildProfile::is_build_option_disabled);
585
586 ClassDB::bind_method(D_METHOD("get_build_option_name", "build_option"), &EditorBuildProfile::_get_build_option_name);
587
588 ClassDB::bind_method(D_METHOD("save_to_file", "path"), &EditorBuildProfile::save_to_file);
589 ClassDB::bind_method(D_METHOD("load_from_file", "path"), &EditorBuildProfile::load_from_file);
590
591 BIND_ENUM_CONSTANT(BUILD_OPTION_3D);
592 BIND_ENUM_CONSTANT(BUILD_OPTION_NAVIGATION_2D);
593 BIND_ENUM_CONSTANT(BUILD_OPTION_NAVIGATION_3D);
594 BIND_ENUM_CONSTANT(BUILD_OPTION_XR);
595 BIND_ENUM_CONSTANT(BUILD_OPTION_OPENXR);
596 BIND_ENUM_CONSTANT(BUILD_OPTION_WAYLAND);
597 BIND_ENUM_CONSTANT(BUILD_OPTION_X11);
598 BIND_ENUM_CONSTANT(BUILD_OPTION_RENDERING_DEVICE);
599 BIND_ENUM_CONSTANT(BUILD_OPTION_FORWARD_RENDERER);
600 BIND_ENUM_CONSTANT(BUILD_OPTION_MOBILE_RENDERER);
601 BIND_ENUM_CONSTANT(BUILD_OPTION_VULKAN);
602 BIND_ENUM_CONSTANT(BUILD_OPTION_D3D12);
603 BIND_ENUM_CONSTANT(BUILD_OPTION_METAL);
604 BIND_ENUM_CONSTANT(BUILD_OPTION_OPENGL);
605 BIND_ENUM_CONSTANT(BUILD_OPTION_PHYSICS_2D);
606 BIND_ENUM_CONSTANT(BUILD_OPTION_PHYSICS_GODOT_2D);
607 BIND_ENUM_CONSTANT(BUILD_OPTION_PHYSICS_3D);
608 BIND_ENUM_CONSTANT(BUILD_OPTION_PHYSICS_GODOT_3D);
609 BIND_ENUM_CONSTANT(BUILD_OPTION_PHYSICS_JOLT);
610 BIND_ENUM_CONSTANT(BUILD_OPTION_TEXT_SERVER_FALLBACK);
611 BIND_ENUM_CONSTANT(BUILD_OPTION_TEXT_SERVER_ADVANCED);
612 BIND_ENUM_CONSTANT(BUILD_OPTION_DYNAMIC_FONTS);
613 BIND_ENUM_CONSTANT(BUILD_OPTION_WOFF2_FONTS);
614 BIND_ENUM_CONSTANT(BUILD_OPTION_GRAPHITE_FONTS);
615 BIND_ENUM_CONSTANT(BUILD_OPTION_MSDFGEN);
616 BIND_ENUM_CONSTANT(BUILD_OPTION_MAX);
617
618 BIND_ENUM_CONSTANT(BUILD_OPTION_CATEGORY_GENERAL);
619 BIND_ENUM_CONSTANT(BUILD_OPTION_CATEGORY_GRAPHICS);
620 BIND_ENUM_CONSTANT(BUILD_OPTION_CATEGORY_PHYSICS);
621 BIND_ENUM_CONSTANT(BUILD_OPTION_CATEGORY_TEXT_SERVER);
622 BIND_ENUM_CONSTANT(BUILD_OPTION_CATEGORY_MAX);
623 }
624
625 EditorBuildProfile::EditorBuildProfile() {
626 reset_build_options();
627
628 HashMap<String, LocalVector<Variant>> settings_openxr = {
629 { "xr/openxr/enabled", { true } },
630 };
631 build_option_settings.insert(BUILD_OPTION_OPENXR, settings_openxr);
632
633 HashMap<String, LocalVector<Variant>> settings_wayland = {
634 { "display/display_server/driver.linuxbsd", { "default", "wayland" } },
635 };
636 build_option_settings.insert(BUILD_OPTION_WAYLAND, settings_wayland);
637
638 HashMap<String, LocalVector<Variant>> settings_x11 = {
639 { "display/display_server/driver.linuxbsd", { "default", "x11" } },
640 };
641 build_option_settings.insert(BUILD_OPTION_X11, settings_x11);
642
643 HashMap<String, LocalVector<Variant>> settings_rd = {
644 { "rendering/renderer/rendering_method", { "forward_plus", "mobile" } },
645 { "rendering/renderer/rendering_method.mobile", { "forward_plus", "mobile" } },
646 { "rendering/renderer/rendering_method.web", { "forward_plus", "mobile" } },
647 };
648 build_option_settings.insert(BUILD_OPTION_RENDERING_DEVICE, settings_rd);
649
650 HashMap<String, LocalVector<Variant>> settings_vulkan = {
651 { "rendering/rendering_device/driver", { "vulkan" } },
652 { "rendering/rendering_device/driver.windows", { "vulkan" } },
653 { "rendering/rendering_device/driver.linuxbsd", { "vulkan" } },
654 { "rendering/rendering_device/driver.android", { "vulkan" } },
655 { "rendering/rendering_device/driver.ios", { "vulkan" } },
656 { "rendering/rendering_device/driver.macos", { "vulkan" } },
657 { "rendering/rendering_device/fallback_to_vulkan", { true } },
658 };
659 build_option_settings.insert(BUILD_OPTION_VULKAN, settings_vulkan);
660
661 HashMap<String, LocalVector<Variant>> settings_d3d12 = {
662 { "rendering/rendering_device/driver", { "d3d12" } },
663 { "rendering/rendering_device/driver.windows", { "d3d12" } },
664 { "rendering/rendering_device/driver.linuxbsd", { "d3d12" } },
665 { "rendering/rendering_device/driver.android", { "d3d12" } },
666 { "rendering/rendering_device/driver.ios", { "d3d12" } },
667 { "rendering/rendering_device/driver.macos", { "d3d12" } },
668 { "rendering/rendering_device/fallback_to_d3d12", { true } },
669 };
670 build_option_settings.insert(BUILD_OPTION_D3D12, settings_d3d12);
671
672 HashMap<String, LocalVector<Variant>> settings_metal = {
673 { "rendering/rendering_device/driver", { "metal" } },
674 { "rendering/rendering_device/driver.ios", { "metal" } },
675 { "rendering/rendering_device/driver.macos", { "metal" } },
676 };
677 build_option_settings.insert(BUILD_OPTION_METAL, settings_metal);
678
679 HashMap<String, LocalVector<Variant>> settings_opengl = {
680 { "rendering/renderer/rendering_method", { "gl_compatibility" } },
681 { "rendering/renderer/rendering_method.mobile", { "gl_compatibility" } },
682 { "rendering/renderer/rendering_method.web", { "gl_compatibility" } },
683 { "rendering/rendering_device/fallback_to_opengl3", { true } },
684 };
685 build_option_settings.insert(BUILD_OPTION_OPENGL, settings_opengl);
686
687 HashMap<String, LocalVector<Variant>> settings_phy_godot_3d = {
688 { "physics/3d/physics_engine", { "DEFAULT", "GodotPhysics3D" } },
689 };
690 build_option_settings.insert(BUILD_OPTION_PHYSICS_GODOT_3D, settings_phy_godot_3d);
691
692 HashMap<String, LocalVector<Variant>> settings_jolt = {
693 { "physics/3d/physics_engine", { "Jolt Physics" } },
694 };
695 build_option_settings.insert(BUILD_OPTION_PHYSICS_JOLT, settings_jolt);
696
697 HashMap<String, LocalVector<Variant>> settings_msdfgen = {
698 { "gui/theme/default_font_multichannel_signed_distance_field", { true } },
699 };
700 build_option_settings.insert(BUILD_OPTION_MSDFGEN, settings_msdfgen);
701 }
702
703 //////////////////////////
704
705 void EditorBuildProfileManager::_notification(int p_what) {
706 switch (p_what) {
707 case NOTIFICATION_READY: {
708 String last_file = EditorSettings::get_singleton()->get_project_metadata("build_profile", "last_file_path", "");
709 if (!last_file.is_empty()) {
710 _import_profile(last_file);
711 }
712 if (edited.is_null()) {
713 edited.instantiate();
714 _update_edited_profile();
715 }
716
717 } break;
718 }
719 }
720
721 void EditorBuildProfileManager::_profile_action(int p_action) {
722 last_action = Action(p_action);
723
724 switch (p_action) {
725 case ACTION_RESET: {
726 confirm_dialog->set_text(TTR("Reset the edited profile?"));
727 confirm_dialog->popup_centered();
728 } break;
729 case ACTION_LOAD: {
730 import_profile->popup_file_dialog();
731 } break;
732 case ACTION_SAVE: {
733 if (!profile_path->get_text().is_empty()) {
734 Error err = edited->save_to_file(profile_path->get_text());
735 if (err != OK) {
736 EditorNode::get_singleton()->show_warning(TTR("File saving failed."));
737 }
738 break;
739 }
740 [[fallthrough]];
741 }
742 case ACTION_SAVE_AS: {
743 export_profile->popup_file_dialog();
744 export_profile->set_current_file(profile_path->get_text());
745 } break;
746 case ACTION_NEW: {
747 confirm_dialog->set_text(TTR("Create a new profile?"));
748 confirm_dialog->popup_centered();
749 } break;
750 case ACTION_DETECT: {
751 String text = TTR("This will scan all files in the current project to detect used classes.\nNote that the first scan may take a while, specially in larger projects.");
752 #ifdef MODULE_MONO_ENABLED
753 text += "\n\n" + TTR("Warning: Class detection for C# scripts is not currently available, and such files will be ignored.");
754 #endif // MODULE_MONO_ENABLED
755 confirm_dialog->set_text(text);
756 confirm_dialog->popup_centered();
757 } break;
758 case ACTION_MAX: {
759 } break;
760 }
761 }
762
763 void EditorBuildProfileManager::_find_files(EditorFileSystemDirectory *p_dir, const HashMap<String, DetectedFile> &p_cache, HashMap<String, DetectedFile> &r_detected) {
764 if (p_dir == nullptr || p_dir->get_path().get_file().begins_with(".")) {
765 return;
766 }
767
768 for (int i = 0; i < p_dir->get_file_count(); i++) {
769 String p = p_dir->get_file_path(i);
770
771 if (EditorNode::get_singleton()->progress_task_step("detect_classes_from_project", p, 1)) {
772 project_scan_canceled = true;
773 return;
774 }
775
776 String p_check = p;
777 // Make so that the import file is the one checked if available,
778 // so the cache can be updated when it changes.
779 if (ResourceFormatImporter::get_singleton()->exists(p_check)) {
780 p_check += ".import";
781 }
782
783 uint64_t timestamp = 0;
784 String md5;
785
786 if (p_cache.has(p)) {
787 const DetectedFile &cache = p_cache[p];
788 // Check if timestamp and MD5 match.
789 timestamp = FileAccess::get_modified_time(p_check);
790 bool cache_valid = true;
791 if (cache.timestamp != timestamp) {
792 md5 = FileAccess::get_md5(p_check);
793 if (md5 != cache.md5) {
794 cache_valid = false;
795 }
796 }
797
798 if (cache_valid) {
799 r_detected.insert(p, cache);
800 continue;
801 }
802 }
803
804 // Not cached, or cache invalid.
805
806 DetectedFile cache;
807
808 HashSet<StringName> classes;
809 ResourceLoader::get_classes_used(p, &classes);
810 for (const StringName &E : classes) {
811 cache.classes.push_back(E);
812 }
813
814 HashSet<String> build_deps;
815 ResourceFormatImporter::get_singleton()->get_build_dependencies(p, &build_deps);
816 for (const String &E : build_deps) {
817 cache.build_deps.push_back(E);
818 }
819
820 if (md5.is_empty()) {
821 cache.timestamp = FileAccess::get_modified_time(p_check);
822 cache.md5 = FileAccess::get_md5(p_check);
823 } else {
824 cache.timestamp = timestamp;
825 cache.md5 = md5;
826 }
827
828 r_detected.insert(p, cache);
829 }
830
831 for (int i = 0; i < p_dir->get_subdir_count(); i++) {
832 _find_files(p_dir->get_subdir(i), p_cache, r_detected);
833 }
834 }
835
836 void EditorBuildProfileManager::_detect_from_project() {
837 EditorNode::get_singleton()->progress_add_task("detect_classes_from_project", TTRC("Scanning Project for Used Classes"), 3, true);
838
839 HashMap<String, DetectedFile> previous_file_cache;
840
841 Ref<FileAccess> f = FileAccess::open(EditorPaths::get_singleton()->get_project_settings_dir().path_join("used_class_cache"), FileAccess::READ);
842 if (f.is_valid()) {
843 while (!f->eof_reached()) {
844 String l = f->get_line();
845 Vector<String> fields = l.split("::");
846 if (fields.size() == 5) {
847 const String &path = fields[0];
848 DetectedFile df;
849 df.timestamp = fields[1].to_int();
850 df.md5 = fields[2];
851 df.classes = fields[3].split(",", false);
852 df.build_deps = fields[4].split(",", false);
853 previous_file_cache.insert(path, df);
854 }
855 }
856 f.unref();
857 }
858
859 HashMap<String, DetectedFile> updated_file_cache;
860
861 _find_files(EditorFileSystem::get_singleton()->get_filesystem(), previous_file_cache, updated_file_cache);
862
863 if (project_scan_canceled) {
864 project_scan_canceled = false;
865 EditorNode::get_singleton()->progress_end_task("detect_classes_from_project");
866
867 return;
868 }
869
870 EditorNode::get_singleton()->progress_task_step("detect_classes_from_project", TTRC("Processing Classes Found"), 2);
871
872 HashSet<StringName> used_classes;
873 LocalVector<String> used_build_deps;
874
875 // Find classes and update the disk cache in the process.
876 f = FileAccess::open(EditorPaths::get_singleton()->get_project_settings_dir().path_join("used_class_cache"), FileAccess::WRITE);
877
878 for (const KeyValue<String, DetectedFile> &E : updated_file_cache) {
879 String l = E.key + "::" + itos(E.value.timestamp) + "::" + E.value.md5 + "::";
880 for (int i = 0; i < E.value.classes.size(); i++) {
881 String c = E.value.classes[i];
882 if (i > 0) {
883 l += ",";
884 }
885 l += c;
886 used_classes.insert(c);
887 }
888 l += "::";
889 for (int i = 0; i < E.value.build_deps.size(); i++) {
890 String c = E.value.build_deps[i];
891 if (i > 0) {
892 l += ",";
893 }
894 l += c;
895 used_build_deps.push_back(c);
896 }
897 f->store_line(l);
898 }
899
900 f.unref();
901
902 // Add classes that are either necessary for the engine to work properly, or there isn't a way to infer their use.
903
904 // HACK: Some classes are included due to creating clashes with unrelated when disabled.
905 // Until that is fixed, they need to always be enabled.
906 const LocalVector<String> hardcoded_classes = {
907 "Font",
908 "InputEvent",
909 "ShaderInclude",
910 "StyleBox",
911 "Window",
912 };
913
914 for (const String &hc_class : hardcoded_classes) {
915 used_classes.insert(hc_class);
916
917 LocalVector<StringName> inheriters;
918 ClassDB::get_inheriters_from_class(hc_class, inheriters);
919 for (const StringName &inheriter : inheriters) {
920 used_classes.insert(inheriter);
921 }
922 }
923
924 // Add forced classes typed by the user.
925
926 const Vector<String> force_detect = edited->get_force_detect_classes().split(",");
927 for (const String &class_name : force_detect) {
928 const String class_stripped = class_name.strip_edges();
929 if (!class_stripped.is_empty()) {
930 used_classes.insert(class_stripped);
931 }
932 }
933
934 // Filter all classes to discard inherited ones.
935
936 HashSet<StringName> all_used_classes;
937
938 for (const StringName &E : used_classes) {
939 StringName c = E;
940 if (!ClassDB::class_exists(c)) {
941 // Maybe this is an old class that got replaced? Try getting compat class.
942 c = ClassDB::get_compatibility_class(c);
943 if (!c) {
944 // No luck, skip.
945 continue;
946 }
947 }
948
949 List<StringName> dependencies;
950 ClassDB::get_class_dependencies(E, &dependencies);
951 for (const StringName &dep : dependencies) {
952 if (!all_used_classes.has(dep)) {
953 // Add classes which this class depends upon.
954 all_used_classes.insert(dep);
955 }
956 }
957
958 while (c) {
959 all_used_classes.insert(c);
960 c = ClassDB::get_parent_class(c);
961 }
962 }
963
964 edited->clear_disabled_classes();
965
966 LocalVector<StringName> all_classes;
967 ClassDB::get_class_list(all_classes);
968
969 for (const StringName &class_name : all_classes) {
970 ClassDB::APIType class_api = ClassDB::get_api_type(class_name);
971 if (class_api == ClassDB::API_EDITOR || class_api != ClassDB::API_CORE) {
972 continue; // This class is editor-only or not from Godot itself.
973 }
974
975 if (class_name != "Resource" && class_name != "Node" && !ClassDB::is_parent_class(class_name, "Resource") && !ClassDB::is_parent_class(class_name, "Node")) {
976 continue;
977 }
978
979 if (all_used_classes.has(class_name)) {
980 continue;
981 }
982
983 StringName p = ClassDB::get_parent_class(class_name);
984 if (!p || all_used_classes.has(p)) {
985 // If no parent, or if the parent is enabled, then add to disabled classes.
986 // This way we avoid disabling redundant classes.
987 edited->set_disable_class(class_name, true);
988 }
989 }
990
991 edited->reset_build_options();
992
993 for (int i = 0; i < EditorBuildProfile::BUILD_OPTION_MAX; i++) {
994 // Check if the build option requires other options that are currently disabled.
995 LocalVector<EditorBuildProfile::BuildOption> dependencies = EditorBuildProfile::get_build_option_dependencies(EditorBuildProfile::BuildOption(i));
996 if (!dependencies.is_empty()) {
997 bool disable = true;
998 for (EditorBuildProfile::BuildOption dependency : dependencies) {
999 if (!edited->is_build_option_disabled(dependency)) {
1000 disable = false;
1001 break;
1002 }
1003 }
1004
1005 if (disable) {
1006 edited->set_disable_build_option(EditorBuildProfile::BuildOption(i), true);
1007 continue;
1008 }
1009 }
1010
1011 bool skip = false;
1012 bool ignore = true;
1013
1014 // Check if the build option has enabled classes using it.
1015 const LocalVector<String> classes = EditorBuildProfile::get_build_option_classes(EditorBuildProfile::BuildOption(i));
1016 if (!classes.is_empty()) {
1017 for (StringName class_name : classes) {
1018 if (all_used_classes.has(class_name) && !edited->is_class_disabled(class_name)) {
1019 skip = true;
1020 break;
1021 }
1022 }
1023
1024 if (skip) {
1025 continue;
1026 }
1027
1028 ignore = false;
1029 }
1030
1031 // Check if there's project settings requiring it.
1032 const HashMap<String, LocalVector<Variant>> settings_list = EditorBuildProfile::get_build_option_settings(EditorBuildProfile::BuildOption(i));
1033 if (!settings_list.is_empty()) {
1034 for (KeyValue<String, LocalVector<Variant>> KV : settings_list) {
1035 Variant proj_value = GLOBAL_GET(KV.key);
1036 for (Variant value : KV.value) {
1037 if (proj_value == value) {
1038 skip = true;
1039 break;
1040 }
1041 }
1042
1043 if (skip) {
1044 break;
1045 }
1046 }
1047
1048 if (skip) {
1049 continue;
1050 }
1051
1052 ignore = false;
1053 }
1054
1055 // Check if a resource setting depends on it.
1056 if (used_build_deps.has(EditorBuildProfile::get_build_option_identifier(EditorBuildProfile::BuildOption(i)))) {
1057 continue;
1058 } else if (EditorBuildProfile::get_build_option_explicit_use(EditorBuildProfile::BuildOption(i))) {
1059 ignore = false;
1060 }
1061
1062 if (!skip && !ignore) {
1063 edited->set_disable_build_option(EditorBuildProfile::BuildOption(i), true);
1064 }
1065 }
1066
1067 if (edited->is_build_option_disabled(EditorBuildProfile::BUILD_OPTION_TEXT_SERVER_ADVANCED)) {
1068 edited->set_disable_build_option(EditorBuildProfile::BUILD_OPTION_TEXT_SERVER_FALLBACK, false);
1069 }
1070
1071 EditorNode::get_singleton()->progress_end_task("detect_classes_from_project");
1072 }
1073
1074 void EditorBuildProfileManager::_action_confirm() {
1075 switch (last_action) {
1076 case ACTION_RESET: {
1077 edited.instantiate();
1078 _update_edited_profile();
1079 } break;
1080 case ACTION_LOAD: {
1081 } break;
1082 case ACTION_SAVE: {
1083 } break;
1084 case ACTION_SAVE_AS: {
1085 } break;
1086 case ACTION_NEW: {
1087 profile_path->set_text("");
1088 edited.instantiate();
1089 _update_edited_profile();
1090 } break;
1091 case ACTION_DETECT: {
1092 _detect_from_project();
1093 _update_edited_profile();
1094 } break;
1095 case ACTION_MAX: {
1096 } break;
1097 }
1098 }
1099
1100 void EditorBuildProfileManager::_hide_requested() {
1101 _cancel_pressed(); // From AcceptDialog.
1102 }
1103
1104 void EditorBuildProfileManager::_fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected) {
1105 TreeItem *class_item = class_list->create_item(p_parent);
1106 class_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
1107 class_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_class));
1108 const String &text = p_class;
1109
1110 bool disabled = edited->is_class_disabled(p_class);
1111 if (disabled) {
1112 class_item->set_custom_color(0, class_list->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
1113 }
1114
1115 class_item->set_text(0, text);
1116 class_item->set_editable(0, true);
1117 class_item->set_selectable(0, true);
1118 class_item->set_metadata(0, p_class);
1119
1120 bool collapsed = edited->is_item_collapsed(p_class);
1121 class_item->set_collapsed(collapsed);
1122
1123 if (p_class == p_selected) {
1124 class_item->select(0);
1125 }
1126 if (disabled) {
1127 // Class disabled, do nothing else (do not show further).
1128 return;
1129 }
1130
1131 class_item->set_checked(0, true); // If it's not disabled, its checked.
1132
1133 List<StringName> child_classes;
1134 ClassDB::get_direct_inheriters_from_class(p_class, &child_classes);
1135 child_classes.sort_custom<StringName::AlphCompare>();
1136
1137 for (const StringName &name : child_classes) {
1138 ClassDB::APIType class_api = ClassDB::get_api_type(name);
1139 if (class_api != ClassDB::API_EDITOR && class_api == ClassDB::API_CORE) {
1140 _fill_classes_from(class_item, name, p_selected);
1141 }
1142 }
1143 }
1144
1145 void EditorBuildProfileManager::_class_list_item_selected() {
1146 if (updating_build_options) {
1147 return;
1148 }
1149
1150 TreeItem *item = class_list->get_selected();
1151 if (!item) {
1152 return;
1153 }
1154
1155 Variant md = item->get_metadata(0);
1156 if (md.is_string()) {
1157 description_bit->parse_symbol("class|" + md.operator String() + "|");
1158 } else if (md.get_type() == Variant::INT) {
1159 String build_option_description = EditorBuildProfile::get_build_option_description(EditorBuildProfile::BuildOption((int)md));
1160 description_bit->set_custom_text(TTR(item->get_text(0)), String(), TTRGET(build_option_description));
1161 }
1162 }
1163
1164 void EditorBuildProfileManager::_class_list_item_edited() {
1165 if (updating_build_options) {
1166 return;
1167 }
1168
1169 TreeItem *item = class_list->get_edited();
1170 if (!item) {
1171 return;
1172 }
1173
1174 bool checked = item->is_checked(0);
1175
1176 Variant md = item->get_metadata(0);
1177 if (md.is_string()) {
1178 String class_selected = md;
1179 edited->set_disable_class(class_selected, !checked);
1180 _update_edited_profile();
1181 } else if (md.get_type() == Variant::INT) {
1182 int build_option_selected = md;
1183 edited->set_disable_build_option(EditorBuildProfile::BuildOption(build_option_selected), !checked);
1184 }
1185 }
1186
1187 void EditorBuildProfileManager::_class_list_item_collapsed(Object *p_item) {
1188 if (updating_build_options) {
1189 return;
1190 }
1191
1192 TreeItem *item = Object::cast_to<TreeItem>(p_item);
1193 if (!item) {
1194 return;
1195 }
1196
1197 Variant md = item->get_metadata(0);
1198 if (!md.is_string()) {
1199 return;
1200 }
1201
1202 String class_name = md;
1203 bool collapsed = item->is_collapsed();
1204 edited->set_item_collapsed(class_name, collapsed);
1205 }
1206
1207 void EditorBuildProfileManager::_update_edited_profile() {
1208 String class_selected;
1209 int build_option_selected = -1;
1210
1211 if (class_list->get_selected()) {
1212 Variant md = class_list->get_selected()->get_metadata(0);
1213 if (md.is_string()) {
1214 class_selected = md;
1215 } else if (md.get_type() == Variant::INT) {
1216 build_option_selected = md;
1217 }
1218 }
1219
1220 class_list->clear();
1221
1222 updating_build_options = true;
1223
1224 TreeItem *root = class_list->create_item();
1225
1226 HashMap<EditorBuildProfile::BuildOptionCategory, TreeItem *> subcats;
1227 for (int i = 0; i < EditorBuildProfile::BUILD_OPTION_CATEGORY_MAX; i++) {
1228 TreeItem *build_cat;
1229 build_cat = class_list->create_item(root);
1230
1231 build_cat->set_text(0, EditorBuildProfile::get_build_option_category_name(EditorBuildProfile::BuildOptionCategory(i)));
1232 subcats[EditorBuildProfile::BuildOptionCategory(i)] = build_cat;
1233 }
1234
1235 for (int i = 0; i < EditorBuildProfile::BUILD_OPTION_MAX; i++) {
1236 TreeItem *build_option;
1237 build_option = class_list->create_item(subcats[EditorBuildProfile::get_build_option_category(EditorBuildProfile::BuildOption(i))]);
1238
1239 build_option->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
1240 build_option->set_text(0, EditorBuildProfile::get_build_option_name(EditorBuildProfile::BuildOption(i)));
1241 build_option->set_selectable(0, true);
1242 build_option->set_editable(0, true);
1243 build_option->set_metadata(0, i);
1244 if (!edited->is_build_option_disabled(EditorBuildProfile::BuildOption(i))) {
1245 build_option->set_checked(0, true);
1246 }
1247
1248 if (i == build_option_selected) {
1249 build_option->select(0);
1250 }
1251 }
1252
1253 TreeItem *classes = class_list->create_item(root);
1254 classes->set_text(0, TTR("Nodes and Classes:"));
1255
1256 _fill_classes_from(classes, "Node", class_selected);
1257 _fill_classes_from(classes, "Resource", class_selected);
1258
1259 force_detect_classes->set_text(edited->get_force_detect_classes());
1260
1261 updating_build_options = false;
1262
1263 _class_list_item_selected();
1264 }
1265
1266 void EditorBuildProfileManager::_force_detect_classes_changed(const String &p_text) {
1267 if (updating_build_options) {
1268 return;
1269 }
1270 edited->set_force_detect_classes(force_detect_classes->get_text());
1271 }
1272
1273 void EditorBuildProfileManager::_import_profile(const String &p_path) {
1274 Ref<EditorBuildProfile> profile;
1275 profile.instantiate();
1276 Error err = profile->load_from_file(p_path);
1277 String basefile = p_path.get_file();
1278 if (err != OK) {
1279 EditorNode::get_singleton()->show_warning(vformat(TTR("File '%s' format is invalid, import aborted."), basefile));
1280 return;
1281 }
1282
1283 profile_path->set_text(p_path);
1284 EditorSettings::get_singleton()->set_project_metadata("build_profile", "last_file_path", p_path);
1285
1286 edited = profile;
1287 _update_edited_profile();
1288 }
1289
1290 void EditorBuildProfileManager::_export_profile(const String &p_path) {
1291 ERR_FAIL_COND(edited.is_null());
1292 Error err = edited->save_to_file(p_path);
1293 if (err != OK) {
1294 EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving profile to path: '%s'."), p_path));
1295 } else {
1296 profile_path->set_text(p_path);
1297 EditorSettings::get_singleton()->set_project_metadata("build_profile", "last_file_path", p_path);
1298 }
1299 }
1300
1301 Ref<EditorBuildProfile> EditorBuildProfileManager::get_current_profile() {
1302 return edited;
1303 }
1304
1305 EditorBuildProfileManager *EditorBuildProfileManager::singleton = nullptr;
1306
1307 void EditorBuildProfileManager::_bind_methods() {
1308 ClassDB::bind_method("_update_selected_profile", &EditorBuildProfileManager::_update_edited_profile);
1309 }
1310
1311 EditorBuildProfileManager::EditorBuildProfileManager() {
1312 VBoxContainer *main_vbc = memnew(VBoxContainer);
1313 add_child(main_vbc);
1314
1315 HBoxContainer *path_hbc = memnew(HBoxContainer);
1316 profile_path = memnew(LineEdit);
1317 path_hbc->add_child(profile_path);
1318 profile_path->set_accessibility_name(TTRC("Profile Path"));
1319 profile_path->set_editable(true);
1320 profile_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1321
1322 profile_actions[ACTION_NEW] = memnew(Button(TTR("New")));
1323 path_hbc->add_child(profile_actions[ACTION_NEW]);
1324 profile_actions[ACTION_NEW]->connect(SceneStringName(pressed), callable_mp(this, &EditorBuildProfileManager::_profile_action).bind(ACTION_NEW));
1325
1326 profile_actions[ACTION_LOAD] = memnew(Button(TTR("Load")));
1327 path_hbc->add_child(profile_actions[ACTION_LOAD]);
1328 profile_actions[ACTION_LOAD]->connect(SceneStringName(pressed), callable_mp(this, &EditorBuildProfileManager::_profile_action).bind(ACTION_LOAD));
1329
1330 profile_actions[ACTION_SAVE] = memnew(Button(TTR("Save")));
1331 path_hbc->add_child(profile_actions[ACTION_SAVE]);
1332 profile_actions[ACTION_SAVE]->connect(SceneStringName(pressed), callable_mp(this, &EditorBuildProfileManager::_profile_action).bind(ACTION_SAVE));
1333
1334 profile_actions[ACTION_SAVE_AS] = memnew(Button(TTR("Save As")));
1335 path_hbc->add_child(profile_actions[ACTION_SAVE_AS]);
1336 profile_actions[ACTION_SAVE_AS]->connect(SceneStringName(pressed), callable_mp(this, &EditorBuildProfileManager::_profile_action).bind(ACTION_SAVE_AS));
1337
1338 main_vbc->add_margin_child(TTR("Profile:"), path_hbc);
1339
1340 main_vbc->add_child(memnew(HSeparator));
1341
1342 HBoxContainer *profiles_hbc = memnew(HBoxContainer);
1343
1344 profile_actions[ACTION_RESET] = memnew(Button(TTR("Reset to Defaults")));
1345 profiles_hbc->add_child(profile_actions[ACTION_RESET]);
1346 profile_actions[ACTION_RESET]->connect(SceneStringName(pressed), callable_mp(this, &EditorBuildProfileManager::_profile_action).bind(ACTION_RESET));
1347
1348 profile_actions[ACTION_DETECT] = memnew(Button(TTR("Detect from Project")));
1349 profiles_hbc->add_child(profile_actions[ACTION_DETECT]);
1350 profile_actions[ACTION_DETECT]->connect(SceneStringName(pressed), callable_mp(this, &EditorBuildProfileManager::_profile_action).bind(ACTION_DETECT));
1351
1352 main_vbc->add_margin_child(TTR("Actions:"), profiles_hbc);
1353
1354 class_list = memnew(Tree);
1355 class_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
1356 class_list->set_hide_root(true);
1357 class_list->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
1358 class_list->set_scroll_hint_mode(Tree::SCROLL_HINT_MODE_BOTH);
1359 class_list->connect("cell_selected", callable_mp(this, &EditorBuildProfileManager::_class_list_item_selected));
1360 class_list->connect("item_edited", callable_mp(this, &EditorBuildProfileManager::_class_list_item_edited), CONNECT_DEFERRED);
1361 class_list->connect("item_collapsed", callable_mp(this, &EditorBuildProfileManager::_class_list_item_collapsed));
1362
1363 // It will be displayed once the user creates or chooses a profile.
1364 MarginContainer *mc = main_vbc->add_margin_child(TTRC("Configure Engine Compilation Profile:"), class_list, true);
1365 mc->set_theme_type_variation("NoBorderHorizontalWindow");
1366 mc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
1367
1368 description_bit = memnew(EditorHelpBit);
1369 description_bit->set_content_height_limits(80 * EDSCALE, 80 * EDSCALE);
1370 description_bit->connect("request_hide", callable_mp(this, &EditorBuildProfileManager::_hide_requested));
1371 main_vbc->add_margin_child(TTR("Description:"), description_bit, false);
1372
1373 confirm_dialog = memnew(ConfirmationDialog);
1374 add_child(confirm_dialog);
1375 confirm_dialog->set_title(TTR("Please Confirm:"));
1376 confirm_dialog->connect(SceneStringName(confirmed), callable_mp(this, &EditorBuildProfileManager::_action_confirm));
1377
1378 import_profile = memnew(EditorFileDialog);
1379 add_child(import_profile);
1380 import_profile->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
1381 import_profile->add_filter("*.gdbuild,*.build", TTR("Engine Compilation Profile"));
1382 import_profile->connect("file_selected", callable_mp(this, &EditorBuildProfileManager::_import_profile));
1383 import_profile->set_title(TTR("Load Profile"));
1384 import_profile->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
1385
1386 export_profile = memnew(EditorFileDialog);
1387 add_child(export_profile);
1388 export_profile->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
1389 export_profile->add_filter("*.gdbuild,*.build", TTR("Engine Compilation Profile"));
1390 export_profile->connect("file_selected", callable_mp(this, &EditorBuildProfileManager::_export_profile));
1391 export_profile->set_title(TTR("Export Profile"));
1392 export_profile->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
1393
1394 force_detect_classes = memnew(LineEdit);
1395 force_detect_classes->set_accessibility_name(TTRC("Forced Classes on Detect:"));
1396 main_vbc->add_margin_child(TTR("Forced Classes on Detect:"), force_detect_classes);
1397 force_detect_classes->connect(SceneStringName(text_changed), callable_mp(this, &EditorBuildProfileManager::_force_detect_classes_changed));
1398
1399 set_title(TTR("Edit Compilation Configuration Profile"));
1400
1401 singleton = this;
1402 }