[vala/switch-to-gir] Add --metadatadir option to specify path for GIR metadata
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/switch-to-gir] Add --metadatadir option to specify path for GIR metadata
- Date: Mon, 8 Nov 2010 12:29:48 +0000 (UTC)
commit 991335479d94a649e64b4c97b11756e86168b0a1
Author: Luca Bruno <lucabru src gnome org>
Date: Mon Nov 8 13:16:35 2010 +0100
Add --metadatadir option to specify path for GIR metadata
compiler/valacompiler.vala | 6 +++++-
vala/valacodecontext.vala | 39 ++++++++++++++++++++++++++++++++++-----
vala/valagirparser.vala | 4 ++--
vapigen/valavapigen.vala | 4 ++++
4 files changed, 45 insertions(+), 8 deletions(-)
---
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index ae88a6b..034d008 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -33,6 +33,8 @@ class Vala.Compiler {
static string[] vapi_directories;
[CCode (array_length = false, array_null_terminated = true)]
static string[] gir_directories;
+ [CCode (array_length = false, array_null_terminated = true)]
+ static string[] metadata_directories;
static string vapi_filename;
static string library;
static string gir;
@@ -85,8 +87,9 @@ class Vala.Compiler {
private CodeContext context;
const OptionEntry[] options = {
- { "girdir", 0, 0, OptionArg.FILENAME_ARRAY, ref gir_directories, "Look for .gir files in DIRECTORY", "DIRECTORY..." },
{ "vapidir", 0, 0, OptionArg.FILENAME_ARRAY, ref vapi_directories, "Look for package bindings in DIRECTORY", "DIRECTORY..." },
+ { "girdir", 0, 0, OptionArg.FILENAME_ARRAY, ref gir_directories, "Look for .gir files in DIRECTORY", "DIRECTORY..." },
+ { "metadatadir", 0, 0, OptionArg.FILENAME_ARRAY, ref metadata_directories, "Look for GIR .metadata files 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" },
@@ -199,6 +202,7 @@ class Vala.Compiler {
}
context.vapi_directories = vapi_directories;
context.gir_directories = gir_directories;
+ context.metadata_directories = metadata_directories;
context.debug = debug;
context.thread = thread;
context.mem_profiler = mem_profiler;
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala
index cfb0a9b..efa91e1 100644
--- a/vala/valacodecontext.vala
+++ b/vala/valacodecontext.vala
@@ -114,6 +114,11 @@ public class Vala.CodeContext {
public string[] gir_directories;
/**
+ * List of directories where to find .metadata files for .gir files.
+ */
+ public string[] metadata_directories;
+
+ /**
* Produce debug information.
*/
public bool debug { get; set; }
@@ -498,7 +503,29 @@ public class Vala.CodeContext {
return get_file_path (gir + ".gir", "gir-1.0", null, gir_directories);
}
- string? get_file_path (string basename, string versioned_data_dir, string? data_dir, string[] directories) {
+ /*
+ * Returns the .metadata file associated with the given .gir file.
+ */
+ public string? get_metadata_path (string gir_filename) {
+ var basename = Path.get_basename (gir_filename);
+ var metadata_basename = "%s.metadata".printf (basename.ndup (basename.length - ".gir".length));
+
+ // look into metadata directories
+ var metadata_filename = get_file_path (metadata_basename, null, null, metadata_directories);
+ if (metadata_filename != null) {
+ return metadata_filename;
+ }
+
+ // look into the same directory of .gir
+ metadata_filename = Path.build_filename (Path.get_dirname (gir_filename), metadata_basename);
+ if (FileUtils.test (metadata_filename, FileTest.EXISTS)) {
+ return metadata_filename;
+ }
+
+ return null;
+ }
+
+ string? get_file_path (string basename, string? versioned_data_dir, string? data_dir, string[] directories) {
string filename = null;
if (directories != null) {
@@ -510,10 +537,12 @@ public class Vala.CodeContext {
}
}
- foreach (string dir in Environment.get_system_data_dirs ()) {
- filename = Path.build_filename (dir, versioned_data_dir, basename);
- if (FileUtils.test (filename, FileTest.EXISTS)) {
- return filename;
+ if (versioned_data_dir != null) {
+ foreach (string dir in Environment.get_system_data_dirs ()) {
+ filename = Path.build_filename (dir, versioned_data_dir, basename);
+ if (FileUtils.test (filename, FileTest.EXISTS)) {
+ return filename;
+ }
}
}
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index bc959fa..31a3bd2 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -584,8 +584,8 @@ public class Vala.GirParser : CodeVisitor {
metadata = Metadata.empty;
girdata_stack = new ArrayList<HashMap<string,string>> ();
- // load metadata
- string metadata_filename = "%s.metadata".printf (source_file.filename.ndup (source_file.filename.length - ".gir".length));
+ // load metadata, first look into metadata directories then in the same directory of the .gir.
+ string? metadata_filename = context.get_metadata_path (source_file.filename);
if (FileUtils.test (metadata_filename, FileTest.EXISTS)) {
var metadata_parser = new MetadataParser ();
var metadata_file = new SourceFile (context, source_file.file_type, metadata_filename);
diff --git a/vapigen/valavapigen.vala b/vapigen/valavapigen.vala
index 2968b0a..cb44363 100644
--- a/vapigen/valavapigen.vala
+++ b/vapigen/valavapigen.vala
@@ -33,6 +33,8 @@ class Vala.VAPIGen : Object {
static string[] vapi_directories;
[CCode (array_length = false, array_null_terminated = true)]
static string[] gir_directories;
+ [CCode (array_length = false, array_null_terminated = true)]
+ static string[] metadata_directories;
static string library;
[CCode (array_length = false, array_null_terminated = true)]
static string[] packages;
@@ -41,6 +43,7 @@ class Vala.VAPIGen : Object {
const OptionEntry[] options = {
{ "vapidir", 0, 0, OptionArg.FILENAME_ARRAY, ref vapi_directories, "Look for package bindings in DIRECTORY", "DIRECTORY..." },
{ "girdir", 0, 0, OptionArg.FILENAME_ARRAY, ref gir_directories, "Look for GIR bindings in DIRECTORY", "DIRECTORY..." },
+ { "metadatadir", 0, 0, OptionArg.FILENAME_ARRAY, ref metadata_directories, "Look for GIR .metadata files in DIRECTORY", "DIRECTORY..." },
{ "pkg", 0, 0, OptionArg.STRING_ARRAY, ref packages, "Include binding for PACKAGE", "PACKAGE..." },
{ "library", 0, 0, OptionArg.STRING, ref library, "Library name", "NAME" },
{ "directory", 'd', 0, OptionArg.FILENAME, ref directory, "Output directory", "DIRECTORY" },
@@ -70,6 +73,7 @@ class Vala.VAPIGen : Object {
context.profile = Profile.GOBJECT;
context.vapi_directories = vapi_directories;
context.gir_directories = gir_directories;
+ context.metadata_directories = metadata_directories;
context.report.enable_warnings = !disable_warnings;
context.report.set_verbose_errors (!quiet_mode);
CodeContext.push (context);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]