[anjuta] jhbuild: new plugin to build/run program inside the jhbuild environment.
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] jhbuild: new plugin to build/run program inside the jhbuild environment.
- Date: Wed, 24 Oct 2012 20:37:57 +0000 (UTC)
commit 3d21acbc7000d60431bfc47320b8a6d1640d9f5b
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date: Tue Oct 23 00:20:02 2012 +0200
jhbuild: new plugin to build/run program inside the jhbuild environment.
https://bugzilla.gnome.org/show_bug.cgi?id=685338
This is a simple plugin implementing IAnjutaEnvironent which runs all
commands using "jhbuild run". It also appends "--prefix" and "--libdir"
parameters to invocations of configure and ./autogen.sh.
configure.ac | 1 +
plugins/Makefile.am | 1 +
plugins/jhbuild/Makefile.am | 48 +++++
plugins/jhbuild/anjuta-jhbuild-plugin-48.png | Bin 0 -> 3020 bytes
plugins/jhbuild/anjuta-jhbuild.plugin.in | 6 +
plugins/jhbuild/plugin.c | 269 ++++++++++++++++++++++++++
plugins/jhbuild/plugin.h | 48 +++++
7 files changed, 373 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 70b2f5e..7a74578 100644
--- a/configure.ac
+++ b/configure.ac
@@ -847,6 +847,7 @@ plugins/language-support-python/Makefile
plugins/parser-cxx/Makefile
plugins/parser-cxx/cxxparser/Makefile
plugins/python-loader/Makefile
+plugins/jhbuild/Makefile
anjuta.desktop.in
manuals/Makefile
manuals/reference/Makefile
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 3dbe48f..11f14ed 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -19,6 +19,7 @@ SUBDIRS = . \
js-debugger \
indentation-c-style \
indentation-python-style \
+ jhbuild \
language-manager \
language-support-cpp-java \
language-support-js \
diff --git a/plugins/jhbuild/Makefile.am b/plugins/jhbuild/Makefile.am
new file mode 100644
index 0000000..5dcb864
--- /dev/null
+++ b/plugins/jhbuild/Makefile.am
@@ -0,0 +1,48 @@
+# Plugin Icon file
+jhbuild_pixmapsdir = $(anjuta_image_dir)
+jhbuild_pixmaps_DATA = \
+ anjuta-jhbuild-plugin-48.png
+
+# Plugin description file
+plugin_in_files = anjuta-jhbuild.plugin.in
+%.plugin: %.plugin.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+
+jhbuild_plugindir = $(anjuta_plugin_dir)
+jhbuild_plugin_DATA = $(plugin_in_files:.plugin.in=.plugin)
+
+# NOTE :
+# The naming convention is very intentional
+# We are forced to use the prefix 'lib' by automake and libtool
+# There is probably a way to avoid it but it is not worth to effort
+# to find out.
+# The 'anjuta_' prfix is a safety measure to avoid conflicts where the
+# plugin 'libpython.so' needs to link with the real 'libpython.so'
+
+# Include paths
+AM_CPPFLAGS = \
+ $(WARN_CFLAGS) \
+ $(DEPRECATED_FLAGS) \
+ $(LIBANJUTA_CFLAGS) \
+ $(EXTRA_CFLAGS) \
+ -DG_LOG_DOMAIN=\"jhbuild\"
+
+# Where to install the plugin
+plugindir = $(anjuta_plugin_dir)
+
+# The plugin
+plugin_LTLIBRARIES = libanjuta-jhbuild.la
+
+# Plugin sources
+libanjuta_jhbuild_la_SOURCES = \
+ plugin.c \
+ plugin.h
+
+libanjuta_jhbuild_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
+
+
+EXTRA_DIST = \
+ $(plugin_in_files) \
+ $(jhbuild_plugin_DATA) \
+ $(jhbuild_pixmaps_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/jhbuild/anjuta-jhbuild-plugin-48.png b/plugins/jhbuild/anjuta-jhbuild-plugin-48.png
new file mode 100644
index 0000000..43f2267
Binary files /dev/null and b/plugins/jhbuild/anjuta-jhbuild-plugin-48.png differ
diff --git a/plugins/jhbuild/anjuta-jhbuild.plugin.in b/plugins/jhbuild/anjuta-jhbuild.plugin.in
new file mode 100644
index 0000000..7347f84
--- /dev/null
+++ b/plugins/jhbuild/anjuta-jhbuild.plugin.in
@@ -0,0 +1,6 @@
+[Anjuta Plugin]
+_Name=JHBuild
+_Description=Build and run programs inside the JHBuild environment
+Location=anjuta-jhbuild:JHBuildPlugin
+Icon=anjuta-jhbuild-plugin-48.png
+Interfaces=IAnjutaEnvironment
diff --git a/plugins/jhbuild/plugin.c b/plugins/jhbuild/plugin.c
new file mode 100644
index 0000000..154ea85
--- /dev/null
+++ b/plugins/jhbuild/plugin.c
@@ -0,0 +1,269 @@
+/* -*- Mode: C; indent-spaces-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ plugin.c
+ Copyright (C) 2012 Carl-Anton Ingmarsson
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include <config.h>
+
+#include "plugin.h"
+
+#include <libanjuta/anjuta-debug.h>
+#include <libanjuta/interfaces/ianjuta-environment.h>
+
+#include <sys/wait.h>
+
+struct _JHBuildPluginClass
+{
+ AnjutaPluginClass parent_class;
+};
+
+#define JHBUILD_PLUGIN_ERROR (jhbuild_plugin_error_quark())
+static GQuark jhbuild_plugin_error_quark(void);
+
+G_DEFINE_QUARK(JHBUILD_PLUGIN_ERROR, jhbuild_plugin_error);
+
+static char *
+jhbuild_plugin_environment_get_real_directory(IAnjutaEnvironment *obj,
+ gchar *dir,
+ GError **err)
+{
+ return dir;
+}
+
+static gboolean
+jhbuild_plugin_environment_override(IAnjutaEnvironment* environment,
+ char** dirp,
+ char*** argvp,
+ char*** envp,
+ GError** error)
+{
+ JHBuildPlugin* self = ANJUTA_PLUGIN_JHBUILD(environment);
+
+ gboolean add_prefix = FALSE;
+ guint argvp_length;
+ char** new_argv;
+
+ if (g_str_has_suffix (*argvp[0], "configure") || g_str_has_suffix (*argvp[0], "autogen.sh"))
+ {
+ char** argv_iter;
+
+ add_prefix = TRUE;
+ for (argv_iter = *argvp; *argv_iter; argv_iter++)
+ {
+ if (g_str_has_prefix (*argv_iter, "--prefix") ||
+ g_str_has_prefix (*argv_iter, "--libdir"))
+ {
+ add_prefix = FALSE;
+ break;
+ }
+ }
+ }
+
+ argvp_length = g_strv_length (*argvp);
+ new_argv = g_new(char*, argvp_length + (add_prefix ? 5 : 3));
+ new_argv[0] = g_strdup("jhbuild");
+ new_argv[1] = g_strdup("run");
+
+ memcpy(new_argv + 2, *argvp, sizeof(char*) * argvp_length);
+
+ if (add_prefix)
+ {
+ new_argv[2 + argvp_length] = g_strdup_printf("--prefix=%s", self->prefix);
+ new_argv[2 + argvp_length + 1] = g_strdup_printf("--libdir=%s", self->libdir);
+ new_argv[2 + argvp_length + 2] = NULL;
+ }
+ else
+ new_argv[2 + argvp_length] = NULL;
+
+ g_free(*argvp);
+ *argvp = new_argv;
+
+ return TRUE;
+}
+
+static char*
+run_jhbuild_env (GError** error)
+{
+ char* argv[] = {"jhbuild", "run", "env", NULL};
+ GError* err = NULL;
+ char* standard_output;
+ char* standard_error;
+ int exit_status;
+
+ if (!g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
+ &standard_output, &standard_error, &exit_status, &err))
+ {
+ g_propagate_prefixed_error (error, err, "Failed to run \"jhbuild run");
+ return NULL;
+ }
+
+ if (WIFEXITED(exit_status) && WEXITSTATUS(exit_status) != 0)
+ {
+ g_set_error(error, JHBUILD_PLUGIN_ERROR, 0, "Failed to run \"jhbuild run\" (%s)", standard_error);
+ g_free(standard_error);
+ g_free(standard_output);
+ return NULL;
+ }
+
+ g_free(standard_error);
+ return standard_output;
+}
+
+static gboolean
+jhbuild_plugin_get_jhbuild_info(JHBuildPlugin* self, GError** error)
+{
+ char* output;
+ char** env_variables;
+ char** variable;
+
+ if (!(output = run_jhbuild_env(error)))
+ return FALSE;
+
+ env_variables = g_strsplit(output, "\n", 0);
+ g_free(output);
+
+
+ /* First scan for JHBUILD_PREFIX */
+ for (variable = env_variables; *variable; ++variable)
+ {
+ if (g_str_has_prefix (*variable, "JHBUILD_PREFIX="))
+ {
+ const char* value;
+
+ value = *variable + strlen("JHBUILD_PREFIX=");
+ self->prefix = g_strdup(value);
+ }
+ }
+
+ if (!self->prefix)
+ {
+ g_set_error_literal (error, ANJUTA_SHELL_ERROR, 0, "Could not find the JHBuild install prefix.");
+ g_strfreev(env_variables);
+ return FALSE;
+ }
+
+ /* Then we scan for LD_LIBRARY_PATH to extract libdir from there. */
+ for (variable = env_variables; *variable; ++variable)
+ {
+ if (g_str_has_prefix (*variable, "LD_LIBRARY_PATH="))
+ {
+ const char* value;
+ char **values, **iter;
+
+ value = *variable + strlen("LD_LIBRARY_PATH=");
+ if (!value)
+ break;
+
+ values = g_strsplit(value, ";", -1);
+ for (iter = values; *iter; ++iter)
+ {
+ if (g_str_has_prefix (*iter, self->prefix))
+ {
+ self->libdir = g_strdup(*iter);
+ break;
+ }
+ }
+ g_strfreev(values);
+ break;
+ }
+ }
+
+ g_strfreev(env_variables);
+
+ if (!self->libdir)
+ {
+ g_set_error_literal (error, JHBUILD_PLUGIN_ERROR, 0, "Could not find the JHBuild library directory.");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+jhbuild_plugin_activate(AnjutaPlugin* plugin)
+{
+ JHBuildPlugin *self = ANJUTA_PLUGIN_JHBUILD (plugin);
+
+ GError *err = NULL;
+
+ if (!jhbuild_plugin_get_jhbuild_info(self, &err))
+ {
+ anjuta_util_dialog_error(GTK_WINDOW(self->shell),
+ "Failed to activate the JHBuild Plugin: %s", err->message);
+ g_error_free (err);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static gboolean
+jhbuild_plugin_deactivate (AnjutaPlugin *plugin)
+{
+ return TRUE;
+}
+
+/* GObject functions
+ *---------------------------------------------------------------------------*/
+
+/* Used in dispose and finalize */
+static gpointer parent_class;
+
+static void
+jhbuild_plugin_instance_init (GObject *obj)
+{
+ JHBuildPlugin *self = ANJUTA_PLUGIN_JHBUILD (obj);
+
+ self->shell = anjuta_plugin_get_shell (ANJUTA_PLUGIN(self));
+}
+
+static void
+jhbuild_plugin_finalize (GObject *obj)
+{
+ JHBuildPlugin *self = ANJUTA_PLUGIN_JHBUILD (obj);
+
+ g_free(self->prefix);
+ g_free(self->libdir);
+
+
+ G_OBJECT_CLASS (parent_class)->finalize (obj);
+}
+
+static void
+jhbuild_plugin_class_init (GObjectClass *klass)
+{
+ AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ plugin_class->activate = jhbuild_plugin_activate;
+ plugin_class->deactivate = jhbuild_plugin_deactivate;
+ klass->finalize = jhbuild_plugin_finalize;
+}
+
+static void
+ienvironment_iface_init(IAnjutaEnvironmentIface *iface)
+{
+ iface->override = jhbuild_plugin_environment_override;
+ iface->get_real_directory = jhbuild_plugin_environment_get_real_directory;
+}
+
+ANJUTA_PLUGIN_BEGIN (JHBuildPlugin, jhbuild_plugin);
+ANJUTA_PLUGIN_ADD_INTERFACE (ienvironment, IANJUTA_TYPE_ENVIRONMENT);
+ANJUTA_PLUGIN_END;
+
+ANJUTA_SIMPLE_PLUGIN (JHBuildPlugin, jhbuild_plugin);
diff --git a/plugins/jhbuild/plugin.h b/plugins/jhbuild/plugin.h
new file mode 100644
index 0000000..a84de21
--- /dev/null
+++ b/plugins/jhbuild/plugin.h
@@ -0,0 +1,48 @@
+/* -*- Mode: C; indent-spaces-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ plugin.h
+ Copyright (C) 2012 Carl-Anton Ingmarsson
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef _PLUGIN_H_
+#define _PLUGIN_H_
+
+#include <libanjuta/anjuta-plugin.h>
+
+#define ANJUTA_TYPE_PLUGIN_JHBUILD (jhbuild_plugin_get_type (NULL))
+#define ANJUTA_PLUGIN_JHBUILD(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), ANJUTA_TYPE_PLUGIN_JHBUILD, JHBuildPlugin))
+#define ANJUTA_PLUGIN_JHBUILD_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), ANJUTA_TYPE_PLUGIN_JHBUILD, JHBuildPluginClass))
+#define ANJUTA_IS_PLUGIN_JHBUILD(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), ANJUTA_TYPE_PLUGIN_JHBUILD))
+#define ANJUTA_IS_PLUGIN_JHBUILD_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), ANJUTA_TYPE_PLUGIN_JHBUILD))
+#define ANJUTA_PLUGIN_JHBUILD_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), ANJUTA_TYPE_PLUGIN_JHBUILD, JHBuildPluginClass))
+
+typedef struct _JHBuildPlugin JHBuildPlugin;
+typedef struct _JHBuildPluginClass JHBuildPluginClass;
+
+struct _JHBuildPlugin
+{
+ AnjutaPlugin parent;
+
+ AnjutaShell* shell;
+
+ char* prefix;
+ char* libdir;
+};
+
+extern GType jhbuild_plugin_get_type(GTypeModule *module);
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]