From 5011afcb6ad6a7f7eb37a2cb74f28985e70cbc20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Tue, 7 Jan 2020 13:29:02 +0100 Subject: Export: Improve usability of command line interface I'm barely scratching the surface of the changes needed to make the --export command line interface easy to use, but this should already improve things somewhat. - Streamline `can_export()` templates check in all platforms, checking first for the presence of official templates, then of any defined custom template, and reporting on the absence of any. Shouldn't change the actual return value much which is still true if either release or debug is usable - we might want to change that eventually and better validate against the requested target. - Fix discrepancy between platforms using `custom_package/debug` and `custom_template/debug` (resp. `release`). All now use `custom_template`, which will break compatibility for `export_presets.cfg` with earlier projects (but is easy to fix). - Use `can_export()` when attempting a command line export and report the same errors that would be shown in the editor. - Improve error reporting after a failed export attempt, handling missing template and invalid path more gracefully. - Cleanup of unused stuff in EditorNode around the export workflow. - Improve --export documentation in --help a bit. Fixes #16949 (at least many of the misunderstandings listed there). Fixes #18470. --- editor/editor_node.cpp | 66 +++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 28 deletions(-) (limited to 'editor/editor_node.cpp') diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 8e6668bc89..d7bc959729 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -562,46 +562,68 @@ void EditorNode::_fs_changed() { _mark_unsaved_scenes(); + // FIXME: Move this to a cleaner location, it's hacky to do this is _fs_changed. + String export_error; if (export_defer.preset != "" && !EditorFileSystem::get_singleton()->is_scanning()) { + String preset_name = export_defer.preset; + // Ensures export_project does not loop infinitely, because notifications may + // come during the export. + export_defer.preset = ""; Ref preset; for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); ++i) { preset = EditorExport::get_singleton()->get_export_preset(i); - if (preset->get_name() == export_defer.preset) { + if (preset->get_name() == preset_name) { break; } preset.unref(); } if (preset.is_null()) { - String errstr = "Unknown export preset: " + export_defer.preset; - ERR_PRINTS(errstr); - OS::get_singleton()->set_exit_code(EXIT_FAILURE); + export_error = vformat("Invalid export preset name: %s.", preset_name); } else { Ref platform = preset->get_platform(); if (platform.is_null()) { - String errstr = "Preset \"" + export_defer.preset + "\" doesn't have a platform."; - ERR_PRINTS(errstr); - OS::get_singleton()->set_exit_code(EXIT_FAILURE); + export_error = vformat("Export preset '%s' doesn't have a matching platform.", preset_name); } else { - // ensures export_project does not loop infinitely, because notifications may - // come during the export - export_defer.preset = ""; Error err = OK; + // FIXME: This way to export only resources .pck or .zip is pretty hacky + // and undocumented, and might be problematic for platforms where .zip is + // a valid project export format (e.g. macOS). if (export_defer.path.ends_with(".pck") || export_defer.path.ends_with(".zip")) { if (export_defer.path.ends_with(".zip")) { err = platform->export_zip(preset, export_defer.debug, export_defer.path); } else if (export_defer.path.ends_with(".pck")) { err = platform->export_pack(preset, export_defer.debug, export_defer.path); } - } else { - err = platform->export_project(preset, export_defer.debug, export_defer.path); + } else { // Normal project export. + String config_error; + bool missing_templates; + if (!platform->can_export(preset, config_error, missing_templates)) { + ERR_PRINT(vformat("Cannot export project with preset '%s' due to configuration errors:\n%s", preset_name, config_error)); + err = missing_templates ? ERR_FILE_NOT_FOUND : ERR_UNCONFIGURED; + } else { + err = platform->export_project(preset, export_defer.debug, export_defer.path); + } } - if (err != OK) { - ERR_PRINTS(vformat(TTR("Project export failed with error code %d."), (int)err)); - OS::get_singleton()->set_exit_code(EXIT_FAILURE); + switch (err) { + case OK: + break; + case ERR_FILE_NOT_FOUND: + export_error = vformat("Project export failed for preset '%s', the export template appears to be missing.", preset_name); + break; + case ERR_FILE_BAD_PATH: + export_error = vformat("Project export failed for preset '%s', the target path '%s' appears to be invalid.", preset_name, export_defer.path); + break; + default: + export_error = vformat("Project export failed with error code %d for preset '%s'.", (int)err, preset_name); + break; } } } + if (!export_error.empty()) { + ERR_PRINT(export_error); + OS::get_singleton()->set_exit_code(EXIT_FAILURE); + } _exit_editor(); } } @@ -3920,12 +3942,11 @@ void EditorNode::_editor_file_dialog_unregister(EditorFileDialog *p_dialog) { Vector EditorNode::_init_callbacks; -Error EditorNode::export_preset(const String &p_preset, const String &p_path, bool p_debug, const String &p_password, bool p_quit_after) { +Error EditorNode::export_preset(const String &p_preset, const String &p_path, bool p_debug) { export_defer.preset = p_preset; export_defer.path = p_path; export_defer.debug = p_debug; - export_defer.password = p_password; disable_progress_dialog = true; return OK; } @@ -6531,12 +6552,6 @@ EditorNode::EditorNode() { gui_base->add_child(file); file->set_current_dir("res://"); - file_export = memnew(EditorFileDialog); - file_export->set_access(EditorFileDialog::ACCESS_FILESYSTEM); - gui_base->add_child(file_export); - file_export->set_title(TTR("Export Project")); - file_export->connect("file_selected", this, "_dialog_action"); - file_export_lib = memnew(EditorFileDialog); file_export_lib->set_title(TTR("Export Library")); file_export_lib->set_mode(EditorFileDialog::MODE_SAVE_FILE); @@ -6547,11 +6562,6 @@ EditorNode::EditorNode() { file_export_lib->get_vbox()->add_child(file_export_lib_merge); gui_base->add_child(file_export_lib); - file_export_password = memnew(LineEdit); - file_export_password->set_secret(true); - file_export_password->set_editable(false); - file_export->get_vbox()->add_margin_child(TTR("Password:"), file_export_password); - file_script = memnew(EditorFileDialog); file_script->set_title(TTR("Open & Run a Script")); file_script->set_access(EditorFileDialog::ACCESS_FILESYSTEM); -- cgit v1.2.3