]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girwriter: Populate gir_namespace/version attributes of external namespaces
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 27 Apr 2019 11:20:28 +0000 (13:20 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 6 Aug 2019 11:38:55 +0000 (13:38 +0200)
codegen/valagirwriter.vala

index df8ee5c82acca2c38b4b63fa6fa7ec6c0e8fbfb8..138d3593b89969b60def087351062c1303a0996a 100644 (file)
@@ -162,6 +162,11 @@ public class Vala.GIRWriter : CodeVisitor {
 
                write_package (package);
 
+               // Make sure to initialize external files with their gir_namespace/version
+               foreach (var file in context.get_source_files ()) {
+                       file.accept (this);
+               }
+
                context.accept (this);
 
                indent--;
@@ -249,6 +254,26 @@ public class Vala.GIRWriter : CodeVisitor {
                buffer.append_printf ("<c:include name=\"%s\"/>\n", name);
        }
 
+       public override void visit_source_file (SourceFile source_file) {
+               if (source_file.file_type != SourceFileType.PACKAGE) {
+                       return;
+               }
+
+               // Populate gir_namespace/version of source-file like in Namespace.check()
+               foreach (var node in source_file.get_nodes ()) {
+                       if (node is Namespace && ((Namespace) node).parent_symbol == context.root) {
+                               var a = node.get_attribute ("CCode");
+                               if (a != null && a.has_argument ("gir_namespace")) {
+                                       source_file.gir_namespace = a.get_string ("gir_namespace");
+                               }
+                               if (a != null && a.has_argument ("gir_version")) {
+                                       source_file.gir_version = a.get_string ("gir_version");
+                               }
+                               break;
+                       }
+               }
+       }
+
        public override void visit_namespace (Namespace ns) {
                if (ns.external_package) {
                        return;