[anjuta] build-basic-autootls: Get make targets for files from language-manager plugin



commit 2b07487e5a045fd9ebba74c57fab118793df24db
Author: Johannes Schmid <jhs idefix localdomain>
Date:   Sat Mar 6 14:41:53 2010 +0100

    build-basic-autootls: Get make targets for files from language-manager plugin
    
    This makes things much cleaner than using a stupid hash_table and it also fixes
    bgo#611933 by adding a make target for vala

 libanjuta/interfaces/libanjuta.idl                 |   26 +++++--
 plugins/build-basic-autotools/plugin.c             |   78 ++++++++++----------
 plugins/language-manager/languages.xml             |   12 ++--
 plugins/language-manager/plugin.c                  |   16 ++++
 .../language-support-cpp-java/cpp-java-assist.c    |    2 +-
 5 files changed, 81 insertions(+), 53 deletions(-)
---
diff --git a/libanjuta/interfaces/libanjuta.idl b/libanjuta/interfaces/libanjuta.idl
index ca0833e..143ae6b 100644
--- a/libanjuta/interfaces/libanjuta.idl
+++ b/libanjuta/interfaces/libanjuta.idl
@@ -6023,7 +6023,7 @@ interface IAnjutaPluginFactory
 /**
  * SECTION:ianjuta-language
  * @title: IAnjutaLanguage
- * @short_description: Interface to manager multiple programming languages
+ * @short_description: Interface to manage multiple programming languages
  * @see_also: 
  * @stability: Unstable
  * @include: libanjuta/interfaces/ianjuta-language.h
@@ -6035,7 +6035,7 @@ interface IAnjutaLanguage
   #include <libanjuta/interfaces/ianjuta-editor-language.h>
 typedef gint Id;
 
-	/*
+	/**
 	 * ianjuta_language_from_mime_type:
 	 * @obj: Self
 	 * @mime_type: A mime type to get the language for
@@ -6044,7 +6044,7 @@ typedef gint Id;
 	 */
 	 Id get_from_mime_type (const gchar* mime_type);
 	 
-	/*
+	/**
 	 * ianjuta_language_from_string:
 	 * @obj: Self
 	 * @string: A string representation of the language. Note that multiple
@@ -6054,7 +6054,7 @@ typedef gint Id;
 	 */
 	 Id get_from_string (const gchar* string);
 	 
- 	/*
+ 	/**
 	 * ianjuta_language_get_name:
 	 * @obj: Self
 	 * @id: A valid language id
@@ -6065,7 +6065,17 @@ typedef gint Id;
 	 */
 	 const gchar* get_name(Id id);
 
-	/*
+	/**
+	 * ianjuta_language_get_make_target:
+	 * @obj: Self
+	 * @id: A valid language id
+	 *
+	 * Returns: The suffix for the file thats needs to be passed to
+	 * make to compile the file, e.g. ".o" for C
+	 */
+	 const gchar* get_make_target (Id id);
+
+	/**
 	 * ianjuta_language_get_strings
 	 * @obj: Self
 	 * @id: A valid language id
@@ -6074,7 +6084,7 @@ typedef gint Id;
 	 */
 	 List<const gchar*> get_strings(Id id);
 	 
-	 /*
+	 /**
 	  * ianjuta_language_get_from_editor:
 	  * @obj: Self
 	  * @editor: An object implementing IAnjutaEditorLanguage
@@ -6087,7 +6097,7 @@ typedef gint Id;
 	  
 	  IAnjutaLanguageId get_from_editor (IAnjutaEditorLanguage* editor);
 	  
-	  	 /*
+	 /**
 	  * ianjuta_language_get_name_from_editor:
 	  * @obj: Self
 	  * @editor: An object implementing IAnjutaEditorLanguage
@@ -6100,7 +6110,7 @@ typedef gint Id;
 	  
 	  const gchar* get_name_from_editor (IAnjutaEditorLanguage* editor);
 	  
-	  /*
+	  /**
 	   * ianjuta_language_get_languages:
 	   * @obj: Self
 	   * @err: Error propagation
diff --git a/plugins/build-basic-autotools/plugin.c b/plugins/build-basic-autotools/plugin.c
index bbfe63f..0eef930 100644
--- a/plugins/build-basic-autotools/plugin.c
+++ b/plugins/build-basic-autotools/plugin.c
@@ -38,6 +38,7 @@
 #include <libanjuta/interfaces/ianjuta-environment.h>
 #include <libanjuta/interfaces/ianjuta-message-manager.h>
 #include <libanjuta/interfaces/ianjuta-document-manager.h>
+#include <libanjuta/interfaces/ianjuta-language.h>
 #include <libanjuta/interfaces/ianjuta-file-savable.h>
 #include <libanjuta/interfaces/ianjuta-indicable.h>
 #include <libanjuta/interfaces/ianjuta-preferences.h>
@@ -1740,8 +1741,6 @@ build_tarball (BasicAutotoolsPlugin *plugin)
 	return context;
 }
 
-
-
 static BuildContext*
 build_compile_file (BasicAutotoolsPlugin *plugin, const gchar *filename)
 {
@@ -1750,27 +1749,7 @@ build_compile_file (BasicAutotoolsPlugin *plugin, const gchar *filename)
 	gchar *src_dir;
 	gchar *target;
 	gchar *ext_ptr;
-	gboolean ret;
-	
-	/* FIXME: This should be configuration somewhere, eg. preferences */
-	static GHashTable *target_ext = NULL;
-	if (!target_ext)
-	{
-		target_ext = g_hash_table_new (g_str_hash, g_str_equal);
-		g_hash_table_insert (target_ext, ".c", ".o");
-		g_hash_table_insert (target_ext, ".cpp", ".o");
-		g_hash_table_insert (target_ext, ".cxx", ".o");
-		g_hash_table_insert (target_ext, ".c++", ".o");
-		g_hash_table_insert (target_ext, ".cc", ".o");
-		g_hash_table_insert (target_ext, ".y", ".o");
-		g_hash_table_insert (target_ext, ".l", ".o");
-		g_hash_table_insert (target_ext, ".in", "");
-		g_hash_table_insert (target_ext, ".in.in", ".in");
-		g_hash_table_insert (target_ext, ".la", ".la");
-		g_hash_table_insert (target_ext, ".a", ".a");
-		g_hash_table_insert (target_ext, ".so", ".so");
-		g_hash_table_insert (target_ext, ".java", ".class");
-	}
+	gboolean ret;	
 	
 	g_return_val_if_fail (filename != NULL, FALSE);
 	ret = FALSE;
@@ -1782,26 +1761,49 @@ build_compile_file (BasicAutotoolsPlugin *plugin, const gchar *filename)
 	ext_ptr = strrchr (target, '.');
 	if (ext_ptr)
 	{
-		const gchar *new_ext;
-		new_ext = g_hash_table_lookup (target_ext, ext_ptr);
-		if (new_ext)
+		GFile* file = g_file_new_for_path (filename);
+		GFileInfo* file_info = g_file_query_info (file,
+		                                          G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+		                                          G_FILE_QUERY_INFO_NONE,
+		                                          NULL,
+		                                          NULL);
+		if (file_info)
 		{
-			BuildProgram *prog;
-			
-			*ext_ptr = '\0';
-			prog = build_program_new_with_command (build_dir, "%s %s%s",
-											   CHOOSE_COMMAND (plugin, COMPILE),
-											   target, new_ext);
-			context = build_save_and_execute_command (plugin, prog, TRUE, NULL);
-			ret = TRUE;
+			const gchar *new_ext;
+			IAnjutaLanguage* langman =
+				anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
+				                            IAnjutaLanguage,
+				                            NULL);
+			gint id = ianjuta_language_get_from_mime_type (langman,
+			                                               g_file_info_get_content_type (file_info),
+			                                               NULL);
+			DEBUG_PRINT ("Found mime-type: %s", g_file_info_get_content_type (file_info));
+			if (id > 0)
+			{
+				new_ext = ianjuta_language_get_make_target (langman, id, NULL);
+				if (new_ext)
+				{
+					BuildProgram *prog;
+
+					DEBUG_PRINT ("New extension: %s", new_ext);
+
+					*ext_ptr = '\0';
+					prog = build_program_new_with_command (build_dir, "%s %s%s",
+					                                       CHOOSE_COMMAND (plugin, COMPILE),
+					                                       target, new_ext);
+					context = build_save_and_execute_command (plugin, prog, TRUE, NULL);
+					ret = TRUE;
+				}
+			}
 		}
-	} else {
+	}
+	else {
 		/* If file has no extension, take it as target itself */
 		BuildProgram *prog;
-		
+
 		prog = build_program_new_with_command (build_dir, "%s %s",
-										   CHOOSE_COMMAND(plugin, COMPILE),
-							   			   target);
+		                                       CHOOSE_COMMAND(plugin, COMPILE),
+		                                       target);
 		context = build_save_and_execute_command (plugin, prog, TRUE, NULL);
 		ret = TRUE;
 	}
diff --git a/plugins/language-manager/languages.xml b/plugins/language-manager/languages.xml
index c7aa521..a0e21e9 100644
--- a/plugins/language-manager/languages.xml
+++ b/plugins/language-manager/languages.xml
@@ -2,11 +2,11 @@
 		 ids start from 1 and that names have to be unique 
 		 Strings are recognized caseless -->
 <languages>
-	<language id="1" name="C" strings="c,chdr" mime-types="text/x-csrc,text/x-chdr" />
-	<language id="2" name="C++" strings="c,cpp,c++,chdr" mime-types="text/x-c++src,text/x-c++hdr" />
-	<language id="3" name="Java" strings="java" mime-types="text/x-java" />
-	<language id="4" name="Python" strings="python" mime-types="text/x-python" />
+	<language id="1" name="C" strings="c,chdr" mime-types="text/x-csrc,text/x-chdr" make-target=".o" />
+	<language id="2" name="C++" strings="c,cpp,c++,chdr" mime-types="text/x-c++src,text/x-c++hdr" make-target=".o" />
+	<language id="3" name="Java" strings="java" mime-types="text/x-java" make-target=".class" />
+	<language id="4" name="Python" strings="python" mime-types="text/x-python"/>
 	<language id="5" name="C#" strings="c#,csharp" mime-types="text/x-csharp" />
-	<language id="6" name="Vala" strings="vala" mime-types="text/x-vala" />
-	<language id="7" name="JavaScript" strings="js,javascript" mime-types="application/javascript" />
+	<language id="6" name="Vala" strings="vala" mime-types="text/x-vala" make-target=".o"/>
+	<language id="7" name="JavaScript" strings="js,javascript" mime-types="application/javascript"/>
 </languages>
diff --git a/plugins/language-manager/plugin.c b/plugins/language-manager/plugin.c
index f68d2e3..88d98bd 100644
--- a/plugins/language-manager/plugin.c
+++ b/plugins/language-manager/plugin.c
@@ -41,6 +41,7 @@ struct _Language
 {
 	IAnjutaLanguageId id;
 	gchar* name;
+	gchar* make_target;
 	GList* strings;
 	GList* mime_types;
 };
@@ -96,6 +97,7 @@ load_languages (LanguageManager* language_manager)
 		id = (gchar*) xmlGetProp (cur_node, (const xmlChar*) "id");
 		lang->id = atoi(id);
 		lang->name = (gchar*) xmlGetProp(cur_node, (const xmlChar*) "name");
+		lang->make_target = (gchar*) xmlGetProp (cur_node, (const xmlChar*) "make-target");
 		mime_types = (gchar*) xmlGetProp (cur_node, (const xmlChar*) "mime-types");
 		strings = (gchar*) xmlGetProp (cur_node, (const xmlChar*) "strings");
 		if (lang->id != 0 && lang->name && mime_types && strings)
@@ -298,6 +300,19 @@ ilanguage_get_strings (IAnjutaLanguage* ilang, IAnjutaLanguageId id, GError** e)
 		return NULL;	
 }
 
+static const char*
+ilanguage_get_make_target (IAnjutaLanguage* ilang, IAnjutaLanguageId id, GError** e)
+{
+	LanguageManager* lang = LANGUAGE_MANAGER(ilang);
+	Language* language = g_hash_table_lookup (lang->languages,
+											   GINT_TO_POINTER(id));
+	if (language)
+		return language->make_target;
+	else
+		return NULL;
+
+}
+
 static IAnjutaLanguageId
 ilanguage_get_from_editor (IAnjutaLanguage* ilang, IAnjutaEditorLanguage* editor, GError** e)
 {	
@@ -331,6 +346,7 @@ ilanguage_iface_init (IAnjutaLanguageIface* iface)
 	iface->get_from_string = ilanguage_get_from_string;
 	iface->get_name = ilanguage_get_name;
 	iface->get_strings = ilanguage_get_strings;
+	iface->get_make_target = ilanguage_get_make_target;
 	iface->get_from_editor = ilanguage_get_from_editor;
 	iface->get_name_from_editor = ilanguage_get_name_from_editor;
 	iface->get_languages = ilanguage_get_languages;
diff --git a/plugins/language-support-cpp-java/cpp-java-assist.c b/plugins/language-support-cpp-java/cpp-java-assist.c
index c8b826e..da8fe76 100644
--- a/plugins/language-support-cpp-java/cpp-java-assist.c
+++ b/plugins/language-support-cpp-java/cpp-java-assist.c
@@ -972,7 +972,7 @@ cpp_java_assist_get_scope_context (IAnjutaEditor* editor,
 								   const gchar *scope_operator,
 								   IAnjutaIterable *iter)
 {
-	IAnjutaIterable* end;
+	IAnjutaIterable* end;	
 	gchar ch, *scope_chars = NULL;
 	gboolean out_of_range = FALSE;
 	gboolean scope_chars_found = FALSE;



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