[vala] Add --gir option to enable GIR generation
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [vala] Add --gir option to enable GIR generation
- Date: Sun, 17 May 2009 06:29:53 -0400 (EDT)
commit 712d456a7f8ab7ffe3a157c24d0ed16e8bdf33e6
Author: Didier 'Ptitjes <ptitjes free fr>
Date: Mon Mar 30 19:01:40 2009 +0200
Add --gir option to enable GIR generation
Signed-off-by: Didier 'Ptitjes <ptitjes free fr>
---
codegen/valagirwriter.vala | 9 ++++++++-
compiler/valacompiler.vala | 28 +++++++++++++++++++++-------
2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 63e9c31..6fe208d 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -28,6 +28,9 @@ using Gee;
*/
public class Vala.GIRWriter : CodeVisitor {
private CodeContext context;
+ private string directory;
+ private string gir_namespace;
+ private string gir_version;
FileStream stream;
@@ -42,13 +45,17 @@ public class Vala.GIRWriter : CodeVisitor {
* @param context a code context
* @param filename a relative or absolute filename
*/
- public void write_file (CodeContext context, string filename) {
+ public void write_file (CodeContext context, string directory, string gir_namespace, string gir_version) {
this.context = context;
+ this.directory = directory;
+ this.gir_namespace = gir_namespace;
+ this.gir_version = gir_version;
var root_symbol = context.root;
var glib_ns = root_symbol.scope.lookup ("GLib");
gobject_type = (TypeSymbol) glib_ns.scope.lookup ("Object");
+ string filename = "%s%c%s-%s.gir".printf (directory, Path.DIR_SEPARATOR, gir_namespace, gir_version);
stream = FileStream.open (filename, "w");
stream.printf ("<?xml version=\"1.0\"?>\n");
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index ab767c6..9a6bf93 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -35,6 +35,7 @@ class Vala.Compiler {
static string[] vapi_directories;
static string vapi_filename;
static string library;
+ static string gir;
[CCode (array_length = false, array_null_terminated = true)]
[NoArrayLength]
static string[] packages;
@@ -74,6 +75,7 @@ class Vala.Compiler {
{ "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" },
{ "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 },
@@ -359,16 +361,28 @@ class Vala.Compiler {
}
if (library != null) {
- if (context.profile == Profile.GOBJECT) {
- var gir_writer = new GIRWriter ();
- string gir_filename = "%s.gir".printf (library);
+ 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];
+
+ // put .gir file in current directory unless -d has been explicitly specified
+ string gir_directory = ".";
+ if (directory != null) {
+ gir_directory = context.directory;
+ }
- // put .gir file in current directory unless -d has been explicitly specified
- if (directory != null && !Path.is_absolute (gir_filename)) {
- gir_filename = "%s%c%s".printf (context.directory, Path.DIR_SEPARATOR, gir_filename);
+ gir_writer.write_file (context, gir_directory, gir_namespace, gir_version);
+ }
}
- gir_writer.write_file (context, gir_filename);
+ gir = null;
}
library = null;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]