[vala/0.36: 24/212] compiler: Add --gresourcesdir option



commit 8f5aa8ea96d2e79bf20860858a71d621af4b67c0
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 1558469..85ef537 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 0108b70..4c4b5fd 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;
@@ -149,7 +151,8 @@ class Vala.Compiler {
                { "verbose", 'v', 0, OptionArg.NONE, ref verbose_mode, "Print additional messages to the 
console", null },
                { "no-color", 0, 0, OptionArg.NONE, ref disable_diagnostic_colors, "Disable colored output", 
null },
                { "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..." },
@@ -310,6 +313,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 0e94552..bf5ebce 100644
--- a/doc/valac.1
+++ b/doc/valac.1
@@ -180,6 +180,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]