[vala] girwriter: Derive gir namespace from base name



commit 4eb9670fd04c457a00f76da42c7c51928cf63b91
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sat Jan 4 14:51:52 2014 +0100

    girwriter: Derive gir namespace from base name
    
    Instead of using the full filename specified by --gir to derive the
    gir namespace, this patch uses only the base name of the file specified by
    --gir.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=721452

 codegen/valagirwriter.vala |    4 ++--
 compiler/valacompiler.vala |   13 +++++++------
 2 files changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 8356afa..f6da0ad 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -141,7 +141,7 @@ public class Vala.GIRWriter : CodeVisitor {
         * @param context  a code context
         * @param filename a relative or absolute filename
         */
-       public void write_file (CodeContext context, string directory, string gir_namespace, string 
gir_version, string package) {
+       public void write_file (CodeContext context, string directory, string gir_filename, string 
gir_namespace, string gir_version, string package) {
                this.context = context;
                this.directory = directory;
                this.gir_namespace = gir_namespace;
@@ -159,7 +159,7 @@ public class Vala.GIRWriter : CodeVisitor {
                indent--;
                buffer.append_printf ("</repository>\n");
 
-               string filename = "%s%c%s-%s.gir".printf (directory, Path.DIR_SEPARATOR, gir_namespace, 
gir_version);
+               string filename = "%s%c%s".printf (directory, Path.DIR_SEPARATOR, gir_filename);
                stream = FileStream.open (filename, "w");
                if (stream == null) {
                        Report.error (null, "unable to open `%s' for writing".printf (filename));
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 8c7f507..16b55f2 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -351,14 +351,15 @@ class Vala.Compiler {
 
                if (library != null) {
                        if (gir != null) {
-                               long gir_len = gir.length;
-                               int last_hyphen = gir.last_index_of_char ('-');
+                               string gir_base = Path.get_basename(gir);
+                               long gir_len = gir_base.length;
+                               int last_hyphen = gir_base.last_index_of_char ('-');
 
-                               if (last_hyphen == -1 || !gir.has_suffix (".gir")) {
+                               if (last_hyphen == -1 || !gir_base.has_suffix (".gir")) {
                                        Report.error (null, "GIR file name `%s' is not well-formed, expected 
NAME-VERSION.gir".printf (gir));
                                } else {
-                                       string gir_namespace = gir.substring (0, last_hyphen);
-                                       string gir_version = gir.substring (last_hyphen + 1, gir_len - 
last_hyphen - 5);
+                                       string gir_namespace = gir_base.substring (0, last_hyphen);
+                                       string gir_version = gir_base.substring (last_hyphen + 1, gir_len - 
last_hyphen - 5);
                                        gir_version.canon ("0123456789.", '?');
                                        if (gir_namespace == "" || gir_version == "" || 
!gir_version[0].isdigit () || gir_version.contains ("?")) {
                                                Report.error (null, "GIR file name `%s' is not well-formed, 
expected NAME-VERSION.gir".printf (gir));
@@ -371,7 +372,7 @@ class Vala.Compiler {
                                                        gir_directory = context.directory;
                                                }
 
-                                               gir_writer.write_file (context, gir_directory, gir_namespace, 
gir_version, library);
+                                               gir_writer.write_file (context, gir_directory, gir, 
gir_namespace, gir_version, library);
                                        }
                                }
 


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