summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-01-07 13:29:02 +0100
committerRémi Verschelde <rverschelde@gmail.com>2020-01-07 14:25:56 +0100
commit5011afcb6ad6a7f7eb37a2cb74f28985e70cbc20 (patch)
tree337be6abf4964783cc3a47bdaf6345c4ed9e806e /editor
parent96fdb48edd49966485cc344a01eaaa74a2999d42 (diff)
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.
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_export.cpp46
-rw-r--r--editor/editor_node.cpp66
-rw-r--r--editor/editor_node.h9
3 files changed, 56 insertions, 65 deletions
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp
index 264206472b..d66b386f93 100644
--- a/editor/editor_export.cpp
+++ b/editor/editor_export.cpp
@@ -1485,41 +1485,29 @@ Ref<Texture> EditorExportPlatformPC::get_logo() const {
bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
String err;
- bool valid = true;
- bool use64 = p_preset->get("binary_format/64_bits");
-
- if (use64 && (!exists_export_template(debug_file_64, &err) || !exists_export_template(release_file_64, &err))) {
- valid = false;
- }
+ bool valid = false;
- if (!use64 && (!exists_export_template(debug_file_32, &err) || !exists_export_template(release_file_32, &err))) {
- valid = false;
- }
-
- String custom_debug_binary = p_preset->get("custom_template/debug");
- String custom_release_binary = p_preset->get("custom_template/release");
+ // Look for export templates (first official, and if defined custom templates).
- if (custom_debug_binary == "" && custom_release_binary == "") {
- if (!err.empty())
- r_error = err;
- r_missing_templates = !valid;
- return valid;
- }
-
- bool dvalid = true;
- bool rvalid = true;
+ bool use64 = p_preset->get("binary_format/64_bits");
+ bool dvalid = exists_export_template(use64 ? debug_file_64 : debug_file_32, &err);
+ bool rvalid = exists_export_template(use64 ? release_file_64 : release_file_32, &err);
- if (!FileAccess::exists(custom_debug_binary)) {
- dvalid = false;
- err += TTR("Custom debug template not found.") + "\n";
+ if (p_preset->get("custom_template/debug") != "") {
+ dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
+ if (!dvalid) {
+ err += TTR("Custom debug template not found.") + "\n";
+ }
}
-
- if (!FileAccess::exists(custom_release_binary)) {
- rvalid = false;
- err += TTR("Custom release template not found.") + "\n";
+ if (p_preset->get("custom_template/release") != "") {
+ rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
+ if (!rvalid) {
+ err += TTR("Custom release template not found.") + "\n";
+ }
}
valid = dvalid || rvalid;
+ r_missing_templates = !valid;
if (!err.empty())
r_error = err;
@@ -1600,7 +1588,7 @@ Error EditorExportPlatformPC::export_project(const Ref<EditorExportPreset> &p_pr
if (embedded_size >= 0x100000000 && !p_preset->get("binary_format/64_bits")) {
EditorNode::get_singleton()->show_warning(TTR("On 32-bit exports the embedded PCK cannot be bigger than 4 GiB."));
- return ERR_UNAVAILABLE;
+ return ERR_INVALID_PARAMETER;
}
FixUpEmbeddedPckFunc fixup_func = get_fixup_embedded_pck_func();
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<EditorExportPreset> 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<EditorExportPlatform> 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<EditorNodeInitCallback> 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);
diff --git a/editor/editor_node.h b/editor/editor_node.h
index acff91790d..469ba76872 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -325,18 +325,13 @@ private:
ExportTemplateManager *export_template_manager;
EditorFeatureProfileManager *feature_profile_manager;
EditorFileDialog *file_templates;
- EditorFileDialog *file_export;
EditorFileDialog *file_export_lib;
EditorFileDialog *file_script;
CheckBox *file_export_lib_merge;
- LineEdit *file_export_password;
String current_path;
MenuButton *update_spinner;
String defer_load_scene;
- String defer_export;
- String defer_export_platform;
- bool defer_export_debug;
Node *_last_instanced_scene;
EditorLog *log;
@@ -563,8 +558,6 @@ private:
String preset;
String path;
bool debug;
- String password;
-
} export_defer;
bool disable_progress_dialog;
@@ -786,7 +779,7 @@ public:
void _copy_warning(const String &p_str);
- Error export_preset(const String &p_preset, const String &p_path, bool p_debug, const String &p_password, bool p_quit_after = false);
+ Error export_preset(const String &p_preset, const String &p_path, bool p_debug);
static void register_editor_types();
static void unregister_editor_types();