Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: Enrico Tröger enrico.troeger@uvena.de Date: Sun, 13 Nov 2016 13:55:43 UTC Commit: d61b92f20260389222d2ab5fd48a65825afb363c https://github.com/geany/geany/commit/d61b92f20260389222d2ab5fd48a65825afb36...
Log Message: ----------- Revert "Implement the run helper as a script" on non-Windows
This restores the previous behavior as it has been on non-Windows systems before. Post-1.29 we will merge #1300 which implements run helper script support for non-Windows systems more sophisticated.
Modified Paths: -------------- src/Makefile.am src/build.c src/geany-run-helper
Modified: src/Makefile.am 2 lines changed, 0 insertions(+), 2 deletions(-) =================================================================== @@ -187,8 +187,6 @@ CLEANFILES += signallist.i # install the run script if MINGW dist_pkglibexec_SCRIPTS = geany-run-helper.bat -else -dist_pkglibexec_SCRIPTS = geany-run-helper endif
# Ubuntu ld has a bug so that libtool sees /usr/local/lib as a system path so
Modified: src/build.c 86 lines changed, 74 insertions(+), 12 deletions(-) =================================================================== @@ -79,6 +79,10 @@ typedef struct RunInfo
static RunInfo *run_info;
+#ifndef G_OS_WIN32 +static const gchar RUN_SCRIPT_CMD[] = "geany_run_script_XXXXXX.sh"; +#endif + /* pack group (<8) and command (<32) into a user_data pointer */ #define GRP_CMD_TO_POINTER(grp, cmd) GUINT_TO_POINTER((((grp)&7) << 5) | ((cmd)&0x1f)) #define GBO_TO_POINTER(gbo) (GRP_CMD_TO_POINTER(GBO_TO_GBG(gbo), GBO_TO_CMD(gbo))) @@ -109,6 +113,9 @@ static guint build_items_count = 9;
static void build_exit_cb(GPid pid, gint status, gpointer user_data); static void build_iofunc(GString *string, GIOCondition condition, gpointer data); +#ifndef G_OS_WIN32 +static gchar *build_create_shellscript(const gchar *working_dir, const gchar *cmd, gboolean autoclose, GError **error); +#endif static void build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *dir); static void set_stop_button(gboolean stop); static void run_exit_cb(GPid child_pid, gint status, gpointer user_data); @@ -785,6 +792,7 @@ static gchar *prepare_run_cmd(GeanyDocument *doc, gchar **working_dir, guint cmd const gchar *cmd_working_dir; gboolean autoclose = FALSE; gchar *cmd_string_utf8, *working_dir_utf8, *run_cmd, *cmd_string; + GError *error = NULL;
cmd = get_build_cmd(doc, GEANY_GBG_EXEC, cmdindex, NULL);
@@ -823,25 +831,23 @@ static gchar *prepare_run_cmd(GeanyDocument *doc, gchar **working_dir, guint cmd #ifdef G_OS_WIN32 /* Expand environment variables like %blah%. */ SETPTR(cmd_string, win32_expand_environment_variables(cmd_string)); -#endif
gchar *helper = g_build_filename(utils_resource_dir(RESOURCE_DIR_LIBEXEC), "geany-run-helper", NULL); - gchar *arg_directory = NULL; - /* escape helper appropriately */ -#ifdef G_OS_WIN32 /* FIXME: check the Windows rules, but it should not matter too much here as \es and "es are not * allowed in paths anyway */ - SETPTR(helper, g_strdup_printf(""%s"", helper)); - SETPTR(arg_directory, g_strdup_printf(""%s"", *working_dir)); + run_cmd = g_strdup_printf(""%s" "%s" %d %s", helper, *working_dir, autoclose ? 1 : 0, cmd_string); + g_free(helper); #else - SETPTR(helper, g_shell_quote(helper)); - SETPTR(arg_directory, g_shell_quote(*working_dir)); + run_cmd = build_create_shellscript(*working_dir, cmd_string, autoclose, &error); + if (!run_cmd) + { + ui_set_statusbar(TRUE, _("Failed to execute "%s" (start-script could not be created: %s)"), + !EMPTY(cmd_string_utf8) ? cmd_string_utf8 : NULL, error->message); + g_error_free(error); + g_free(*working_dir); + } #endif - run_cmd = g_strdup_printf("%s %s %d %s", helper, arg_directory, autoclose ? 1 : 0, cmd_string); - g_free(arg_directory); - g_free(helper); - utils_free_pointers(3, cmd_string_utf8, working_dir_utf8, cmd_string, NULL); return run_cmd; } @@ -930,6 +936,9 @@ static void build_run_cmd(GeanyDocument *doc, guint cmdindex) "Check the Terminal setting in Preferences"), utf8_term_cmd, error->message); g_free(utf8_term_cmd); g_error_free(error); +#ifndef G_OS_WIN32 + g_unlink(run_cmd); +#endif run_info[cmdindex].pid = (GPid) 0; } } @@ -1080,6 +1089,59 @@ static void run_exit_cb(GPid child_pid, gint status, gpointer user_data) build_menu_update(NULL); }
+ +/* write a little shellscript to call the executable (similar to anjuta_launcher but "internal") + * working_dir and cmd are both in the locale encoding + * it returns the full file name (including path) of the created script in the locale encoding */ +#ifndef G_OS_WIN32 +static gchar *build_create_shellscript(const gchar *working_dir, const gchar *cmd, gboolean autoclose, GError **error) +{ + gint fd; + gchar *str, *fname; + gboolean success = TRUE; + gchar *escaped_dir; + fd = g_file_open_tmp (RUN_SCRIPT_CMD, &fname, error); + if (fd < 0) + return NULL; + close(fd); + + escaped_dir = g_shell_quote(working_dir); + str = g_strdup_printf( + "#!/bin/sh\n\nrm $0\n\ncd %s\n\n%s\n\necho "\n\n------------------\n(program exited with code: $?)" \ + \n\n%s\n", escaped_dir, cmd, (autoclose) ? "" : + "\necho "Press return to continue"\n#to be more compatible with shells like " + "dash\ndummy_var=""\nread dummy_var"); + g_free(escaped_dir); + + if (!g_file_set_contents(fname, str, -1, error)) + success = FALSE; + g_free(str); +#ifdef __APPLE__ + if (success && g_chmod(fname, 0777) != 0) + { + if (error) + { + gint errsv = errno; + + g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errsv), + "Failed to make file executable: %s", g_strerror(errsv)); + } + success = FALSE; + } +#endif + + if (!success) + { + g_unlink(fname); + g_free(fname); + fname = NULL; + } + + return fname; +} +#endif + + typedef void Callback(GtkWidget *w, gpointer u);
/* run the command catenating cmd_cat if present */
Modified: src/geany-run-helper 28 lines changed, 0 insertions(+), 28 deletions(-) =================================================================== @@ -1,28 +0,0 @@ -#!/bin/sh -# USAGE: geany-run-helper DIRECTORY AUTOCLOSE COMMAND... - -# OSX resets the current directory, so check it back -cd "$1" -shift -# save autoclose option and remove it -autoclose=$1 -shift - -# spawn the child -"$@" - -# show the result -echo " - ------------------- -(program exited with code: $?) -" - -# and if wanted, wait on the user -if ! [ "$autoclose" = 0 ] -then - echo "Press return to continue" - # to be more compatible with shells like dash - dummy_var= - read dummy_var -fi
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).