Dear list, and Didier,

It might be more convenient if the default value of everything related to
the library is deduced from the value of --library.

The attachment is my patch on this.

Commit 712d456 also depends on Regex which is not available in GLib 2.14.
This patch also removes the RegEx dependency.


Regards,


Yu
From 407df7ef57ab83d7ec57228cd2db7009a6afdcd8 Mon Sep 17 00:00:00 2001
From: Feng Yu <[email protected]>
Date: Tue, 19 May 2009 17:13:00 -0400
Subject: [PATCH] Deduce the ABI version, Gir Namespace, vapi file name, gir file name from --library.

The logic:
if --library=package-1.0 then
default values:
--gir-namespace = Package
--abi-version = 1.0
--gir = Package-1.0.gir
--vapi = package-1.0.vapi
endif
if --library=package then
default values
--gir-namespace = Pakcage
--abi-version = 0.0
--gir = Package-0.0.gir
--vapi = package-0.0.vapi
endif

This is a incompatible change, when no abi version is specified in library.
---
 compiler/valacompiler.vala |   77 ++++++++++++++++++++++++++++----------------
 1 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 2bb6c00..19e6e32 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -33,9 +33,11 @@ class Vala.Compiler {
 	[CCode (array_length = false, array_null_terminated = true)]
 	[NoArrayLength]
 	static string[] vapi_directories;
-	static string vapi_filename;
 	static string library;
-	static string gir;
+	static string abi_version;
+	static string vapi_filename;
+	static string gir_filename;
+	static string gir_namespace;
 	[CCode (array_length = false, array_null_terminated = true)]
 	[NoArrayLength]
 	static string[] packages;
@@ -73,9 +75,11 @@ class Vala.Compiler {
 	const OptionEntry[] options = {
 		{ "vapidir", 0, 0, OptionArg.FILENAME_ARRAY, ref vapi_directories, "Look for package bindings in DIRECTORY", "DIRECTORY..." },
 		{ "pkg", 0, 0, OptionArg.STRING_ARRAY, ref packages, "Include binding for PACKAGE", "PACKAGE..." },
-		{ "vapi", 0, 0, OptionArg.FILENAME, ref vapi_filename, "Output VAPI file name", "FILE" },
-		{ "library", 0, 0, OptionArg.STRING, ref library, "Library name", "NAME" },
-		{ "gir", 0, 0, OptionArg.STRING, ref gir, "GObject-Introspection repository file name", "NAME-VERSION.gir" },
+		{ "library", 0, 0, OptionArg.STRING, ref library, "Library name", "library-name" },
+		{ "abi-version", 0, 0, OptionArg.STRING, ref abi_version, "ABI version of the library", "ABIVERSION" },
+		{ "vapi", 0, 0, OptionArg.FILENAME, ref vapi_filename, "Output VAPI file name", "library-name-ABIVERSION.vapi" },
+		{ "gir-namespace", 0, 0, OptionArg.STRING, ref gir_namespace, "GObject-Introspection repository namespace", "LibraryName" },
+		{ "gir", 0, 0, OptionArg.STRING, ref gir_filename, "GObject-Introspection repository file name", "GirNamespace-ABIVERSION.gir" },
 		{ "basedir", 'b', 0, OptionArg.FILENAME, ref basedir, "Base source directory", "DIRECTORY" },
 		{ "directory", 'd', 0, OptionArg.FILENAME, ref directory, "Output directory", "DIRECTORY" },
 		{ "version", 0, 0, OptionArg.NONE, ref version, "Display version number", null },
@@ -344,9 +348,21 @@ class Vala.Compiler {
 			return quit ();
 		}
 
+
+		if (abi_version == null && library != null) {
+			var rev = library.reverse();
+			string[] sp = rev.split("-", 2);
+			if(sp != null && sp.length == 2) {
+				library = sp[1].reverse();
+				abi_version = sp[0].reverse();
+			} else {
+				abi_version = "0.0";
+			}
+		}
+
 		if (vapi_filename == null && library != null) {
 			// keep backward compatibility with --library option
-			vapi_filename = "%s.vapi".printf (library);
+			vapi_filename = "%s-%s.vapi".printf (library, abi_version);
 		}
 
 		if (vapi_filename != null) {
@@ -360,33 +376,38 @@ class Vala.Compiler {
 			interface_writer.write_file (context, vapi_filename);
 		}
 
-		if (library != null) {
-			if (gir != null) {
-				if (context.profile == Profile.GOBJECT) {
-					string[] split_gir = Regex.split_simple("(.*)-([0-9]+(\\.[0-9]+)?)\\.gir$", gir);
-
-					if (split_gir.length < 4) {
-						Report.error (null, "GIR file name `%s' is not well-formed, expected NAME-VERSION.gir".printf (gir));
-					} else {
-						var gir_writer = new GIRWriter ();
-						string gir_namespace = split_gir[1];
-						string gir_version = split_gir[2];
+		if(gir_namespace == null && library != null) {
+			StringBuilder sb = new StringBuilder("");
+			unowned string p = library;
+			unichar c = p.get_char();
+			bool to_upper = true;
+			for(;c != 0; p = p.next_char(), c = p.get_char()) {
+				if(c == '-') {
+					to_upper = true;
+				} else {
+					sb.append_unichar(to_upper?c.toupper():c);
+					to_upper = false;
+				}
+			}
+			gir_namespace = sb.str;
+		}
 
-						// put .gir file in current directory unless -d has been explicitly specified
-						string gir_directory = ".";
-						if (directory != null) {
-							gir_directory = context.directory;
-						}
+		if(gir_filename == null && library != null) {
+			gir_filename = "%s-%s.gir".printf (gir_namespace, abi_version);
+		}
 
-						gir_writer.write_file (context, gir_directory, gir_namespace, gir_version, library);
-					}
+		if (gir_filename != null) {
+			if (context.profile == Profile.GOBJECT) {
+				var gir_writer = new GIRWriter ();
+				// put .gir file in current directory unless -d has been explicitly specified
+				string gir_directory = "."; if (directory != null) {
+					gir_directory = context.directory;
 				}
 
-				gir = null;
+				gir_writer.write_file (context, gir_directory, gir_namespace, abi_version, library);
 			}
-
-			library = null;
 		}
+
 		if (internal_vapi_filename != null) {
 			if (internal_header_filename == null ||
 			    header_filename == null) {
-- 
1.5.5.6

_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to