modelbuilder: a directory named `src` triggers more heuristics
authorJean Privat <jean@pryen.org>
Tue, 22 Apr 2014 20:28:23 +0000 (16:28 -0400)
committerJean Privat <jean@pryen.org>
Fri, 25 Apr 2014 02:29:20 +0000 (22:29 -0400)
A MGroup is determined by the fact that a directory is named `src`
Thus, current project that put their module in a src directory can be
correctly identified as MProject

~~~
$ nitls src/nit*.nit examples/mnit_dino/src/*.nit -t
mnit_dino (examples/mnit_dino/src)
|--dino (examples/mnit_dino/src/dino.nit)
|--dino_android (examples/mnit_dino/src/dino_android.nit)
|--dino_linux (examples/mnit_dino/src/dino_linux.nit)
|--fancy_dino (examples/mnit_dino/src/fancy_dino.nit)
|--game_logic (examples/mnit_dino/src/game_logic.nit)
|--graphism (examples/mnit_dino/src/graphism.nit)
`--splash (examples/mnit_dino/src/splash.nit)
nit (src)
|--nit (src/nit.nit)
|--nit_version (src/nit_version.nit)
|--nitdbg_client (src/nitdbg_client.nit)
|--nitdbg_server (src/nitdbg_server.nit)
|--nitdbg_websocket_server (src/nitdbg_websocket_server.nit)
|--nitdoc (src/nitdoc.nit)
|--nitg (src/nitg.nit)
|--nitlight (src/nitlight.nit)
|--nitls (src/nitls.nit)
|--nitmetrics (src/nitmetrics.nit)
|--nitunit (src/nitunit.nit)
`--nitx (src/nitx.nit)
~~~

Signed-off-by: Jean Privat <jean@pryen.org>

src/modelbuilder.nit

index 8b6f6e9..7ccbfa4 100644 (file)
@@ -468,11 +468,20 @@ class ModelBuilder
                        return mgroups[rdp]
                end
 
-               # Hack, a dir is determined by the presence of a honomymous nit file
+               # Hack, a group is determined by:
+               # * the presence of a honomymous nit file
+               # * the fact that the directory is named `src`
                var pn = rdp.basename(".nit")
                var mp = dirpath.join_path(pn + ".nit").simplify_path
 
-               if not mp.file_exists then return null
+               if not mp.file_exists then
+                       if pn == "src" then
+                               # With a src directory, the group name is the name of the parent directory
+                               pn = rdp.dirname.basename("")
+                       else
+                               return null
+                       end
+               end
 
                # check parent directory
                var parentpath = dirpath.join_path("..").simplify_path