Commit 53b32ce8 authored by Daniel Espinosa Ortiz's avatar Daniel Espinosa Ortiz

server: fix add namespace at {datadir}/vala/vapi

parent 77f162a6
...@@ -8,4 +8,7 @@ namespace Config { ...@@ -8,4 +8,7 @@ namespace Config {
public const string DATADIR; public const string DATADIR;
[CCode (cname = "VAPIDIR")] [CCode (cname = "VAPIDIR")]
public const string VAPIDIR; public const string VAPIDIR;
[CCode (cname = "VAPIDATADIR")]
public const string VAPIDATADIR;
} }
...@@ -120,6 +120,10 @@ public interface GVls.Server : GLib.Object, ContainerHashable ...@@ -120,6 +120,10 @@ public interface GVls.Server : GLib.Object, ContainerHashable
if (prefix_dir.query_exists (null)) { if (prefix_dir.query_exists (null)) {
vapi_dirs.add (prefix_dir); vapi_dirs.add (prefix_dir);
} }
var data_vapi = GLib.File.new_for_path (VAPIDATADIR);
if (data_vapi.query_exists (null)) {
vapi_dirs.add (data_vapi);
}
} }
/** /**
* *
...@@ -149,13 +153,13 @@ public interface GVls.Server : GLib.Object, ContainerHashable ...@@ -149,13 +153,13 @@ public interface GVls.Server : GLib.Object, ContainerHashable
if (vapi_dirs.get_n_items () == 0) { if (vapi_dirs.get_n_items () == 0) {
add_default_vapi_dirs (); add_default_vapi_dirs ();
} }
GLib.File nsf = null;
for (int i = 0; i < vapi_dirs.get_n_items (); i++) { for (int i = 0; i < vapi_dirs.get_n_items (); i++) {
var d = vapi_dirs.get_item (i) as GLib.File; var d = vapi_dirs.get_item (i) as GLib.File;
try { try {
var fs = d.enumerate_children (FileAttribute.STANDARD_NAME, var fs = d.enumerate_children (FileAttribute.STANDARD_NAME,
FileQueryInfoFlags.NONE, null); FileQueryInfoFlags.NONE, null);
FileInfo info = fs.next_file (null); FileInfo info = fs.next_file (null);
GLib.File nsf = null;
var pat = "^namespace(\\s)*"+ns+"(\\s{1})"; var pat = "^namespace(\\s)*"+ns+"(\\s{1})";
GLib.Regex rex = new GLib.Regex (pat, RegexCompileFlags.OPTIMIZE, RegexMatchFlags.ANCHORED); GLib.Regex rex = new GLib.Regex (pat, RegexCompileFlags.OPTIMIZE, RegexMatchFlags.ANCHORED);
while (info != null && nsf == null) { while (info != null && nsf == null) {
...@@ -174,12 +178,11 @@ public interface GVls.Server : GLib.Object, ContainerHashable ...@@ -174,12 +178,11 @@ public interface GVls.Server : GLib.Object, ContainerHashable
} }
info = fs.next_file (null); info = fs.next_file (null);
} }
return nsf;
} catch (GLib.Error e) { } catch (GLib.Error e) {
warning ("Error getting VAPI files at: %s : Error: %s", d.get_uri (), e.message); warning ("Error getting VAPI files at: %s : Error: %s", d.get_uri (), e.message);
} }
} }
return null; return nsf;
} }
/** /**
* *
...@@ -192,7 +195,12 @@ public interface GVls.Server : GLib.Object, ContainerHashable ...@@ -192,7 +195,12 @@ public interface GVls.Server : GLib.Object, ContainerHashable
} else if (get_symbol (ns) != null) { } else if (get_symbol (ns) != null) {
return false; return false;
} }
var nsf = find_namespace_file (ns); GLib.File nsf = null;
if (root_server != null) {
nsf = root_server.find_namespace_file (ns);
} else {
nsf = find_namespace_file (ns);
}
if (nsf == null) { if (nsf == null) {
throw new ServerError.NO_VAPI_DIR_ERROR ("Namespace not found in current VAPI dirs: %s", ns); throw new ServerError.NO_VAPI_DIR_ERROR ("Namespace not found in current VAPI dirs: %s", ns);
} }
......
vapidir = join_paths (get_option('datadir'),'vala','vapi') vapidir = join_paths (get_option('prefix'), get_option('datadir'),'vala','vapi')
GIR_NAME= VERSIONED_CAMEL_CASE_NAME+'.gir' GIR_NAME= VERSIONED_CAMEL_CASE_NAME+'.gir'
TYPELIB_NAME= VERSIONED_CAMEL_CASE_NAME+'.typelib' TYPELIB_NAME= VERSIONED_CAMEL_CASE_NAME+'.typelib'
VAPI_NAME = VERSIONED_PROJECT_NAME+'.vapi' VAPI_NAME = VERSIONED_PROJECT_NAME+'.vapi'
...@@ -41,6 +41,7 @@ confh.set_quoted('VALA_API_VERSION', vala_version) ...@@ -41,6 +41,7 @@ confh.set_quoted('VALA_API_VERSION', vala_version)
confh.set_quoted('PREFIX', get_option ('prefix')) confh.set_quoted('PREFIX', get_option ('prefix'))
confh.set_quoted('DATADIR', get_option ('datadir')) confh.set_quoted('DATADIR', get_option ('datadir'))
confh.set_quoted('VAPIDIR', VAPIDIR) confh.set_quoted('VAPIDIR', VAPIDIR)
confh.set_quoted('VAPIDATADIR', vapidir)
configure_file(output : 'config.h', configure_file(output : 'config.h',
configuration : confh) configuration : confh)
...@@ -149,4 +150,4 @@ custom_target('typelib', ...@@ -149,4 +150,4 @@ custom_target('typelib',
depends: lib, depends: lib,
install: true, install: true,
install_dir: join_paths(get_option('libdir'), 'girepository-1.0')) install_dir: join_paths(get_option('libdir'), 'girepository-1.0'))
endif endif
\ No newline at end of file
...@@ -260,12 +260,12 @@ class Tests { ...@@ -260,12 +260,12 @@ class Tests {
assert (server.symbols.get_n_items () != 0); assert (server.symbols.get_n_items () != 0);
var root = server.get_symbol("@RootNamespace@"); var root = server.get_symbol("@RootNamespace@");
assert (root != null); assert (root != null);
for (int i = 0; i < root.get_n_items (); i++) { // for (int i = 0; i < root.get_n_items (); i++) {
message ("Root Symbol found: %s".printf ((root.get_item (i) as Symbol).name)); // message ("Root Symbol found: %s".printf ((root.get_item (i) as Symbol).name));
} // }
for (int i = 0; i < server.symbols.get_n_items (); i++) { // for (int i = 0; i < server.symbols.get_n_items (); i++) {
message ("Symbol found: %s".printf ((server.symbols.get_item (i) as Symbol).name)); // message ("Symbol found: %s".printf ((server.symbols.get_item (i) as Symbol).name));
} // }
assert (server.get_symbol ("string") != null); assert (server.get_symbol ("string") != null);
assert (server.get_symbol ("string.split") != null); assert (server.get_symbol ("string.split") != null);
} catch (GLib.Error e) { } catch (GLib.Error e) {
...@@ -273,7 +273,7 @@ class Tests { ...@@ -273,7 +273,7 @@ class Tests {
assert_not_reached (); assert_not_reached ();
} }
}); });
Test.add_func ("/gvls/parse/using/namespace", Test.add_func ("/gvls/parse/using/namespace/versioned",
()=>{ ()=>{
var envp = GLib.Environ.get (); var envp = GLib.Environ.get ();
string SRC_DIR = GLib.Environ.get_variable (envp, "SRC_DIR"); string SRC_DIR = GLib.Environ.get_variable (envp, "SRC_DIR");
...@@ -321,6 +321,25 @@ class Tests { ...@@ -321,6 +321,25 @@ class Tests {
assert_not_reached (); assert_not_reached ();
} }
}); });
Test.add_func ("/gvls/parse/using/namespace/unversioned",
()=>{
var envp = GLib.Environ.get ();
string SRC_DIR = GLib.Environ.get_variable (envp, "SRC_DIR");
GLib.File file = GLib.File.new_for_path (SRC_DIR+"/namespace.vala");
assert (file.query_exists ());
Server server = new GServer () as Server;
server.add_default_namespaces ();
assert (server.vapi_dirs.get_n_items () == 2);
try {
server.add_namespace ("Gee");
assert (server.get_symbol ("Gee") != null);
server.add_namespace ("Vala");
assert (server.get_symbol ("Vala") != null);
} catch (GLib.Error e) {
message ("Error: %s", e.message);
assert_not_reached ();
}
});
Test.add_func ("/gvls/parse/documentation", Test.add_func ("/gvls/parse/documentation",
()=>{ ()=>{
var envp = GLib.Environ.get (); var envp = GLib.Environ.get ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment