Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/export/editor_export_plugin.cpp
9896 views
1
/**************************************************************************/
2
/* editor_export_plugin.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_export_plugin.h"
32
33
#include "core/config/project_settings.h"
34
#include "editor/export/editor_export_platform.h"
35
36
void EditorExportPlugin::set_export_base_path(const String &p_export_base_path) {
37
export_base_path = p_export_base_path;
38
}
39
40
const String &EditorExportPlugin::get_export_base_path() const {
41
return export_base_path;
42
}
43
44
void EditorExportPlugin::set_export_preset(const Ref<EditorExportPreset> &p_preset) {
45
if (p_preset.is_valid()) {
46
export_preset = p_preset;
47
}
48
}
49
50
Ref<EditorExportPreset> EditorExportPlugin::get_export_preset() const {
51
return export_preset;
52
}
53
54
Ref<EditorExportPlatform> EditorExportPlugin::get_export_platform() const {
55
if (export_preset.is_valid()) {
56
return export_preset->get_platform();
57
} else {
58
return Ref<EditorExportPlatform>();
59
}
60
}
61
62
void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {
63
ExtraFile ef;
64
ef.data = p_file;
65
ef.path = p_path;
66
ef.remap = p_remap;
67
extra_files.push_back(ef);
68
}
69
70
void EditorExportPlugin::add_shared_object(const String &p_path, const Vector<String> &p_tags, const String &p_target) {
71
shared_objects.push_back(SharedObject(p_path, p_tags, p_target));
72
}
73
74
void EditorExportPlugin::_add_shared_object(const SharedObject &p_shared_object) {
75
shared_objects.push_back(p_shared_object);
76
}
77
78
void EditorExportPlugin::add_apple_embedded_platform_framework(const String &p_path) {
79
apple_embedded_platform_frameworks.push_back(p_path);
80
}
81
82
void EditorExportPlugin::add_apple_embedded_platform_embedded_framework(const String &p_path) {
83
apple_embedded_platform_embedded_frameworks.push_back(p_path);
84
}
85
86
Vector<String> EditorExportPlugin::get_apple_embedded_platform_frameworks() const {
87
return apple_embedded_platform_frameworks;
88
}
89
90
Vector<String> EditorExportPlugin::get_apple_embedded_platform_embedded_frameworks() const {
91
return apple_embedded_platform_embedded_frameworks;
92
}
93
94
void EditorExportPlugin::add_apple_embedded_platform_plist_content(const String &p_plist_content) {
95
apple_embedded_platform_plist_content += p_plist_content + "\n";
96
}
97
98
String EditorExportPlugin::get_apple_embedded_platform_plist_content() const {
99
return apple_embedded_platform_plist_content;
100
}
101
102
void EditorExportPlugin::add_apple_embedded_platform_linker_flags(const String &p_flags) {
103
if (apple_embedded_platform_linker_flags.length() > 0) {
104
apple_embedded_platform_linker_flags += ' ';
105
}
106
apple_embedded_platform_linker_flags += p_flags;
107
}
108
109
String EditorExportPlugin::get_apple_embedded_platform_linker_flags() const {
110
return apple_embedded_platform_linker_flags;
111
}
112
113
void EditorExportPlugin::add_apple_embedded_platform_bundle_file(const String &p_path) {
114
apple_embedded_platform_bundle_files.push_back(p_path);
115
}
116
117
Vector<String> EditorExportPlugin::get_apple_embedded_platform_bundle_files() const {
118
return apple_embedded_platform_bundle_files;
119
}
120
121
void EditorExportPlugin::add_apple_embedded_platform_cpp_code(const String &p_code) {
122
apple_embedded_platform_cpp_code += p_code;
123
}
124
125
String EditorExportPlugin::get_apple_embedded_platform_cpp_code() const {
126
return apple_embedded_platform_cpp_code;
127
}
128
129
void EditorExportPlugin::add_macos_plugin_file(const String &p_path) {
130
macos_plugin_files.push_back(p_path);
131
}
132
133
const Vector<String> &EditorExportPlugin::get_macos_plugin_files() const {
134
return macos_plugin_files;
135
}
136
137
void EditorExportPlugin::add_apple_embedded_platform_project_static_lib(const String &p_path) {
138
apple_embedded_platform_project_static_libs.push_back(p_path);
139
}
140
141
Vector<String> EditorExportPlugin::get_apple_embedded_platform_project_static_libs() const {
142
return apple_embedded_platform_project_static_libs;
143
}
144
145
Variant EditorExportPlugin::get_option(const StringName &p_name) const {
146
ERR_FAIL_COND_V(export_preset.is_null(), Variant());
147
return export_preset->get(p_name);
148
}
149
150
String EditorExportPlugin::_has_valid_export_configuration(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset) {
151
String warning;
152
if (!supports_platform(p_export_platform)) {
153
warning += vformat(TTR("Plugin \"%s\" is not supported on \"%s\""), get_name(), p_export_platform->get_name());
154
warning += "\n";
155
return warning;
156
}
157
158
set_export_preset(p_preset);
159
List<EditorExportPlatform::ExportOption> options;
160
_get_export_options(p_export_platform, &options);
161
for (const EditorExportPlatform::ExportOption &E : options) {
162
String option_warning = _get_export_option_warning(p_export_platform, E.option.name);
163
if (!option_warning.is_empty()) {
164
warning += option_warning + "\n";
165
}
166
}
167
168
return warning;
169
}
170
171
void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const Vector<String> &p_features) {
172
GDVIRTUAL_CALL(_export_file, p_path, p_type, p_features);
173
}
174
175
void EditorExportPlugin::_export_begin_script(const Vector<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
176
GDVIRTUAL_CALL(_export_begin, p_features, p_debug, p_path, p_flags);
177
}
178
179
void EditorExportPlugin::_export_end_script() {
180
GDVIRTUAL_CALL(_export_end);
181
}
182
183
// Customization
184
185
bool EditorExportPlugin::_begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
186
bool ret = false;
187
GDVIRTUAL_CALL(_begin_customize_resources, p_platform, p_features, ret);
188
return ret;
189
}
190
191
Ref<Resource> EditorExportPlugin::_customize_resource(const Ref<Resource> &p_resource, const String &p_path) {
192
Ref<Resource> ret;
193
GDVIRTUAL_CALL(_customize_resource, p_resource, p_path, ret);
194
return ret;
195
}
196
197
bool EditorExportPlugin::_begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
198
bool ret = false;
199
GDVIRTUAL_CALL(_begin_customize_scenes, p_platform, p_features, ret);
200
return ret;
201
}
202
203
Node *EditorExportPlugin::_customize_scene(Node *p_root, const String &p_path) {
204
Node *ret = nullptr;
205
GDVIRTUAL_CALL(_customize_scene, p_root, p_path, ret);
206
return ret;
207
}
208
209
uint64_t EditorExportPlugin::_get_customization_configuration_hash() const {
210
uint64_t ret = 0;
211
GDVIRTUAL_CALL(_get_customization_configuration_hash, ret);
212
return ret;
213
}
214
215
void EditorExportPlugin::_end_customize_scenes() {
216
GDVIRTUAL_CALL(_end_customize_scenes);
217
}
218
219
void EditorExportPlugin::_end_customize_resources() {
220
GDVIRTUAL_CALL(_end_customize_resources);
221
}
222
223
String EditorExportPlugin::get_name() const {
224
String ret;
225
GDVIRTUAL_CALL(_get_name, ret);
226
return ret;
227
}
228
229
bool EditorExportPlugin::supports_platform(const Ref<EditorExportPlatform> &p_export_platform) const {
230
bool ret = false;
231
GDVIRTUAL_CALL(_supports_platform, p_export_platform, ret);
232
return ret;
233
}
234
235
PackedStringArray EditorExportPlugin::get_export_features(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
236
return _get_export_features(p_export_platform, p_debug);
237
}
238
239
PackedStringArray EditorExportPlugin::get_android_dependencies(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
240
PackedStringArray ret;
241
GDVIRTUAL_CALL(_get_android_dependencies, p_export_platform, p_debug, ret);
242
return ret;
243
}
244
245
PackedStringArray EditorExportPlugin::get_android_dependencies_maven_repos(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
246
PackedStringArray ret;
247
GDVIRTUAL_CALL(_get_android_dependencies_maven_repos, p_export_platform, p_debug, ret);
248
return ret;
249
}
250
251
PackedStringArray EditorExportPlugin::get_android_libraries(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
252
PackedStringArray ret;
253
GDVIRTUAL_CALL(_get_android_libraries, p_export_platform, p_debug, ret);
254
return ret;
255
}
256
257
String EditorExportPlugin::get_android_manifest_activity_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
258
String ret;
259
GDVIRTUAL_CALL(_get_android_manifest_activity_element_contents, p_export_platform, p_debug, ret);
260
return ret;
261
}
262
263
String EditorExportPlugin::get_android_manifest_application_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
264
String ret;
265
GDVIRTUAL_CALL(_get_android_manifest_application_element_contents, p_export_platform, p_debug, ret);
266
return ret;
267
}
268
269
String EditorExportPlugin::get_android_manifest_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
270
String ret;
271
GDVIRTUAL_CALL(_get_android_manifest_element_contents, p_export_platform, p_debug, ret);
272
return ret;
273
}
274
275
PackedByteArray EditorExportPlugin::update_android_prebuilt_manifest(const Ref<EditorExportPlatform> &p_export_platform, const PackedByteArray &p_manifest_data) const {
276
PackedByteArray ret;
277
GDVIRTUAL_CALL(_update_android_prebuilt_manifest, p_export_platform, p_manifest_data, ret);
278
return ret;
279
}
280
281
PackedStringArray EditorExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_platform, bool p_debug) const {
282
PackedStringArray ret;
283
GDVIRTUAL_CALL(_get_export_features, p_platform, p_debug, ret);
284
return ret;
285
}
286
287
void EditorExportPlugin::_get_export_options(const Ref<EditorExportPlatform> &p_platform, List<EditorExportPlatform::ExportOption> *r_options) const {
288
TypedArray<Dictionary> ret;
289
GDVIRTUAL_CALL(_get_export_options, p_platform, ret);
290
for (int i = 0; i < ret.size(); i++) {
291
Dictionary option = ret[i];
292
ERR_CONTINUE_MSG(!option.has("option"), "Missing required element 'option'");
293
ERR_CONTINUE_MSG(!option.has("default_value"), "Missing required element 'default_value'");
294
PropertyInfo property_info = PropertyInfo::from_dict(option["option"]);
295
Variant default_value = option["default_value"];
296
bool update_visibility = option.has("update_visibility") && option["update_visibility"];
297
r_options->push_back(EditorExportPlatform::ExportOption(property_info, default_value, update_visibility));
298
}
299
}
300
301
bool EditorExportPlugin::_should_update_export_options(const Ref<EditorExportPlatform> &p_platform) const {
302
bool ret = false;
303
GDVIRTUAL_CALL(_should_update_export_options, p_platform, ret);
304
return ret;
305
}
306
307
bool EditorExportPlugin::_get_export_option_visibility(const Ref<EditorExportPlatform> &p_export_platform, const String &p_option_name) const {
308
bool ret = true;
309
GDVIRTUAL_CALL(_get_export_option_visibility, p_export_platform, p_option_name, ret);
310
return ret;
311
}
312
313
String EditorExportPlugin::_get_export_option_warning(const Ref<EditorExportPlatform> &p_export_platform, const String &p_option_name) const {
314
String ret;
315
GDVIRTUAL_CALL(_get_export_option_warning, p_export_platform, p_option_name, ret);
316
return ret;
317
}
318
319
Dictionary EditorExportPlugin::_get_export_options_overrides(const Ref<EditorExportPlatform> &p_platform) const {
320
Dictionary ret;
321
GDVIRTUAL_CALL(_get_export_options_overrides, p_platform, ret);
322
return ret;
323
}
324
325
void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) {
326
}
327
328
void EditorExportPlugin::_export_begin(const HashSet<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
329
}
330
331
void EditorExportPlugin::_export_end() {}
332
333
void EditorExportPlugin::skip() {
334
skipped = true;
335
}
336
337
void EditorExportPlugin::_bind_methods() {
338
ClassDB::bind_method(D_METHOD("add_shared_object", "path", "tags", "target"), &EditorExportPlugin::add_shared_object);
339
ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file);
340
341
ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_project_static_lib", "path"), &EditorExportPlugin::add_apple_embedded_platform_project_static_lib);
342
ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_framework);
343
ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_embedded_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_embedded_framework);
344
ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_plist_content", "plist_content"), &EditorExportPlugin::add_apple_embedded_platform_plist_content);
345
ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_linker_flags", "flags"), &EditorExportPlugin::add_apple_embedded_platform_linker_flags);
346
ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_bundle_file", "path"), &EditorExportPlugin::add_apple_embedded_platform_bundle_file);
347
ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_cpp_code", "code"), &EditorExportPlugin::add_apple_embedded_platform_cpp_code);
348
349
#ifndef DISABLE_DEPRECATED
350
ClassDB::bind_method(D_METHOD("add_ios_project_static_lib", "path"), &EditorExportPlugin::add_apple_embedded_platform_project_static_lib);
351
ClassDB::bind_method(D_METHOD("add_ios_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_framework);
352
ClassDB::bind_method(D_METHOD("add_ios_embedded_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_embedded_framework);
353
ClassDB::bind_method(D_METHOD("add_ios_plist_content", "plist_content"), &EditorExportPlugin::add_apple_embedded_platform_plist_content);
354
ClassDB::bind_method(D_METHOD("add_ios_linker_flags", "flags"), &EditorExportPlugin::add_apple_embedded_platform_linker_flags);
355
ClassDB::bind_method(D_METHOD("add_ios_bundle_file", "path"), &EditorExportPlugin::add_apple_embedded_platform_bundle_file);
356
ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_apple_embedded_platform_cpp_code);
357
#endif
358
359
ClassDB::bind_method(D_METHOD("add_macos_plugin_file", "path"), &EditorExportPlugin::add_macos_plugin_file);
360
ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip);
361
ClassDB::bind_method(D_METHOD("get_option", "name"), &EditorExportPlugin::get_option);
362
363
ClassDB::bind_method(D_METHOD("get_export_preset"), &EditorExportPlugin::get_export_preset);
364
ClassDB::bind_method(D_METHOD("get_export_platform"), &EditorExportPlugin::get_export_platform);
365
366
GDVIRTUAL_BIND(_export_file, "path", "type", "features");
367
GDVIRTUAL_BIND(_export_begin, "features", "is_debug", "path", "flags");
368
GDVIRTUAL_BIND(_export_end);
369
370
GDVIRTUAL_BIND(_begin_customize_resources, "platform", "features");
371
GDVIRTUAL_BIND(_customize_resource, "resource", "path");
372
373
GDVIRTUAL_BIND(_begin_customize_scenes, "platform", "features");
374
GDVIRTUAL_BIND(_customize_scene, "scene", "path");
375
376
GDVIRTUAL_BIND(_get_customization_configuration_hash);
377
378
GDVIRTUAL_BIND(_end_customize_scenes);
379
GDVIRTUAL_BIND(_end_customize_resources);
380
381
GDVIRTUAL_BIND(_get_export_options, "platform");
382
GDVIRTUAL_BIND(_get_export_options_overrides, "platform");
383
GDVIRTUAL_BIND(_should_update_export_options, "platform");
384
GDVIRTUAL_BIND(_get_export_option_visibility, "platform", "option");
385
GDVIRTUAL_BIND(_get_export_option_warning, "platform", "option");
386
387
GDVIRTUAL_BIND(_get_export_features, "platform", "debug");
388
GDVIRTUAL_BIND(_get_name);
389
390
GDVIRTUAL_BIND(_supports_platform, "platform");
391
392
GDVIRTUAL_BIND(_get_android_dependencies, "platform", "debug");
393
GDVIRTUAL_BIND(_get_android_dependencies_maven_repos, "platform", "debug");
394
GDVIRTUAL_BIND(_get_android_libraries, "platform", "debug");
395
GDVIRTUAL_BIND(_get_android_manifest_activity_element_contents, "platform", "debug");
396
GDVIRTUAL_BIND(_get_android_manifest_application_element_contents, "platform", "debug");
397
GDVIRTUAL_BIND(_get_android_manifest_element_contents, "platform", "debug");
398
GDVIRTUAL_BIND(_update_android_prebuilt_manifest, "platform", "manifest_data");
399
}
400
401