export_plugin.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /**************************************************************************/
  2. /* 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. #include "export_plugin.h"
  31. #include "logo_svg.gen.h"
  32. #include "run_icon_svg.gen.h"
  33. #include "core/config/project_settings.h"
  34. #include "editor/editor_node.h"
  35. #include "editor/editor_paths.h"
  36. #include "editor/editor_string_names.h"
  37. #include "editor/export/editor_export.h"
  38. #include "editor/themes/editor_scale.h"
  39. #include "modules/svg/image_loader_svg.h"
  40. Error EditorExportPlatformLinuxBSD::_export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path) {
  41. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE);
  42. if (f.is_null()) {
  43. add_message(EXPORT_MESSAGE_ERROR, TTR("Debug Script Export"), vformat(TTR("Could not open file \"%s\"."), p_path));
  44. return ERR_CANT_CREATE;
  45. }
  46. f->store_line("#!/bin/sh");
  47. f->store_line("printf '\\033c\\033]0;%s\\a' " + p_app_name);
  48. f->store_line("base_path=\"$(dirname \"$(realpath \"$0\")\")\"");
  49. f->store_line("\"$base_path/" + p_pkg_name + "\" \"$@\"");
  50. return OK;
  51. }
  52. Error EditorExportPlatformLinuxBSD::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) {
  53. String custom_debug = p_preset->get("custom_template/debug");
  54. String custom_release = p_preset->get("custom_template/release");
  55. String arch = p_preset->get("binary_format/architecture");
  56. String template_path = p_debug ? custom_debug : custom_release;
  57. template_path = template_path.strip_edges();
  58. if (!template_path.is_empty()) {
  59. String exe_arch = _get_exe_arch(template_path);
  60. if (arch != exe_arch) {
  61. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Mismatching custom export template executable architecture: found \"%s\", expected \"%s\"."), exe_arch, arch));
  62. return ERR_CANT_CREATE;
  63. }
  64. }
  65. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  66. if (da->file_exists(template_path.get_base_dir().path_join("libaccesskit." + arch + ".so"))) {
  67. da->copy(template_path.get_base_dir().path_join("libaccesskit." + arch + ".so"), p_path.get_base_dir().path_join("libaccesskit." + arch + ".so"), get_chmod_flags());
  68. }
  69. bool export_as_zip = p_path.ends_with("zip");
  70. String pkg_name;
  71. if (String(GLOBAL_GET("application/config/name")) != "") {
  72. pkg_name = String(GLOBAL_GET("application/config/name"));
  73. } else {
  74. pkg_name = "Unnamed";
  75. }
  76. pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
  77. // Setup temp folder.
  78. String path = p_path;
  79. String tmp_dir_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name);
  80. Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_dir_path);
  81. if (export_as_zip) {
  82. if (tmp_app_dir.is_null()) {
  83. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not create and open the directory: \"%s\""), tmp_dir_path));
  84. return ERR_CANT_CREATE;
  85. }
  86. if (DirAccess::exists(tmp_dir_path)) {
  87. if (tmp_app_dir->change_dir(tmp_dir_path) == OK) {
  88. tmp_app_dir->erase_contents_recursive();
  89. }
  90. }
  91. tmp_app_dir->make_dir_recursive(tmp_dir_path);
  92. path = tmp_dir_path.path_join(p_path.get_file().get_basename());
  93. }
  94. // Export project.
  95. Error err = EditorExportPlatformPC::export_project(p_preset, p_debug, path, p_flags);
  96. if (err != OK) {
  97. // Message is supplied by the subroutine method.
  98. return err;
  99. }
  100. // Save console wrapper.
  101. int con_scr = p_preset->get("debug/export_console_wrapper");
  102. if ((con_scr == 1 && p_debug) || (con_scr == 2)) {
  103. String scr_path = path.get_basename() + ".sh";
  104. err = _export_debug_script(p_preset, pkg_name, path.get_file(), scr_path);
  105. FileAccess::set_unix_permissions(scr_path, 0755);
  106. if (err != OK) {
  107. add_message(EXPORT_MESSAGE_ERROR, TTR("Debug Console Export"), TTR("Could not create console wrapper."));
  108. }
  109. }
  110. // ZIP project.
  111. if (export_as_zip) {
  112. if (FileAccess::exists(p_path)) {
  113. OS::get_singleton()->move_to_trash(p_path);
  114. }
  115. Ref<FileAccess> io_fa_dst;
  116. zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);
  117. zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
  118. zip_folder_recursive(zip, tmp_dir_path, "", pkg_name);
  119. zipClose(zip, nullptr);
  120. if (tmp_app_dir->change_dir(tmp_dir_path) == OK) {
  121. tmp_app_dir->erase_contents_recursive();
  122. tmp_app_dir->change_dir("..");
  123. tmp_app_dir->remove(pkg_name);
  124. }
  125. }
  126. return err;
  127. }
  128. String EditorExportPlatformLinuxBSD::get_template_file_name(const String &p_target, const String &p_arch) const {
  129. return "linux_" + p_target + "." + p_arch;
  130. }
  131. List<String> EditorExportPlatformLinuxBSD::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
  132. List<String> list;
  133. list.push_back(p_preset->get("binary_format/architecture"));
  134. list.push_back("zip");
  135. return list;
  136. }
  137. bool EditorExportPlatformLinuxBSD::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {
  138. if (p_preset == nullptr) {
  139. return true;
  140. }
  141. bool advanced_options_enabled = p_preset->are_advanced_options_enabled();
  142. // Hide SSH options.
  143. bool ssh = p_preset->get("ssh_remote_deploy/enabled");
  144. if (!ssh && p_option != "ssh_remote_deploy/enabled" && p_option.begins_with("ssh_remote_deploy/")) {
  145. return false;
  146. }
  147. if (p_option == "dotnet/embed_build_outputs" ||
  148. p_option == "custom_template/debug" ||
  149. p_option == "custom_template/release") {
  150. return advanced_options_enabled;
  151. }
  152. return true;
  153. }
  154. void EditorExportPlatformLinuxBSD::get_export_options(List<ExportOption> *r_options) const {
  155. EditorExportPlatformPC::get_export_options(r_options);
  156. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "binary_format/architecture", PROPERTY_HINT_ENUM, "x86_64,x86_32,arm64,arm32,rv64,ppc64,ppc32,loongarch64"), "x86_64"));
  157. String run_script = "#!/usr/bin/env bash\n"
  158. "export DISPLAY=:0\n"
  159. "unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"\n"
  160. "\"{temp_dir}/{exe_name}\" {cmd_args}";
  161. String cleanup_script = "#!/usr/bin/env bash\n"
  162. "kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")\n"
  163. "rm -rf \"{temp_dir}\"";
  164. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true));
  165. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/host"), "user@host_ip"));
  166. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/port"), "22"));
  167. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_ssh", PROPERTY_HINT_MULTILINE_TEXT), ""));
  168. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_scp", PROPERTY_HINT_MULTILINE_TEXT), ""));
  169. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/run_script", PROPERTY_HINT_MULTILINE_TEXT), run_script));
  170. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/cleanup_script", PROPERTY_HINT_MULTILINE_TEXT), cleanup_script));
  171. }
  172. bool EditorExportPlatformLinuxBSD::is_elf(const String &p_path) const {
  173. Ref<FileAccess> fb = FileAccess::open(p_path, FileAccess::READ);
  174. ERR_FAIL_COND_V_MSG(fb.is_null(), false, vformat("Can't open file: \"%s\".", p_path));
  175. uint32_t magic = fb->get_32();
  176. return (magic == 0x464c457f);
  177. }
  178. bool EditorExportPlatformLinuxBSD::is_shebang(const String &p_path) const {
  179. Ref<FileAccess> fb = FileAccess::open(p_path, FileAccess::READ);
  180. ERR_FAIL_COND_V_MSG(fb.is_null(), false, vformat("Can't open file: \"%s\".", p_path));
  181. uint16_t magic = fb->get_16();
  182. return (magic == 0x2123);
  183. }
  184. bool EditorExportPlatformLinuxBSD::is_executable(const String &p_path) const {
  185. return is_elf(p_path) || is_shebang(p_path);
  186. }
  187. bool EditorExportPlatformLinuxBSD::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {
  188. String err;
  189. bool valid = EditorExportPlatformPC::has_valid_export_configuration(p_preset, err, r_missing_templates, p_debug);
  190. String custom_debug = p_preset->get("custom_template/debug").operator String().strip_edges();
  191. String custom_release = p_preset->get("custom_template/release").operator String().strip_edges();
  192. String arch = p_preset->get("binary_format/architecture");
  193. if (!custom_debug.is_empty() && FileAccess::exists(custom_debug)) {
  194. String exe_arch = _get_exe_arch(custom_debug);
  195. if (arch != exe_arch) {
  196. err += vformat(TTR("Mismatching custom debug export template executable architecture: found \"%s\", expected \"%s\"."), exe_arch, arch) + "\n";
  197. }
  198. }
  199. if (!custom_release.is_empty() && FileAccess::exists(custom_release)) {
  200. String exe_arch = _get_exe_arch(custom_release);
  201. if (arch != exe_arch) {
  202. err += vformat(TTR("Mismatching custom release export template executable architecture: found \"%s\", expected \"%s\"."), exe_arch, arch) + "\n";
  203. }
  204. }
  205. if (!err.is_empty()) {
  206. r_error = err;
  207. }
  208. return valid;
  209. }
  210. String EditorExportPlatformLinuxBSD::_get_exe_arch(const String &p_path) const {
  211. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
  212. if (f.is_null()) {
  213. return "invalid";
  214. }
  215. // Read and check ELF magic number.
  216. {
  217. uint32_t magic = f->get_32();
  218. if (magic != 0x464c457f) { // 0x7F + "ELF"
  219. return "invalid";
  220. }
  221. }
  222. // Process header.
  223. int64_t header_pos = f->get_position();
  224. f->seek(header_pos + 14);
  225. uint16_t machine = f->get_16();
  226. f->close();
  227. switch (machine) {
  228. case 0x0003:
  229. return "x86_32";
  230. case 0x003e:
  231. return "x86_64";
  232. case 0x0014:
  233. return "ppc32";
  234. case 0x0015:
  235. return "ppc64";
  236. case 0x0028:
  237. return "arm32";
  238. case 0x00b7:
  239. return "arm64";
  240. case 0x00f3:
  241. return "rv64";
  242. case 0x0102:
  243. return "loongarch64";
  244. default:
  245. return "unknown";
  246. }
  247. }
  248. Error EditorExportPlatformLinuxBSD::fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) {
  249. // Patch the header of the "pck" section in the ELF file so that it corresponds to the embedded data.
  250. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ_WRITE);
  251. if (f.is_null()) {
  252. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to open executable file \"%s\"."), p_path));
  253. return ERR_CANT_OPEN;
  254. }
  255. // Read and check ELF magic number.
  256. {
  257. uint32_t magic = f->get_32();
  258. if (magic != 0x464c457f) { // 0x7F + "ELF"
  259. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable file header corrupted."));
  260. return ERR_FILE_CORRUPT;
  261. }
  262. }
  263. // Read program architecture bits from class field.
  264. int bits = f->get_8() * 32;
  265. if (bits == 32 && p_embedded_size >= 0x100000000) {
  266. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("32-bit executables cannot have embedded data >= 4 GiB."));
  267. }
  268. // Get info about the section header table.
  269. int64_t section_table_pos;
  270. int64_t section_header_size;
  271. if (bits == 32) {
  272. section_header_size = 40;
  273. f->seek(0x20);
  274. section_table_pos = f->get_32();
  275. f->seek(0x30);
  276. } else { // 64
  277. section_header_size = 64;
  278. f->seek(0x28);
  279. section_table_pos = f->get_64();
  280. f->seek(0x3c);
  281. }
  282. int num_sections = f->get_16();
  283. int string_section_idx = f->get_16();
  284. // Load the strings table.
  285. uint8_t *strings;
  286. {
  287. // Jump to the strings section header.
  288. f->seek(section_table_pos + string_section_idx * section_header_size);
  289. // Read strings data size and offset.
  290. int64_t string_data_pos;
  291. int64_t string_data_size;
  292. if (bits == 32) {
  293. f->seek(f->get_position() + 0x10);
  294. string_data_pos = f->get_32();
  295. string_data_size = f->get_32();
  296. } else { // 64
  297. f->seek(f->get_position() + 0x18);
  298. string_data_pos = f->get_64();
  299. string_data_size = f->get_64();
  300. }
  301. // Read strings data.
  302. f->seek(string_data_pos);
  303. strings = (uint8_t *)memalloc(string_data_size);
  304. if (!strings) {
  305. return ERR_OUT_OF_MEMORY;
  306. }
  307. f->get_buffer(strings, string_data_size);
  308. }
  309. // Search for the "pck" section.
  310. bool found = false;
  311. for (int i = 0; i < num_sections; ++i) {
  312. int64_t section_header_pos = section_table_pos + i * section_header_size;
  313. f->seek(section_header_pos);
  314. uint32_t name_offset = f->get_32();
  315. if (strcmp((char *)strings + name_offset, "pck") == 0) {
  316. // "pck" section found, let's patch!
  317. if (bits == 32) {
  318. f->seek(section_header_pos + 0x10);
  319. f->store_32(p_embedded_start);
  320. f->store_32(p_embedded_size);
  321. } else { // 64
  322. f->seek(section_header_pos + 0x18);
  323. f->store_64(p_embedded_start);
  324. f->store_64(p_embedded_size);
  325. }
  326. found = true;
  327. break;
  328. }
  329. }
  330. memfree(strings);
  331. if (!found) {
  332. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable \"pck\" section not found."));
  333. return ERR_FILE_CORRUPT;
  334. }
  335. return OK;
  336. }
  337. Ref<Texture2D> EditorExportPlatformLinuxBSD::get_run_icon() const {
  338. return run_icon;
  339. }
  340. bool EditorExportPlatformLinuxBSD::poll_export() {
  341. Ref<EditorExportPreset> preset;
  342. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  343. Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
  344. if (ep->is_runnable() && ep->get_platform() == this) {
  345. preset = ep;
  346. break;
  347. }
  348. }
  349. int prev = menu_options;
  350. menu_options = (preset.is_valid() && preset->get("ssh_remote_deploy/enabled").operator bool());
  351. if (ssh_pid != 0 || !cleanup_commands.is_empty()) {
  352. if (menu_options == 0) {
  353. cleanup();
  354. } else {
  355. menu_options += 1;
  356. }
  357. }
  358. return menu_options != prev;
  359. }
  360. Ref<ImageTexture> EditorExportPlatformLinuxBSD::get_option_icon(int p_index) const {
  361. return p_index == 1 ? stop_icon : EditorExportPlatform::get_option_icon(p_index);
  362. }
  363. int EditorExportPlatformLinuxBSD::get_options_count() const {
  364. return menu_options;
  365. }
  366. String EditorExportPlatformLinuxBSD::get_option_label(int p_index) const {
  367. return (p_index) ? TTR("Stop and uninstall") : TTR("Run on remote Linux/BSD system");
  368. }
  369. String EditorExportPlatformLinuxBSD::get_option_tooltip(int p_index) const {
  370. return (p_index) ? TTR("Stop and uninstall running project from the remote system") : TTR("Run exported project on remote Linux/BSD system");
  371. }
  372. void EditorExportPlatformLinuxBSD::cleanup() {
  373. if (ssh_pid != 0 && OS::get_singleton()->is_process_running(ssh_pid)) {
  374. print_line("Terminating connection...");
  375. OS::get_singleton()->kill(ssh_pid);
  376. OS::get_singleton()->delay_usec(1000);
  377. }
  378. if (!cleanup_commands.is_empty()) {
  379. print_line("Stopping and deleting previous version...");
  380. for (const SSHCleanupCommand &cmd : cleanup_commands) {
  381. if (cmd.wait) {
  382. ssh_run_on_remote(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
  383. } else {
  384. ssh_run_on_remote_no_wait(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
  385. }
  386. }
  387. }
  388. ssh_pid = 0;
  389. cleanup_commands.clear();
  390. }
  391. Error EditorExportPlatformLinuxBSD::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) {
  392. cleanup();
  393. if (p_device) { // Stop command, cleanup only.
  394. return OK;
  395. }
  396. EditorProgress ep("run", TTR("Running..."), 5);
  397. const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("linuxbsd");
  398. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  399. if (!da->dir_exists(dest)) {
  400. Error err = da->make_dir_recursive(dest);
  401. if (err != OK) {
  402. EditorNode::get_singleton()->show_warning(TTR("Could not create temp directory:") + "\n" + dest);
  403. return err;
  404. }
  405. }
  406. String host = p_preset->get("ssh_remote_deploy/host").operator String();
  407. String port = p_preset->get("ssh_remote_deploy/port").operator String();
  408. if (port.is_empty()) {
  409. port = "22";
  410. }
  411. Vector<String> extra_args_ssh = p_preset->get("ssh_remote_deploy/extra_args_ssh").operator String().split(" ", false);
  412. Vector<String> extra_args_scp = p_preset->get("ssh_remote_deploy/extra_args_scp").operator String().split(" ", false);
  413. const String basepath = dest.path_join("tmp_linuxbsd_export");
  414. #define CLEANUP_AND_RETURN(m_err) \
  415. { \
  416. if (da->file_exists(basepath + ".zip")) { \
  417. da->remove(basepath + ".zip"); \
  418. } \
  419. if (da->file_exists(basepath + "_start.sh")) { \
  420. da->remove(basepath + "_start.sh"); \
  421. } \
  422. if (da->file_exists(basepath + "_clean.sh")) { \
  423. da->remove(basepath + "_clean.sh"); \
  424. } \
  425. return m_err; \
  426. } \
  427. ((void)0)
  428. if (ep.step(TTR("Exporting project..."), 1)) {
  429. return ERR_SKIP;
  430. }
  431. Error err = export_project(p_preset, true, basepath + ".zip", p_debug_flags);
  432. if (err != OK) {
  433. DirAccess::remove_file_or_error(basepath + ".zip");
  434. return err;
  435. }
  436. String cmd_args;
  437. {
  438. Vector<String> cmd_args_list = gen_export_flags(p_debug_flags);
  439. for (int i = 0; i < cmd_args_list.size(); i++) {
  440. if (i != 0) {
  441. cmd_args += " ";
  442. }
  443. cmd_args += cmd_args_list[i];
  444. }
  445. }
  446. const bool use_remote = p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG) || p_debug_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT);
  447. int dbg_port = EditorSettings::get_singleton()->get("network/debug/remote_port");
  448. print_line("Creating temporary directory...");
  449. ep.step(TTR("Creating temporary directory..."), 2);
  450. String temp_dir;
  451. err = ssh_run_on_remote(host, port, extra_args_ssh, "mktemp -d", &temp_dir);
  452. if (err != OK || temp_dir.is_empty()) {
  453. CLEANUP_AND_RETURN(err);
  454. }
  455. print_line("Uploading archive...");
  456. ep.step(TTR("Uploading archive..."), 3);
  457. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + ".zip", temp_dir);
  458. if (err != OK) {
  459. CLEANUP_AND_RETURN(err);
  460. }
  461. {
  462. String run_script = p_preset->get("ssh_remote_deploy/run_script");
  463. run_script = run_script.replace("{temp_dir}", temp_dir);
  464. run_script = run_script.replace("{archive_name}", basepath.get_file() + ".zip");
  465. run_script = run_script.replace("{exe_name}", basepath.get_file());
  466. run_script = run_script.replace("{cmd_args}", cmd_args);
  467. Ref<FileAccess> f = FileAccess::open(basepath + "_start.sh", FileAccess::WRITE);
  468. if (f.is_null()) {
  469. CLEANUP_AND_RETURN(err);
  470. }
  471. f->store_string(run_script);
  472. }
  473. {
  474. String clean_script = p_preset->get("ssh_remote_deploy/cleanup_script");
  475. clean_script = clean_script.replace("{temp_dir}", temp_dir);
  476. clean_script = clean_script.replace("{archive_name}", basepath.get_file() + ".zip");
  477. clean_script = clean_script.replace("{exe_name}", basepath.get_file());
  478. clean_script = clean_script.replace("{cmd_args}", cmd_args);
  479. Ref<FileAccess> f = FileAccess::open(basepath + "_clean.sh", FileAccess::WRITE);
  480. if (f.is_null()) {
  481. CLEANUP_AND_RETURN(err);
  482. }
  483. f->store_string(clean_script);
  484. }
  485. print_line("Uploading scripts...");
  486. ep.step(TTR("Uploading scripts..."), 4);
  487. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_start.sh", temp_dir);
  488. if (err != OK) {
  489. CLEANUP_AND_RETURN(err);
  490. }
  491. err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_start.sh"));
  492. if (err != OK || temp_dir.is_empty()) {
  493. CLEANUP_AND_RETURN(err);
  494. }
  495. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_clean.sh", temp_dir);
  496. if (err != OK) {
  497. CLEANUP_AND_RETURN(err);
  498. }
  499. err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh"));
  500. if (err != OK || temp_dir.is_empty()) {
  501. CLEANUP_AND_RETURN(err);
  502. }
  503. print_line("Starting project...");
  504. ep.step(TTR("Starting project..."), 5);
  505. err = ssh_run_on_remote_no_wait(host, port, extra_args_ssh, vformat("\"%s/%s\"", temp_dir, basepath.get_file() + "_start.sh"), &ssh_pid, (use_remote) ? dbg_port : -1);
  506. if (err != OK) {
  507. CLEANUP_AND_RETURN(err);
  508. }
  509. cleanup_commands.clear();
  510. cleanup_commands.push_back(SSHCleanupCommand(host, port, extra_args_ssh, vformat("\"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh")));
  511. print_line("Project started.");
  512. CLEANUP_AND_RETURN(OK);
  513. #undef CLEANUP_AND_RETURN
  514. }
  515. EditorExportPlatformLinuxBSD::EditorExportPlatformLinuxBSD() {
  516. if (EditorNode::get_singleton()) {
  517. Ref<Image> img = memnew(Image);
  518. const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
  519. ImageLoaderSVG::create_image_from_string(img, _linuxbsd_logo_svg, EDSCALE, upsample, false);
  520. set_logo(ImageTexture::create_from_image(img));
  521. ImageLoaderSVG::create_image_from_string(img, _linuxbsd_run_icon_svg, EDSCALE, upsample, false);
  522. run_icon = ImageTexture::create_from_image(img);
  523. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  524. if (theme.is_valid()) {
  525. stop_icon = theme->get_icon(SNAME("Stop"), EditorStringName(EditorIcons));
  526. } else {
  527. stop_icon.instantiate();
  528. }
  529. }
  530. }