[vala: 2/2] compiler: Add --gresourcesdir option



commit a667b82aab0fecb6f932de54ddfd0a577e3f8cd7
Author: Daniel Espinosa <esodan gmail com>
Date:   Fri May 26 13:42:55 2017 -0500

    compiler: Add --gresourcesdir option
    
    In case a gresources.xml is located in a different directory than its
    corresponding resources, --gresourcesdir will add additional search
    locations for UI files of Gtk+ templates.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=783133

 codegen/valagtkmodule.vala |    6 +++---
 compiler/valacompiler.vala |    6 +++++-
 doc/valac.1                |    3 +++
 vala/valacodecontext.vala  |   10 ++++++++++
 4 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valagtkmodule.vala b/codegen/valagtkmodule.vala
index 85b648a..5d87870 100644
--- a/codegen/valagtkmodule.vala
+++ b/codegen/valagtkmodule.vala
@@ -65,7 +65,7 @@ public class Vala.GtkModule : GSignalModule {
                                Report.error (null, "GResources file `%s' does not exist".printf (gresource));
                                continue;
                        }
-                       var gresource_dir = Path.get_dirname (gresource);
+
                        MarkupReader reader = new MarkupReader (gresource);
 
                        int state = 0;
@@ -81,7 +81,7 @@ public class Vala.GtkModule : GSignalModule {
                                        state = 1;
                                } else if (state == 1 && current_token == MarkupTokenType.TEXT) {
                                        var name = reader.content;
-                                       var filename = Path.build_filename (gresource_dir, name);
+                                       var filename = context.get_gresource_path (gresource, name);
                                        if (alias != null) {
                                                gresource_to_file_map.set (Path.build_filename (prefix, 
alias), filename);
                                        }
@@ -104,7 +104,7 @@ public class Vala.GtkModule : GSignalModule {
                var ui_file = gresource_to_file_map.get (ui_resource);
                if (ui_file == null || !FileUtils.test (ui_file, FileTest.EXISTS)) {
                        node.error = true;
-                       Report.error (node.source_reference, "UI resource not found: `%s'. Please make sure 
to specify the proper GResources xml files with --gresources.".printf (ui_resource));
+                       Report.error (node.source_reference, "UI resource not found: `%s'. Please make sure 
to specify the proper GResources xml files with --gresources and alternative search locations with 
--gresourcesdir.".printf (ui_resource));
                        return;
                }
                current_handler_to_signal_map = new HashMap<string, Signal>(str_hash, str_equal);
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index d2d3997..8a87525 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -49,6 +49,8 @@ class Vala.Compiler {
        static string target_glib;
        [CCode (array_length = false, array_null_terminated = true)]
        static string[] gresources;
+       [CCode (array_length = false, array_null_terminated = true)]
+       static string[] gresources_directories;
 
        static bool ccode_only;
        static string header_filename;
@@ -151,7 +153,8 @@ class Vala.Compiler {
                { "no-color", 0, 0, OptionArg.NONE, ref disable_colored_output, "Disable colored output, 
alias for --color=never", null },
                { "color", 0, OptionFlags.OPTIONAL_ARG, OptionArg.CALLBACK, (void*) option_parse_color, 
"Enable color output, options are 'always', 'never', or 'auto'", "WHEN" },
                { "target-glib", 0, 0, OptionArg.STRING, ref target_glib, "Target version of glib for code 
generation", "MAJOR.MINOR" },
-               { "gresources", 0, 0, OptionArg.STRING_ARRAY, ref gresources, "XML of gresources", "FILE..." 
},
+               { "gresources", 0, 0, OptionArg.FILENAME_ARRAY, ref gresources, "XML of gresources", 
"FILE..." },
+               { "gresourcesdir", 0, 0, OptionArg.FILENAME_ARRAY, ref gresources_directories, "Look for 
resources in DIRECTORY", "DIRECTORY..." },
                { "enable-version-header", 0, 0, OptionArg.NONE, ref enable_version_header, "Write vala build 
version in generated files", null },
                { "disable-version-header", 0, 0, OptionArg.NONE, ref disable_version_header, "Do not write 
vala build version in generated files", null },
                { "", 0, 0, OptionArg.FILENAME_ARRAY, ref sources, null, "FILE..." },
@@ -327,6 +330,7 @@ class Vala.Compiler {
                }
 
                context.gresources = gresources;
+               context.gresources_directories = gresources_directories;
 
                if (context.report.get_errors () > 0 || (fatal_warnings && context.report.get_warnings () > 
0)) {
                        return quit ();
diff --git a/doc/valac.1 b/doc/valac.1
index db2f4e5..65402fb 100644
--- a/doc/valac.1
+++ b/doc/valac.1
@@ -188,6 +188,9 @@ Target version of glib for code generation
 \fB\-\-gresources\fR=\fI\,FILE\/\fR...
 XML of gresources
 .TP
+\fB\-\-gresourcesdir\fR=\fI\,DIRECTORY\/\fR...
+Look for resources in DIRECTORY
+.TP
 \fB\-\-enable\-version\-header\fR
 Write vala build version in generated files
 .TP
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala
index 4484c05..7815c0a 100644
--- a/vala/valacodecontext.vala
+++ b/vala/valacodecontext.vala
@@ -200,6 +200,8 @@ public class Vala.CodeContext {
 
        public string[] gresources;
 
+       public string[] gresources_directories;
+
        private List<SourceFile> source_files = new ArrayList<SourceFile> ();
        private List<string> c_source_files = new ArrayList<string> ();
        private Namespace _root = new Namespace (null);
@@ -517,6 +519,14 @@ public class Vala.CodeContext {
                return get_file_path (gir + ".gir", "gir-1.0", null, gir_directories);
        }
 
+       public string? get_gresource_path (string gresource, string resource) {
+               var filename = get_file_path (resource, null, null, { Path.get_dirname (gresource) });
+               if (filename == null) {
+                       filename = get_file_path (resource, null, null, gresources_directories);
+               }
+               return filename;
+       }
+
        /*
         * Returns the .metadata file associated with the given .gir file.
         */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]