[anjuta] Allow to change working directory with anjuta_launcher



commit a0dbab9a779b32bc2bdb924c93e22263c607aba5
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Sun Jul 12 15:29:10 2009 +0200

    Allow to change working directory with anjuta_launcher

 libanjuta/anjuta-launcher.c            |   28 ++++++++++++++++------------
 libanjuta/anjuta-launcher.h            |    1 +
 plugins/build-basic-autotools/plugin.c |   17 ++++++++---------
 plugins/git/git-command.c              |    5 ++---
 plugins/project-wizard/autogen.c       |    2 +-
 5 files changed, 28 insertions(+), 25 deletions(-)
---
diff --git a/libanjuta/anjuta-launcher.c b/libanjuta/anjuta-launcher.c
index 40040f3..a79c582 100644
--- a/libanjuta/anjuta-launcher.c
+++ b/libanjuta/anjuta-launcher.c
@@ -1082,17 +1082,14 @@ anjuta_launcher_set_encoding (AnjutaLauncher *launcher, const gchar *charset)
 }
 
 static pid_t
-anjuta_launcher_fork (AnjutaLauncher *launcher, gchar *const args[], gchar *const envp[])
+anjuta_launcher_fork (AnjutaLauncher *launcher, const gchar *dir, gchar *const args[], gchar *const envp[])
 {
-	char *working_dir;
 	int pty_master_fd, md;
 	int stdout_pipe[2], stderr_pipe[2];
 	pid_t child_pid;
 	struct termios termios_flags;
 	gchar * const *env;
 	
-	working_dir = g_get_current_dir ();
-	
 	/* The pipes */
 	pipe (stderr_pipe);
 	pipe (stdout_pipe);
@@ -1120,7 +1117,13 @@ anjuta_launcher_fork (AnjutaLauncher *launcher, gchar *const args[], gchar *cons
 			fcntl (stdout_pipe[1], F_SETFL, O_SYNC | md);
 		if ((md = fcntl (stderr_pipe[1], F_GETFL)) != -1)
 			fcntl (stderr_pipe[1], F_SETFL, O_SYNC | md);
-		
+	
+		/* Set working directory */
+		if (dir != NULL)
+		{
+			chdir (dir);
+		}
+
 		/* Set up environment */
 		if (envp != NULL)
 		{
@@ -1148,7 +1151,6 @@ anjuta_launcher_fork (AnjutaLauncher *launcher, gchar *const args[], gchar *cons
 		perror(_("execvp failed"));
 		_exit(-1);
 	}
-	g_free (working_dir);
 	
 	/* Close parent's side pipes */
 	close (stderr_pipe[1]);
@@ -1230,6 +1232,7 @@ anjuta_launcher_fork (AnjutaLauncher *launcher, gchar *const args[], gchar *cons
 /**
  * anjuta_launcher_execute_v:
  * @launcher: a #AnjutaLancher object.
+ * @dir: Working directory or NULL.
  * @argv: Command args.
  * @envp: Additional environment variable.
  * @callback: The callback for delivering output from the process.
@@ -1241,10 +1244,11 @@ anjuta_launcher_fork (AnjutaLauncher *launcher, gchar *const args[], gchar *cons
  * Return value: TRUE if successfully launched, otherwise FALSE.
  */
 gboolean
-anjuta_launcher_execute_v (AnjutaLauncher *launcher, gchar *const argv[],
-						   gchar *const envp[],
-						   AnjutaLauncherOutputCallback callback,
-						   gpointer callback_data)
+anjuta_launcher_execute_v (AnjutaLauncher *launcher, gchar *const dir,
+	       	gchar *const argv[],
+	       	gchar *const envp[],
+	       	AnjutaLauncherOutputCallback callback,
+	       	gpointer callback_data)
 {
 	if (anjuta_launcher_is_busy (launcher))
 		return FALSE;
@@ -1260,7 +1264,7 @@ anjuta_launcher_execute_v (AnjutaLauncher *launcher, gchar *const argv[],
 	launcher->priv->callback_data = callback_data;
 	
 	/* On a fork error perform a cleanup and return */
-	if (anjuta_launcher_fork (launcher, argv, envp) < 0)
+	if (anjuta_launcher_fork (launcher, dir, argv, envp) < 0)
 	{
 		anjuta_launcher_initialize (launcher);
 		return FALSE;
@@ -1306,7 +1310,7 @@ anjuta_launcher_execute (AnjutaLauncher *launcher, const gchar *command_str,
 	}
 	*args_ptr = NULL;
 
-	ret = anjuta_launcher_execute_v (launcher, args, NULL,
+	ret = anjuta_launcher_execute_v (launcher, NULL, args, NULL,
 		callback, callback_data);
 	g_free (args);
 	anjuta_util_glist_strings_free (args_list);
diff --git a/libanjuta/anjuta-launcher.h b/libanjuta/anjuta-launcher.h
index 8f4dce6..7f97456 100644
--- a/libanjuta/anjuta-launcher.h
+++ b/libanjuta/anjuta-launcher.h
@@ -84,6 +84,7 @@ gboolean anjuta_launcher_execute (AnjutaLauncher *launcher,
 								  AnjutaLauncherOutputCallback callback,
 								  gpointer callback_data);
 gboolean anjuta_launcher_execute_v (AnjutaLauncher *launcher,
+									gchar *const dir,
 									gchar *const argv[],
 									gchar *const envp[],
 									AnjutaLauncherOutputCallback callback,
diff --git a/plugins/build-basic-autotools/plugin.c b/plugins/build-basic-autotools/plugin.c
index b22f201..fcfcbae 100644
--- a/plugins/build-basic-autotools/plugin.c
+++ b/plugins/build-basic-autotools/plugin.c
@@ -1320,9 +1320,6 @@ build_execute_command_in_context (BuildContext* context, GError **err)
 	
 	build_program_override (context->program, context->environment);
 	
-	/* Add current directory */
-	build_program_add_env (context->program, "PWD", context->program->work_dir);
-	
 	if (context->message_view)
 	{
 		gchar *command;
@@ -1337,16 +1334,18 @@ build_execute_command_in_context (BuildContext* context, GError **err)
 		g_free (command);
 	
 		anjuta_launcher_execute_v (context->launcher,
-								   context->program->argv,
-								   context->program->envp,
-								   on_build_mesg_arrived, context);
+		    context->program->work_dir,
+		    context->program->argv,
+		    context->program->envp,
+		    on_build_mesg_arrived, context);
 	}
 	else
 	{
 		anjuta_launcher_execute_v (context->launcher,
-								   context->program->argv,
-								   context->program->envp,
-								   NULL, NULL);
+		    context->program->work_dir,
+		    context->program->argv,
+		    context->program->envp,
+		    NULL, NULL);
 	}		
 	
 	return TRUE;
diff --git a/plugins/git/git-command.c b/plugins/git/git-command.c
index c333464..a6f322e 100644
--- a/plugins/git/git-command.c
+++ b/plugins/git/git-command.c
@@ -220,9 +220,8 @@ git_command_launch (GitCommand *self)
 	else
 		callback = (AnjutaLauncherOutputCallback) git_command_multi_line_output_arrived;
 
-	chdir (self->priv->working_directory);
-	
-	if (!anjuta_launcher_execute_v (self->priv->launcher, 
+	if (!anjuta_launcher_execute_v (self->priv->launcher,
+	    							self->priv->working_directory,
 									args,
 									NULL,
 									callback,
diff --git a/plugins/project-wizard/autogen.c b/plugins/project-wizard/autogen.c
index 298fe82..486e44b 100644
--- a/plugins/project-wizard/autogen.c
+++ b/plugins/project-wizard/autogen.c
@@ -351,7 +351,7 @@ npw_autogen_execute (NPWAutogen* this, NPWAutogenFunc func, gpointer data, GErro
 	}
 	
 	this->busy = TRUE;
-	if (!anjuta_launcher_execute_v (this->launcher, args, NULL, on_autogen_output, this))
+	if (!anjuta_launcher_execute_v (this->launcher, NULL, args, NULL, on_autogen_output, this))
 	{
 		return FALSE;
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]