loader: get_mgroup check and assign the `project.ini` file to projects
[nit.git] / src / loader.nit
index d3c9f7e..90c439f 100644 (file)
@@ -18,6 +18,7 @@
 module loader
 
 import modelbuilder_base
+import ini
 
 redef class ToolContext
        # Option --path
@@ -351,7 +352,7 @@ redef class ModelBuilder
                        mgroup = new MGroup(pn, mproject, null) # same name for the root group
                        mgroup.filepath = path
                        mproject.root = mgroup
-                       toolcontext.info("found project `{pn}` at {path}", 2)
+                       toolcontext.info("found singleton project `{pn}` at {path}", 2)
                end
 
                var res = new ModulePath(pn, path, mgroup)
@@ -387,6 +388,13 @@ redef class ModelBuilder
                        return mgroups[rdp]
                end
 
+               # Filter out non-directories
+               var stat = dirpath.file_stat
+               if stat == null or not stat.is_dir then
+                       mgroups[rdp] = null
+                       return null
+               end
+
                # Hack, a group is determined by one of the following:
                # * the presence of a honomymous nit file
                # * the fact that the directory is named `src`
@@ -394,6 +402,14 @@ redef class ModelBuilder
                var pn = rdp.basename(".nit")
                var mp = dirpath.join_path(pn + ".nit").simplify_path
 
+               # Check `project.ini` that indicate a project
+               var ini = null
+               var parent = null
+               var inipath = dirpath / "project.ini"
+               if inipath.file_exists then
+                       ini = new ConfigTree(inipath)
+               end
+
                # dirpath2 is the root directory
                # dirpath is the src subdirectory directory, if any, else it is the same that dirpath2
                var dirpath2 = dirpath
@@ -419,10 +435,12 @@ redef class ModelBuilder
                var mgroup
                if parent == null then
                        # no parent, thus new project
+                       if ini != null and ini.has_key("name") then pn = ini["name"]
                        var mproject = new MProject(pn, model)
                        mgroup = new MGroup(pn, mproject, null) # same name for the root group
                        mproject.root = mgroup
                        toolcontext.info("found project `{mproject}` at {dirpath}", 2)
+                       mproject.ini = ini
                else
                        mgroup = new MGroup(pn, parent.mproject, parent)
                        toolcontext.info("found sub group `{mgroup.full_name}` at {dirpath}", 2)
@@ -918,6 +936,15 @@ class ModulePath
        redef fun to_s do return filepath
 end
 
+redef class MProject
+       # The associated `.ini` file, if any
+       #
+       # The `ini` file is given as is and might contain invalid or missing information.
+       #
+       # Some projects, like stand-alone projects or virtual projects have no `ini` file associated.
+       var ini: nullable ConfigTree = null
+end
+
 redef class MGroup
        # Modules paths associated with the group
        var module_paths = new Array[ModulePath]