After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 584683 - GIR: add vapi annotation
GIR: add vapi annotation
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.7.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2009-06-03 02:56 UTC by Mark Lee
Modified: 2010-02-01 16:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
add GIR annotation for vala and vapi files (8.86 KB, patch)
2009-07-30 16:04 UTC, Mark Lee
none Details | Review
Update original patch (7.62 KB, patch)
2009-08-20 22:22 UTC, John Carr
none Details | Review
Updated patch (13.37 KB, patch)
2010-01-31 21:07 UTC, Rob Taylor
none Details | Review
Updated patch (17.93 KB, patch)
2010-02-01 11:41 UTC, Rob Taylor
none Details | Review

Description Mark Lee 2009-06-03 02:56:06 UTC
One of the GIR features missing in Vala's handling of reading and writing GIR files is <include/> support. I propose that a new annotation for namespaces be added, specifically for GIR support.

Example (gobject-2.0.vapi):

[GIR (namespace = "GObject", version = "2.0")]
[CCode (cprefix = "G", lower_case_cprefix = "g_", cheader_filename = "glib.h")]
namespace GLib {
    // ...
}

There are three methods to determine the values of the annotations:
1. Manually (when hand-writing vapi files)
2. Via package.metadata, "gir_namespace" and "gir_version" (when giving vapigen a GI file)
3. Automatically parsed from the GIR file (when giving vapigen a GIR file)

The main advantage to this approach that I see is that it avoids the need for valac to call `pkg-config` multiple times to determine the GIR namespace(s) and version(s) of the library's dependencies. (see bug 577347).

This would also avoid having to make namespace exceptions in gir reading/writing (such as my attachment 133005 [details] [review] in bug 559704).
Comment 1 Mark Lee 2009-07-30 16:04:40 UTC
Created attachment 139569 [details] [review]
add GIR annotation for vala and vapi files

Adds support for both parsing and writing the GIR annotation for Vala files.

The annotation is meant to be applied to namespaces only in vala/vapi files,
and the GIR metadata is propagated to the child symbols by the namespace.

The special casing for GObject.Object GIR namespace has been removed.

All symbols now have a GIR namespace property, used when the Vala namespace    
does not match the GIR namespace. All namespaces now have a GIR namespace
version property, used when writing the GIR dependencies in a library's
GIR file.

There are also namespace metadata annotations added: gir_namespace and
gir_version (see gdk-pixbuf-2.0.metadata for an example).

Adds the proper GIR namespaces for gobject-2.0, cairo, and gdk-pixbuf-2.0.
Comment 2 John Carr 2009-08-20 22:22:13 UTC
Created attachment 141300 [details] [review]
Update original patch

If i understood IRC correctly this needed switching to use [CCodeNode] instead of [Gir], so i had a go.

Rather than propogate gir_namespace to a load of classes i added get_gir_namespace which walks parent_symbol until it finds a namespace or a wall - not sure if this is the best idea or if it even works but it at least builds :)
Comment 3 John Carr 2009-08-20 22:24:12 UTC
[Doh, fails to link though]
Comment 4 Rob Taylor 2010-01-31 21:07:40 UTC
Created attachment 152697 [details] [review]
Updated patch

This is my latest version of the patch after much reworking. Now we store the namespace and version as properties on SourceFile, this allows us to split a vala namespace into multiple GIR namespaces.

It now correctly outputs <include> lines for the api dependancies, and warns if dependent namespaces havn't been annotated.
Comment 5 Rob Taylor 2010-01-31 22:48:17 UTC
Ah, no, still not final. There's a bug where it writes multiple <include> tags. Patch coming up.
Comment 6 Rob Taylor 2010-02-01 11:41:43 UTC
Created attachment 152719 [details] [review]
Updated patch

This version fixes the multiple <include> problem and adds annotations for some core vapis.
Comment 7 Jürg Billeter 2010-02-01 16:00:50 UTC
commit 7dcc676f1782a18fccfdf5203ef809e4aa6c19c9
Author: Rob Taylor <rob.taylor@codethink.co.uk>
Date:   Sun Jan 31 16:11:00 2010 +0000

    GIR Namespace support
    
    This patch introduces two new CCode annotations for use in VAPI files,
    gir_namespace and gir_version. This allows us to correctly map vala
    namespaces to gobject-introspection namespaces when generating GIR
    files.
    
    The mapping is actually done on a SourceFile level. This allows us to
    work around cases where one vala namespace maps into multiple GIR
    namespaces (in particular, GLib vs GLib and GObject).
    
    In the absense of annotations, the old 'guess it' method will be
    applied.
    
    This commit also adds annotations to some core vapis.
    
    Fixes bug 584683.