Refactor the export checking logic to improve separation of concerns

This commit is contained in:
Fredia Huya-Kouadio 2022-07-17 10:22:54 -04:00
parent 1806e414b8
commit d2213f76a9
9 changed files with 120 additions and 21 deletions

View file

@ -1656,7 +1656,7 @@ Ref<Texture> EditorExportPlatformPC::get_logo() const {
return logo; 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; String err;
bool valid = false; bool valid = false;
@ -1688,6 +1688,28 @@ bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset,
return valid; return valid;
} }
bool EditorExportPlatformPC::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
return true;
}
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.empty()) {
r_error += templates_error;
}
if (!project_configuration_error.empty()) {
r_error += project_configuration_error;
}
return valid_export_configuration && valid_project_configuration;
}
List<String> EditorExportPlatformPC::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const { List<String> EditorExportPlatformPC::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
List<String> list; List<String> list;
for (Map<String, String>::Element *E = extensions.front(); E; E = E->next()) { for (Map<String, String>::Element *E = extensions.front(); E; E = E->next()) {

View file

@ -311,7 +311,9 @@ public:
String test_etc2() const; //generic test for etc2 since most platforms use it String test_etc2() const; //generic test for etc2 since most platforms use it
String test_etc2_or_pvrtc() const; // test for etc2 or pvrtc support for iOS String test_etc2_or_pvrtc() const; // test for etc2 or pvrtc support for iOS
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 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; virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) = 0;
@ -481,7 +483,8 @@ public:
virtual String get_os_name() const; virtual String get_os_name() const;
virtual Ref<Texture> get_logo() const; virtual Ref<Texture> get_logo() const;
virtual 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;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const;
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const; virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0); virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path); virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);

View file

@ -2059,7 +2059,7 @@ String EditorExportPlatformAndroid::get_apksigner_path() {
return 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; String err;
bool valid = false; bool valid = false;
const bool custom_build_enabled = p_preset->get("custom_build/use_custom_build"); const bool custom_build_enabled = p_preset->get("custom_build/use_custom_build");
@ -2107,7 +2107,7 @@ bool EditorExportPlatformAndroid::can_export(const Ref<EditorExportPreset> &p_pr
valid = installed_android_build_template && !r_missing_templates; 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 = p_preset->get("keystore/debug");
String dk_user = p_preset->get("keystore/debug_user"); String dk_user = p_preset->get("keystore/debug_user");
@ -2183,6 +2183,19 @@ bool EditorExportPlatformAndroid::can_export(const Ref<EditorExportPreset> &p_pr
} }
} }
if (!err.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"); bool apk_expansion = p_preset->get("apk_expansion/enable");
if (apk_expansion) { if (apk_expansion) {
@ -2249,8 +2262,7 @@ bool EditorExportPlatformAndroid::can_export(const Ref<EditorExportPreset> &p_pr
} }
} }
if (int(p_preset->get("custom_build/export_format")) == EXPORT_FORMAT_AAB && if (int(p_preset->get("custom_build/export_format")) == EXPORT_FORMAT_AAB && !custom_build_enabled) {
!custom_build_enabled) {
valid = false; valid = false;
err += TTR("\"Export AAB\" is only valid when \"Use Custom Build\" is enabled."); err += TTR("\"Export AAB\" is only valid when \"Use Custom Build\" is enabled.");
err += "\n"; err += "\n";
@ -2308,7 +2320,9 @@ bool EditorExportPlatformAndroid::can_export(const Ref<EditorExportPreset> &p_pr
err += "\n"; err += "\n";
} }
r_error = err; if (!err.empty()) {
r_error = err;
}
return valid; return valid;
} }

View file

@ -204,7 +204,8 @@ public:
static String get_apksigner_path(); static String get_apksigner_path();
virtual 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;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const;
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const; virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;

View file

@ -204,7 +204,8 @@ public:
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0); virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
virtual 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;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const;
virtual void get_platform_features(List<String> *r_features) { virtual void get_platform_features(List<String> *r_features) {
r_features->push_back("mobile"); r_features->push_back("mobile");
@ -2099,7 +2100,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
return OK; 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; String err;
bool valid = false; bool valid = false;
@ -2124,7 +2125,18 @@ bool EditorExportPlatformIOS::can_export(const Ref<EditorExportPreset> &p_preset
valid = dvalid || rvalid; valid = dvalid || rvalid;
r_missing_templates = !valid; r_missing_templates = !valid;
// Validate the rest of the configuration. if (!err.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"); String team_id = p_preset->get("application/app_store_team_id");
if (team_id.length() == 0) { if (team_id.length() == 0) {

View file

@ -328,7 +328,8 @@ public:
virtual String get_os_name() const; virtual String get_os_name() const;
virtual Ref<Texture> get_logo() const; virtual Ref<Texture> get_logo() const;
virtual 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;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const;
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const; virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0); virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
@ -687,7 +688,7 @@ Ref<Texture> EditorExportPlatformJavaScript::get_logo() const {
return logo; 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 {
String err; String err;
bool valid = false; bool valid = false;
ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type"); ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
@ -712,7 +713,18 @@ bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p
valid = dvalid || rvalid; valid = dvalid || rvalid;
r_missing_templates = !valid; r_missing_templates = !valid;
// Validate the rest of the configuration. if (!err.empty()) {
r_error = err;
}
return valid;
}
bool EditorExportPlatformJavaScript::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
String err;
bool valid = true;
// Validate the project configuration.
if (p_preset->get("vram_texture_compression/for_mobile")) { if (p_preset->get("vram_texture_compression/for_mobile")) {
String etc_error = test_etc2(); String etc_error = test_etc2();

View file

@ -120,7 +120,8 @@ public:
} }
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0); virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
virtual 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;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const;
virtual void get_platform_features(List<String> *r_features) { virtual void get_platform_features(List<String> *r_features) {
r_features->push_back("pc"); r_features->push_back("pc");
@ -1428,7 +1429,7 @@ void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String
memdelete(da); memdelete(da);
} }
bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const { bool EditorExportPlatformOSX::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
String err; String err;
bool valid = false; bool valid = false;
@ -1458,6 +1459,17 @@ bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset
valid = dvalid || rvalid; valid = dvalid || rvalid;
r_missing_templates = !valid; r_missing_templates = !valid;
if (!err.empty()) {
r_error = err;
}
return valid;
}
bool EditorExportPlatformOSX::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
String err;
bool valid = true;
String identifier = p_preset->get("application/identifier"); String identifier = p_preset->get("application/identifier");
String pn_err; String pn_err;
if (!is_package_name_valid(identifier, &pn_err)) { if (!is_package_name_valid(identifier, &pn_err)) {

View file

@ -1073,7 +1073,7 @@ public:
} }
} }
virtual 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 {
String err; String err;
bool valid = false; bool valid = false;
@ -1112,6 +1112,17 @@ public:
valid = dvalid || rvalid; valid = dvalid || rvalid;
r_missing_templates = !valid; r_missing_templates = !valid;
if (!err.empty()) {
r_error = err;
}
return valid;
}
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
String err;
bool valid = true;
// Validate the rest of the configuration. // Validate the rest of the configuration.
if (!_valid_resource_name(p_preset->get("package/short_name"))) { if (!_valid_resource_name(p_preset->get("package/short_name"))) {

View file

@ -48,7 +48,8 @@ public:
virtual Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size); virtual Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size);
virtual void get_export_options(List<ExportOption> *r_options); virtual void get_export_options(List<ExportOption> *r_options);
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
virtual 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;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const;
}; };
Error EditorExportPlatformWindows::sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) { Error EditorExportPlatformWindows::sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
@ -386,15 +387,26 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
return OK; 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 = ""; 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"); String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit");
if (p_preset->get("application/modify_resources") && rcedit_path.empty()) { if (p_preset->get("application/modify_resources") && rcedit_path.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"; 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.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")); String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon"));
if (!icon_path.empty() && !FileAccess::exists(icon_path)) { if (!icon_path.empty() && !FileAccess::exists(icon_path)) {
err += TTR("Invalid icon path:") + " " + icon_path + "\n"; err += TTR("Invalid icon path:") + " " + icon_path + "\n";