Merge: Honor `source.exclude` in ini files
authorJean Privat <jean@pryen.org>
Sun, 5 Jun 2016 16:10:23 +0000 (12:10 -0400)
committerJean Privat <jean@pryen.org>
Sun, 5 Jun 2016 16:10:23 +0000 (12:10 -0400)
`source.exclude` is used in very specific cases to prevent some .nit file of directory to belong to a package.

This means two things:
* when the loader is scanning/loading a full package or group, and finds an excluded group or module, then the excluded entity will be not included in the package (and not scanned/loaded)
* when the loader is explicitly requested to load an excluded entity, then it will be detached from the parent package. The excluded modules will be considered as standalone modules.

Pull-Request: #2160
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

14 files changed:
contrib/pep8analysis/package.ini
src/loader.nit
src/modelbuilder_base.nit
src/package.ini
tests/nitls.args
tests/nitpick.args
tests/sav/nitdoc_args4.res
tests/sav/nitls_args7.res [new file with mode: 0644]
tests/sav/nitls_args8.res [new file with mode: 0644]
tests/sav/test_neo_args1.res
tests/sav/test_sort_perf_args1.res
tests/test_prog/game/excluded.nit [new file with mode: 0644]
tests/test_prog/game/excluded_dir/more.nit [new file with mode: 0644]
tests/test_prog/package.ini

index 43d5e4a..bbf3802 100644 (file)
@@ -3,6 +3,8 @@ name=pep8analysis
 tags=educ,web,cli
 maintainer=Alexis Laferrière <alexis.laf@xymus.net>
 license=Apache-2.0
+[source]
+exclude=src/parser/parser_abs.nit
 [upstream]
 browse=https://github.com/nitlang/nit/tree/master/contrib/pep8analysis/
 git=https://github.com/nitlang/nit.git
index 967d335..d1a4ce5 100644 (file)
@@ -379,6 +379,13 @@ redef class ModelBuilder
                var mgrouppath = path.join_path("..").simplify_path
                var mgroup = identify_group(mgrouppath)
 
+               if mgroup != null then
+                       var mpackage = mgroup.mpackage
+                       if not mpackage.accept(path) then
+                               mgroup = null
+                               toolcontext.info("module `{path}` excluded from package `{mpackage}`", 2)
+                       end
+               end
                if mgroup == null then
                        # singleton package
                        var loc = new Location.opaque_file(path)
@@ -473,6 +480,13 @@ redef class ModelBuilder
                        if not stopper.file_exists then
                                # Recursively get the parent group
                                parent = identify_group(parentpath)
+                               if parent != null then do
+                                       var mpackage = parent.mpackage
+                                       if not mpackage.accept(dirpath) then
+                                               toolcontext.info("directory `{dirpath}` excluded from package `{mpackage}`", 2)
+                                               parent = null
+                                       end
+                               end
                                if parent == null then
                                        # Parent is not a group, thus we are not a group either
                                        mgroups[rdp] = null
@@ -1064,6 +1078,27 @@ redef class MPackage
        #
        # Some packages, like stand-alone packages or virtual packages have no `ini` file associated.
        var ini: nullable ConfigTree = null
+
+       # Array of relative source paths excluded according to the `source.exclude` key of the `ini`
+       var excludes: nullable Array[String] is lazy do
+               var ini = self.ini
+               if ini == null then return null
+               var exclude = ini["source.exclude"]
+               if exclude == null then return null
+               var excludes = exclude.split(":")
+               return excludes
+       end
+
+       # Does the source inclusion/inclusion rules of the package `ini` accept such path?
+       fun accept(filepath: String): Bool
+       do
+               var excludes = self.excludes
+               if excludes != null then
+                       var relpath = root.filepath.relpath(filepath)
+                       if excludes.has(relpath) then return false
+               end
+               return true
+       end
 end
 
 redef class MGroup
index 85bb115..5cc235f 100644 (file)
@@ -348,6 +348,12 @@ class ModelBuilder
                var name = qid.n_id.text
                var qname = qid.full_name
 
+               if bad_class_names[mmodule].has(qname) then
+                       error(qid, "Error: class `{qname}` not found in module `{mmodule}`.")
+                       return
+               end
+               bad_class_names[mmodule].add(qname)
+
                var all_classes = model.get_mclasses_by_name(name)
                var hints = new Array[String]
 
@@ -404,6 +410,10 @@ class ModelBuilder
                error(qid, "Error: class `{qname}` not found in module `{mmodule}`.")
        end
 
+       # List of already reported bad class names.
+       # Used to not perform and repeat hints again and again.
+       private var bad_class_names = new MultiHashMap[MModule, String]
+
        # Return the static type associated to the node `ntype`.
        # `mmodule` and `mclassdef` is the context where the call is made (used to understand formal types)
        # In case of problem, an error is displayed on `ntype` and null is returned.
index 292ff28..c7dae85 100644 (file)
@@ -3,6 +3,8 @@ name=nitc
 tags=devel,cli
 maintainer=Jean Privat <jean@pryen.org>
 license=Apache-2.0
+[source]
+exclude=parser/parser_abs.nit:parser/.parser-nofact.nit
 [upstream]
 browse=https://github.com/nitlang/nit/tree/master/src
 git=https://github.com/nitlang/nit.git
index 568f76a..e79a1e1 100644 (file)
@@ -4,3 +4,5 @@ base_simple3.nit project1
 -s base_simple3.nit project1
 -M base_simple3.nit base_simple_import.nit
 -td project1/module3.nit
+test_prog --no-color
+test_prog/game/excluded.nit test_prog/game/excluded_dir/more.nit -t --no-color
index 396ac26..1ef81d1 100644 (file)
@@ -1,3 +1,4 @@
 --no-color -W test_advice_repeated_types.nit
 --no-color base_simple3.nit; echo $?
 --no-color error_mod_unk.nit; echo $?
+--no-color test_prog
index 01782ba..9238b51 100644 (file)
@@ -1,8 +1,35 @@
+Empty README for group `excluded` (readme-warning)
+Errors: 0. Warnings: 1.
+MGroupPage excluded
+       # excluded.section
+               ## excluded.intro
+               ## excluded.concerns
+               ## excluded.concern
+               ## excluded.concern
+               ## excluded-.concern
+                       ### excluded-.definition
+                               #### excluded-.intros_redefs
+                                       ##### list.group
+                                               ###### excluded-.intros
+                                               ###### excluded-.redefs
+
+MModulePage excluded
+       # excluded.section
+               ## excluded-.intro
+               ## excluded-.importation
+                       ### excluded-.graph
+                       ### list.group
+                               #### excluded-.imports
+                               #### excluded-.clients
+
 OverviewPage Overview
        # home.article
                ## packages.section
+                       ### excluded.definition
                        ### test_prog.definition
 
+ReadmePage excluded
+
 ReadmePage test_prog
        # mdarticle-0
 
@@ -1007,24 +1034,24 @@ MModulePage rpg
                                #### test_prog__rpg__rpg.imports
                                #### test_prog__rpg__rpg.clients
 
-Generated 96 pages
+Generated 99 pages
  list:
-  MPropertyPage: 58 (60.41%)
-  MClassPage: 20 (20.83%)
-  MModulePage: 8 (8.33%)
-  MGroupPage: 4 (4.16%)
-  ReadmePage: 4 (4.16%)
-  SearchPage: 1 (1.04%)
-  OverviewPage: 1 (1.04%)
-Found 182 mentities
+  MPropertyPage: 58 (58.58%)
+  MClassPage: 20 (20.20%)
+  MModulePage: 9 (9.09%)
+  ReadmePage: 5 (5.05%)
+  MGroupPage: 5 (5.05%)
+  SearchPage: 1 (1.01%)
+  OverviewPage: 1 (1.01%)
+Found 185 mentities
  list:
-  MMethodDef: 68 (37.36%)
-  MMethod: 57 (31.31%)
-  MClassDef: 22 (12.08%)
-  MClass: 20 (10.98%)
-  MModule: 8 (4.39%)
-  MGroup: 4 (2.19%)
+  MMethodDef: 68 (36.75%)
+  MMethod: 57 (30.81%)
+  MClassDef: 22 (11.89%)
+  MClass: 20 (10.81%)
+  MModule: 9 (4.86%)
+  MGroup: 5 (2.70%)
+  MPackage: 2 (1.08%)
   MVirtualTypeDef: 1 (0.54%)
   MVirtualTypeProp: 1 (0.54%)
-  MPackage: 1 (0.54%)
 quicksearch-list.js
diff --git a/tests/sav/nitls_args7.res b/tests/sav/nitls_args7.res
new file mode 100644 (file)
index 0000000..a0a686e
--- /dev/null
@@ -0,0 +1,12 @@
+test_prog: Test program for model tools. (test_prog)
+|--game: Gaming group (test_prog/game)
+|  `--\e[1mgame\e[m: A game abstraction for RPG. (test_prog/game/game.nit)
+|--platform: Fictive Crappy Platform. (test_prog/platform)
+|  `--\e[1mplatform\e[m: Declares base types allowed on the platform. (test_prog/platform/platform.nit)
+|--rpg: Role Playing Game group (test_prog/rpg)
+|  |--\e[1mcareers\e[m: Careers of the game. (test_prog/rpg/careers.nit)
+|  |--\e[1mcharacter\e[m: Characters are playable entity in the world. (test_prog/rpg/character.nit)
+|  |--\e[1mcombat\e[m: COmbat interactions between characters. (test_prog/rpg/combat.nit)
+|  |--\e[1mraces\e[m: Races of the game. (test_prog/rpg/races.nit)
+|  `--\e[1mrpg\e[m: A worlg RPG abstraction. (test_prog/rpg/rpg.nit)
+`--\e[1mtest_prog\e[m: A test program with a fake model to check model tools. (test_prog/test_prog.nit)
diff --git a/tests/sav/nitls_args8.res b/tests/sav/nitls_args8.res
new file mode 100644 (file)
index 0000000..b80e7ce
--- /dev/null
@@ -0,0 +1,2 @@
+\e[1mexcluded\e[m (test_prog/game/excluded.nit)
+\e[1mmore\e[m (test_prog/game/excluded_dir/more.nit)
index 4ac86da..fdc3be7 100644 (file)
@@ -1,12 +1,12 @@
 # mpackages:
-test_prog
+excluded test_prog
 ------------------------------------
-test_prog
+excluded test_prog
 
 # mmodules:
-careers character combat game platform races rpg test_prog
+careers character combat excluded game platform races rpg test_prog
 ------------------------------------
-careers character combat game platform races rpg test_prog
+careers character combat excluded game platform races rpg test_prog
 
 # mclasses:
 Alcoholic Bool Career Character Combatable Dwarf Elf Float Game Human Int List Magician Object Race Starter String Sys Warrior Weapon
index 01532de..b1fe714 100644 (file)
@@ -2,6 +2,9 @@ test_prog/
 |--test_prog/README.md
 |--test_prog/game
 |  |--test_prog/game/README.md
+|  |--test_prog/game/excluded.nit
+|  |--test_prog/game/excluded_dir
+|  |  `--test_prog/game/excluded_dir/more.nit
 |  `--test_prog/game/game.nit
 |--test_prog/package.ini
 |--test_prog/platform
diff --git a/tests/test_prog/game/excluded.nit b/tests/test_prog/game/excluded.nit
new file mode 100644 (file)
index 0000000..d296d4b
--- /dev/null
@@ -0,0 +1 @@
+This is not a valid Nit program
diff --git a/tests/test_prog/game/excluded_dir/more.nit b/tests/test_prog/game/excluded_dir/more.nit
new file mode 100644 (file)
index 0000000..d296d4b
--- /dev/null
@@ -0,0 +1 @@
+This is not a valid Nit program
index ff4b70d..bfcd472 100644 (file)
@@ -5,6 +5,8 @@ tags=test,game
 maintainer=John Doe <jdoe@example.com> (http://www.example.com/~jdoe), Spider-Man
 more_contributors=Riri <riri@example.com>, Fifi (http://www.example.com/~fifi), Loulou
 license=Apache-2.0
+[source]
+exclude=game/excluded.nit:game/excluded_dir
 [upstream]
 browse=https://github.com/nitlang/nit/tree/master/tests/test_prog
 git=https://github.com/nitlang/nit.git