diff options
Diffstat (limited to 'src/plugin.c')
-rw-r--r-- | src/plugin.c | 284 |
1 files changed, 246 insertions, 38 deletions
diff --git a/src/plugin.c b/src/plugin.c index 85b3158..95b8846 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -26,6 +26,7 @@ #include <sys/types.h> #include <sys/wait.h> +#include <sys/utsname.h> #include "plugin.h" @@ -37,6 +38,9 @@ #define PREFS_PROP_SDK_ROOT "sdk.root" #define PREFS_PROP_TRIPLET "sdk.triplet" +#define PREFS_PROP_POKY_ROOT "sdk.poky_root" + +#define PREFS_PROP_POKY_MODE "sdk.poky_mode" #define PREFS_PROP_KERNEL "sdk.kernel" #define PREFS_PROP_ROOTFS "sdk.rootfs" @@ -1144,19 +1148,53 @@ message_view_buffer_flushed_cb (IAnjutaMessageView *view, gchar *data, data, "", NULL); } +static gchar * +get_host_component () +{ + struct utsname res; + gchar *os = NULL; + gchar *host_component = NULL; + + uname (&res); + os = g_ascii_strdown (res.sysname, -1); + host_component = g_strdup_printf("%s-%s", res.machine, os); + + g_free (os); + + return host_component; +} + /* Update the path to remove or include our sdk bin directory */ static void update_path (AnjutaPluginSdk *sp) { char *path = NULL; - gchar **pathv = NULL; - gchar **new_pathv = NULL; - gchar **path_it = NULL; - gchar **new_path_it = NULL; gchar *new_path_component = NULL; - - if (sp->triplet != NULL && sp->sdk_root != NULL) - new_path_component = g_build_filename (sp->sdk_root, "bin", NULL); + GArray *path_array = NULL; + char **pathv = NULL; + int i = 0; + gchar *poky_scripts_dir = NULL; + gchar *poky_host_staging_bin_dir = NULL; + gchar *poky_cross_dir = NULL; + gchar *host_component = NULL; + + /* Create new versions of path bits */ + if (sp->poky_mode == POKY_MODE_TOOLCHAIN) + { + if (sp->triplet != NULL && sp->sdk_root != NULL) + new_path_component = g_build_filename (sp->sdk_root, "bin", NULL); + } else { + if (sp->poky_root) + { + host_component = get_host_component (); + poky_scripts_dir = g_build_filename (sp->poky_root, "scripts", NULL); + poky_host_staging_bin_dir = g_build_filename (sp->poky_root, "build", "tmp", + "staging", host_component, "usr", "bin", NULL); + poky_cross_dir = g_build_filename (sp->poky_root, "build", "tmp", + "cross", "bin", NULL); + g_free (host_component); + } + } /* get current path. do not free */ path = getenv ("PATH"); @@ -1164,39 +1202,62 @@ update_path (AnjutaPluginSdk *sp) /* split old path up */ pathv = g_strsplit (path, ":", -1); - /* allocate memory for new pathv */ - new_pathv = g_malloc0 ((g_strv_length (pathv) + 2) * (sizeof (gchar *))); - - /* new pathv iterator */ - new_path_it = new_pathv; + /* Convert it into a GArray */ + path_array = g_array_sized_new (TRUE, FALSE, sizeof (gchar *), + g_strv_length (pathv)); + path_array = g_array_insert_vals (path_array, 0, pathv, + g_strv_length (pathv)); - /* insert at the front if we have something to insert */ - if (new_path_component) + /* Remove old versions */ + for (i = 0; i < path_array->len; i++) { - *new_path_it = new_path_component; - new_path_it++; - } + gchar *tmp = g_array_index (path_array, gchar *, i); - /* iterate through */ - for (path_it = pathv; *path_it != NULL; path_it++) - { - /* Check for the old component */ - if (sp->path_component && g_str_equal (*path_it, sp->path_component)) + if ((sp->path_component && g_str_equal (tmp, sp->path_component)) || + (sp->poky_scripts_dir && g_str_equal (tmp, sp->poky_scripts_dir)) || + (sp->poky_host_staging_bin_dir + && g_str_equal (tmp, sp->poky_host_staging_bin_dir)) || + (sp->poky_cross_dir && g_str_equal (tmp, sp->poky_cross_dir))) { - path_it++; /* skip over */ + path_array = g_array_remove_index (path_array, i); + i--; /* because we've deleted something */ } + } + + if (sp->poky_mode == POKY_MODE_TOOLCHAIN) + { + /* Add the new path component */ + if (new_path_component) + path_array = g_array_prepend_val (path_array, new_path_component); + } else { + if (poky_scripts_dir) + path_array = g_array_prepend_val (path_array, poky_scripts_dir); - *new_path_it = *path_it; - new_path_it++; + if (poky_cross_dir) + path_array = g_array_prepend_val (path_array, poky_cross_dir); + + if (poky_host_staging_bin_dir) + path_array = g_array_prepend_val (path_array, poky_host_staging_bin_dir); } /* Create our new path */ - path = g_strjoinv (":", new_pathv); + path = g_strjoinv (":", (gchar **)path_array->data); + setenv ("PATH", path, 1); - /* Save the component */ + /* Save the components */ g_free (sp->path_component); + g_free (sp->poky_scripts_dir); + g_free (sp->poky_cross_dir); + g_free (sp->poky_host_staging_bin_dir); + sp->path_component = new_path_component; + sp->poky_scripts_dir = poky_scripts_dir; + sp->poky_cross_dir = poky_cross_dir; + sp->poky_host_staging_bin_dir = poky_host_staging_bin_dir; + + g_array_free (path_array, TRUE); + g_strfreev (pathv); } /* @@ -1219,7 +1280,9 @@ update_environment (AnjutaPluginSdk *sp) { gchar *tmp = NULL; - if (sp->triplet == NULL || sp->sdk_root == NULL) + if (sp->triplet == NULL || + (sp->poky_mode == POKY_MODE_TOOLCHAIN && sp->sdk_root == NULL) || + (sp->poky_mode == POKY_MODE_FULL && sp->poky_root == NULL)) { cleanup_environment (sp); return; @@ -1227,17 +1290,32 @@ update_environment (AnjutaPluginSdk *sp) update_path (sp); - tmp = g_build_filename (sp->sdk_root, sp->triplet, NULL); - setenv ("PKG_CONFIG_SYSROOT_DIR", tmp, 1); - g_free (tmp); + if (sp->poky_mode == POKY_MODE_TOOLCHAIN) + { + tmp = g_build_filename (sp->sdk_root, sp->triplet, NULL); + setenv ("PKG_CONFIG_SYSROOT_DIR", tmp, 1); + g_free (tmp); - tmp = g_build_filename (sp->sdk_root, sp->triplet, "lib", "pkgconfig", NULL); - setenv ("PKG_CONFIG_PATH", tmp, 1); - g_free (tmp); + tmp = g_build_filename (sp->sdk_root, sp->triplet, "lib", "pkgconfig", NULL); + setenv ("PKG_CONFIG_PATH", tmp, 1); + g_free (tmp); - tmp = g_build_filename (sp->sdk_root, "site-config", NULL); - setenv ("CONFIG_SITE", tmp, 1); - g_free (tmp); + tmp = g_build_filename (sp->sdk_root, "site-config", NULL); + setenv ("CONFIG_SITE", tmp, 1); + g_free (tmp); + } else { + tmp = g_build_filename (sp->poky_root, "build", "tmp", "staging", + sp->triplet, NULL); + setenv ("PKG_CONFIG_SYSROOT_DIR", tmp, 1); + g_free (tmp); + + tmp = g_build_filename (sp->poky_root, "build", "tmp", "staging", sp->triplet, + "usr", "lib", "pkgconfig", NULL); + setenv ("PKG_CONFIG_PATH", tmp, 1); + g_free (tmp); + + unsetenv ("CONFIG_SITE"); + } } static void @@ -1345,6 +1423,29 @@ kernel_preference_notify_cb (GConfClient *client, guint cnxn_id, } } +static void +poky_mode_preference_notify_cb (GConfClient *client, guint cnxn_id, + GConfEntry *entry, gpointer userdata) +{ + AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; + + sp->poky_mode = anjuta_preferences_get_int (sp->prefs, PREFS_PROP_POKY_MODE); + + update_environment (sp); +} + +static void +poky_root_preference_notify_cb (GConfClient *client, guint cnxn_id, + GConfEntry *entry, gpointer userdata) +{ + AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; + + g_free (sp->poky_root); + sp->poky_root = anjuta_preferences_get (sp->prefs, PREFS_PROP_POKY_ROOT); + + update_environment (sp); +} + /* * Callbacks for when a value for "project_root_uri" is added to the shell aka * when a project is opened @@ -1458,11 +1559,17 @@ anjuta_plugin_sdk_activate (AnjutaPlugin *plugin) PREFS_PROP_ROOTFS, rootfs_preference_notify_cb, sp, NULL); sp->kernel_notifyid = anjuta_preferences_notify_add (sp->prefs, PREFS_PROP_KERNEL, kernel_preference_notify_cb, sp, NULL); + sp->poky_root_notifyid = anjuta_preferences_notify_add (sp->prefs, + PREFS_PROP_POKY_ROOT, poky_root_preference_notify_cb, sp, NULL); + sp->poky_mode_notifyid = anjuta_preferences_notify_add (sp->prefs, + PREFS_PROP_POKY_MODE, poky_mode_preference_notify_cb, sp, NULL); sp->sdk_root = anjuta_preferences_get (sp->prefs, PREFS_PROP_SDK_ROOT); sp->triplet = anjuta_preferences_get (sp->prefs, PREFS_PROP_TRIPLET); sp->kernel = anjuta_preferences_get (sp->prefs, PREFS_PROP_KERNEL); sp->rootfs = anjuta_preferences_get (sp->prefs, PREFS_PROP_ROOTFS); + sp->poky_root = anjuta_preferences_get (sp->prefs, PREFS_PROP_POKY_ROOT); + sp->poky_mode = anjuta_preferences_get_int (sp->prefs, PREFS_PROP_POKY_MODE); if (sp->kernel == NULL || sp->rootfs == NULL) { @@ -1535,6 +1642,8 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin) anjuta_preferences_notify_remove (sp->prefs, sp->triplet_notifyid); anjuta_preferences_notify_remove (sp->prefs, sp->rootfs_notifyid); anjuta_preferences_notify_remove (sp->prefs, sp->kernel_notifyid); + anjuta_preferences_notify_remove (sp->prefs, sp->poky_root_notifyid); + anjuta_preferences_notify_remove (sp->prefs, sp->poky_mode_notifyid); anjuta_plugin_remove_watch (plugin, sp->project_root_uri_watch, FALSE); @@ -1593,6 +1702,8 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin) g_free (sp->triplet); g_free (sp->kernel); g_free (sp->rootfs); + g_free (sp->poky_root); + g_free (sp->project_root_uri); g_free (sp->path_component); g_free (sp->gdb_local_path); @@ -1603,6 +1714,8 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin) sp->triplet = NULL; sp->kernel = NULL; sp->rootfs = NULL; + sp->poky_root = NULL; + sp->project_root_uri = NULL; sp->path_component = NULL; sp->gdb_local_path = NULL; @@ -1668,6 +1781,20 @@ preferences_timeout_cb (gpointer userdata) } static void +full_radio_toggled_cb (GtkToggleButton *toggle, gpointer userdata) +{ + gtk_widget_set_sensitive (GTK_WIDGET (userdata), + gtk_toggle_button_get_active (toggle)); +} + +static void +toolchain_radio_toggled_cb (GtkToggleButton *toggle, gpointer userdata) +{ + gtk_widget_set_sensitive (GTK_WIDGET (userdata), + gtk_toggle_button_get_active (toggle)); +} + +static void ipreferences_merge (IAnjutaPreferences *ipref, AnjutaPreferences *prefs, GError **error) { @@ -1686,6 +1813,10 @@ ipreferences_merge (IAnjutaPreferences *ipref, AnjutaPreferences *prefs, GtkWidget *chooser; GtkWidget *entry; GtkWidget *inner_alignment; + GtkWidget *qemu_vbox; + + GtkWidget *toolchain_radio; + GtkWidget *full_radio; gboolean res; gchar *filename = NULL; @@ -1716,9 +1847,20 @@ ipreferences_merge (IAnjutaPreferences *ipref, AnjutaPreferences *prefs, gtk_container_add (GTK_CONTAINER (inner_alignment), inner_vbox); gtk_container_add (GTK_CONTAINER (frame), inner_alignment); + /* Radio for external toolchain */ + toolchain_radio = gtk_radio_button_new_with_label (NULL, + _("Use an external toolchain")); + gtk_box_pack_start (GTK_BOX (inner_vbox), toolchain_radio, TRUE, FALSE, 0); + /* Widgets for sdk root */ + inner_alignment = gtk_alignment_new (0, 0.5, 1, 1); + g_object_set (inner_alignment, "left-padding", 24, NULL); + gtk_box_pack_start (GTK_BOX (inner_vbox), inner_alignment, TRUE, FALSE, 0); + hbox = gtk_hbox_new (FALSE, 6); - gtk_box_pack_start (GTK_BOX (inner_vbox), hbox, TRUE, FALSE, 0); + gtk_container_add (GTK_CONTAINER (inner_alignment), hbox); + g_signal_connect (toolchain_radio, "toggled", (GCallback)toolchain_radio_toggled_cb, + hbox); /* label */ label = gtk_label_new (_("SDK root: ")); @@ -1744,6 +1886,72 @@ ipreferences_merge (IAnjutaPreferences *ipref, AnjutaPreferences *prefs, if (!res) g_warning ("Error adding preference for SDK root"); + /* Radio for poky tree */ + full_radio = gtk_radio_button_new_with_label_from_widget ( + GTK_RADIO_BUTTON (toolchain_radio), + _("Use a full Poky tree")); + gtk_box_pack_start (GTK_BOX (inner_vbox), full_radio, TRUE, FALSE, 0); + + /* Widgets for full tree */ + inner_alignment = gtk_alignment_new (0, 0.5, 1, 1); + g_object_set (inner_alignment, "left-padding", 24, NULL); + gtk_box_pack_start (GTK_BOX (inner_vbox), inner_alignment, TRUE, FALSE, 0); + + hbox = gtk_hbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (inner_alignment), hbox); + g_signal_connect (full_radio, "toggled", (GCallback)full_radio_toggled_cb, + hbox); + + /* Make the full options insensitive since by default we used external + * toolchain mode */ + gtk_widget_set_sensitive (hbox, FALSE); + + /* label */ + label = gtk_label_new (_("Poky root: ")); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_size_group_add_widget (opts_labels_group, label); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + + /* chooser */ + chooser = gtk_file_chooser_button_new (_("Select Poky root"), + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); + sp->poky_root_chooser = chooser; + + gtk_size_group_add_widget (opts_fields_group, label); + gtk_box_pack_start (GTK_BOX (hbox), chooser, TRUE, TRUE, 0); + + res = anjuta_preferences_register_property_raw ( + ANJUTA_PREFERENCES (prefs), + chooser, + PREFS_PROP_POKY_ROOT, + NULL, + 0, + ANJUTA_PROPERTY_OBJECT_TYPE_FOLDER, + ANJUTA_PROPERTY_DATA_TYPE_TEXT); + + if (!res) + g_warning ("Error adding preference for Poky root"); + + /* Register a preference for the toggle */ + + /* This is all a bit of a hack, we register the property on the second one + * in the group. If the mode is 1 then this gets selected and the world is a + * happy place. But if this is 0, then the group is in an inconsistent + * state...Ah, but actually when the widgets are created the first is + * toggled on by default. + */ + res = anjuta_preferences_register_property_raw ( + ANJUTA_PREFERENCES (prefs), + full_radio, + PREFS_PROP_POKY_MODE, + NULL, + 0, + ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE, + ANJUTA_PROPERTY_DATA_TYPE_INT); + + if (!res) + g_warning ("Error adding preference for mode of operation"); + /* Widgets for toolchain triplet */ hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (inner_vbox), hbox, TRUE, FALSE, 0); |