Skip to content

Commit

Permalink
Merge pull request #63122 from m4gr3d/split_can_export_main
Browse files Browse the repository at this point in the history
Refactor the export checking logic to improve separation of concerns
  • Loading branch information
m4gr3d authored Aug 15, 2022
2 parents 128d687 + 45c7377 commit 5a8d786
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 20 deletions.
18 changes: 18 additions & 0 deletions editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,5 +1176,23 @@ void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags
}
}

bool EditorExportPlatform::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
String templates_error;
bool valid_export_configuration = has_valid_export_configuration(p_preset, templates_error, r_missing_templates);

String project_configuration_error;
bool valid_project_configuration = has_valid_project_configuration(p_preset, project_configuration_error);

if (!templates_error.is_empty()) {
r_error += templates_error;
}

if (!project_configuration_error.is_empty()) {
r_error += project_configuration_error;
}

return valid_export_configuration && valid_project_configuration;
}

EditorExportPlatform::EditorExportPlatform() {
}
4 changes: 3 additions & 1 deletion editor/export/editor_export_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ class EditorExportPlatform : public RefCounted {
virtual Ref<Texture2D> get_run_icon() const { return get_logo(); }

String test_etc2() const;
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const = 0;
bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const = 0;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const = 0;

virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const = 0;
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) = 0;
Expand Down
6 changes: 5 additions & 1 deletion editor/export/editor_export_platform_pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Ref<Texture2D> EditorExportPlatformPC::get_logo() const {
return logo;
}

bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
bool EditorExportPlatformPC::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
String err;
bool valid = false;

Expand Down Expand Up @@ -106,6 +106,10 @@ bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset,
return valid;
}

bool EditorExportPlatformPC::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
return true;
}

Error EditorExportPlatformPC::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);

Expand Down
3 changes: 2 additions & 1 deletion editor/export/editor_export_platform_pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class EditorExportPlatformPC : public EditorExportPlatform {
virtual String get_os_name() const override;
virtual Ref<Texture2D> get_logo() const override;

virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
virtual String get_template_file_name(const String &p_target, const String &p_arch) const = 0;
Expand Down
17 changes: 15 additions & 2 deletions platform/android/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2049,7 +2049,7 @@ String EditorExportPlatformAndroid::get_apksigner_path() {
return apksigner_path;
}

bool EditorExportPlatformAndroid::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
bool EditorExportPlatformAndroid::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
String err;
bool valid = false;
const bool custom_build_enabled = p_preset->get("custom_build/use_custom_build");
Expand Down Expand Up @@ -2097,7 +2097,7 @@ bool EditorExportPlatformAndroid::can_export(const Ref<EditorExportPreset> &p_pr
valid = installed_android_build_template && !r_missing_templates;
}

// Validate the rest of the configuration.
// Validate the rest of the export configuration.

String dk = p_preset->get("keystore/debug");
String dk_user = p_preset->get("keystore/debug_user");
Expand Down Expand Up @@ -2173,6 +2173,19 @@ bool EditorExportPlatformAndroid::can_export(const Ref<EditorExportPreset> &p_pr
}
}

if (!err.is_empty()) {
r_error = err;
}

return valid;
}

bool EditorExportPlatformAndroid::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
String err;
bool valid = true;
const bool custom_build_enabled = p_preset->get("custom_build/use_custom_build");

// Validate the project configuration.
bool apk_expansion = p_preset->get("apk_expansion/enable");

if (apk_expansion) {
Expand Down
3 changes: 2 additions & 1 deletion platform/android/export/export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {

static String get_apksigner_path();

virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;

virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;

Expand Down
15 changes: 13 additions & 2 deletions platform/ios/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
return OK;
}

bool EditorExportPlatformIOS::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
bool EditorExportPlatformIOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
String err;
bool valid = false;

Expand All @@ -1842,7 +1842,18 @@ bool EditorExportPlatformIOS::can_export(const Ref<EditorExportPreset> &p_preset
valid = dvalid || rvalid;
r_missing_templates = !valid;

// Validate the rest of the configuration.
if (!err.is_empty()) {
r_error = err;
}

return valid;
}

bool EditorExportPlatformIOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
String err;
bool valid = true;

// Validate the project configuration.

String team_id = p_preset->get("application/app_store_team_id");
if (team_id.length() == 0) {
Expand Down
3 changes: 2 additions & 1 deletion platform/ios/export/export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ class EditorExportPlatformIOS : public EditorExportPlatform {
}
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;

virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;

virtual void get_platform_features(List<String> *r_features) const override {
r_features->push_back("mobile");
Expand Down
24 changes: 22 additions & 2 deletions platform/javascript/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ Ref<Texture2D> EditorExportPlatformJavaScript::get_logo() const {
return logo;
}

bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
bool EditorExportPlatformJavaScript::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
#ifndef DEV_ENABLED
// We don't provide export templates for the HTML5 platform currently as there
// is no suitable renderer to use with them. So we forbid exporting and tell
Expand Down Expand Up @@ -396,7 +396,27 @@ bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p
valid = dvalid || rvalid;
r_missing_templates = !valid;

// Validate the rest of the configuration.
if (!err.is_empty()) {
r_error = err;
}

return valid;
}

bool EditorExportPlatformJavaScript::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
#ifndef DEV_ENABLED
// We don't provide export templates for the HTML5 platform currently as there
// is no suitable renderer to use with them. So we forbid exporting and tell
// users why. This is skipped in DEV_ENABLED so that contributors can still test
// the pipeline once we start having WebGL or WebGPU support.
r_error = "The HTML5 platform is currently not supported in Godot 4.0, as there is no suitable renderer for it.\n";
return false;
#endif

String err;
bool valid = true;

// Validate the project configuration.

if (p_preset->get("vram_texture_compression/for_mobile")) {
String etc_error = test_etc2();
Expand Down
3 changes: 2 additions & 1 deletion platform/javascript/export/export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class EditorExportPlatformJavaScript : public EditorExportPlatform {
virtual String get_os_name() const override;
virtual Ref<Texture2D> get_logo() const override;

virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;

Expand Down
13 changes: 12 additions & 1 deletion platform/macos/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@ void EditorExportPlatformMacOS::_zip_folder_recursive(zipFile &p_zip, const Stri
da->list_dir_end();
}

bool EditorExportPlatformMacOS::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
bool EditorExportPlatformMacOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
String err;
bool valid = false;

Expand Down Expand Up @@ -1580,6 +1580,17 @@ bool EditorExportPlatformMacOS::can_export(const Ref<EditorExportPreset> &p_pres
valid = dvalid || rvalid;
r_missing_templates = !valid;

if (!err.is_empty()) {
r_error = err;
}

return valid;
}

bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
String err;
bool valid = true;

String identifier = p_preset->get("application/bundle_identifier");
String pn_err;
if (!is_package_name_valid(identifier, &pn_err)) {
Expand Down
3 changes: 2 additions & 1 deletion platform/macos/export/export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ class EditorExportPlatformMacOS : public EditorExportPlatform {
}
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;

virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;

virtual void get_platform_features(List<String> *r_features) const override {
r_features->push_back("pc");
Expand Down
23 changes: 21 additions & 2 deletions platform/uwp/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void EditorExportPlatformUWP::get_export_options(List<ExportOption> *r_options)
}
}

bool EditorExportPlatformUWP::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
bool EditorExportPlatformUWP::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
#ifndef DEV_ENABLED
// We don't provide export templates for the UWP platform currently as it
// has not been ported for Godot 4.0. This is skipped in DEV_ENABLED so that
Expand Down Expand Up @@ -163,7 +163,26 @@ bool EditorExportPlatformUWP::can_export(const Ref<EditorExportPreset> &p_preset
valid = dvalid || rvalid;
r_missing_templates = !valid;

// Validate the rest of the configuration.
if (!err.is_empty()) {
r_error = err;
}

return valid;
}

bool EditorExportPlatformUWP::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
#ifndef DEV_ENABLED
// We don't provide export templates for the UWP platform currently as it
// has not been ported for Godot 4.0. This is skipped in DEV_ENABLED so that
// contributors can still test the pipeline if/when we can build it again.
r_error = "The UWP platform is currently not supported in Godot 4.0.\n";
return false;
#endif

String err;
bool valid = true;

// Validate the project configuration.

if (!_valid_resource_name(p_preset->get("package/short_name"))) {
valid = false;
Expand Down
3 changes: 2 additions & 1 deletion platform/uwp/export/export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ class EditorExportPlatformUWP : public EditorExportPlatform {

virtual void get_export_options(List<ExportOption> *r_options) override;

virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;

virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;

Expand Down
15 changes: 13 additions & 2 deletions platform/windows/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,26 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
return OK;
}

bool EditorExportPlatformWindows::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
bool EditorExportPlatformWindows::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
String err = "";
bool valid = EditorExportPlatformPC::can_export(p_preset, err, r_missing_templates);
bool valid = EditorExportPlatformPC::has_valid_export_configuration(p_preset, err, r_missing_templates);

String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit");
if (p_preset->get("application/modify_resources") && rcedit_path.is_empty()) {
err += TTR("The rcedit tool must be configured in the Editor Settings (Export > Windows > Rcedit) to change the icon or app information data.") + "\n";
}

if (!err.is_empty()) {
r_error = err;
}

return valid;
}

bool EditorExportPlatformWindows::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
String err = "";
bool valid = true;

String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon"));
if (!icon_path.is_empty() && !FileAccess::exists(icon_path)) {
err += TTR("Invalid icon path:") + " " + icon_path + "\n";
Expand Down
3 changes: 2 additions & 1 deletion platform/windows/export/export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class EditorExportPlatformWindows : public EditorExportPlatformPC {
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
virtual void get_export_options(List<ExportOption> *r_options) override;
virtual bool get_export_option_visibility(const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;
virtual String get_template_file_name(const String &p_target, const String &p_arch) const override;
virtual Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) override;
};
Expand Down

0 comments on commit 5a8d786

Please sign in to comment.