Android & iOS: collect the arguments from the `app_files` annotation
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 22 Jul 2016 01:53:29 +0000 (21:53 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 22 Jul 2016 14:20:04 +0000 (10:20 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

src/platform/app_annotations.nit

index 1d60f15..9cfdec9 100644 (file)
@@ -44,6 +44,9 @@ class AppProject
                return local_time_s.to_i
        end
 
+       # Extra folders where to find platform specific resource files
+       var files = new Array[String]
+
        private var modelbuilder: ModelBuilder
        private var mainmodule: MModule
 
@@ -64,6 +67,9 @@ class AppProject
                        if val != null then namespace = val
                end
 
+               var annots = modelbuilder.collect_annotations_on_modules("app_files", mainmodule)
+               for a in annots do files.add_all a.as_relative_paths(modelbuilder)
+
                modelbuilder.toolcontext.check_errors
        end
 
@@ -134,4 +140,29 @@ redef class AAnnotation
 
                return version_fields.join(".")
        end
+
+       # Parse all arguments as paths relative to the declaring module
+       #
+       # If no arguments are given, then use the parent directory of the module.
+       private fun as_relative_paths(modelbuilder: ModelBuilder): Array[String]
+       do
+               var paths = new Array[String]
+
+               var file = location.file
+               if file == null then return paths
+
+               var args = n_args
+               if args.is_empty then
+                       paths.add file.filename.dirname
+               else
+                       for arg in args do
+                               var val = arg.as_string
+                               if val != null then
+                                       paths.add file.filename.dirname/val
+                               else modelbuilder.error(arg, "Syntax Error: `app_files` expects String literals as arguments.")
+                       end
+               end
+
+               return paths
+       end
 end