From: Alexandre Terrasa Date: Mon, 9 Sep 2013 17:52:53 +0000 (-0400) Subject: nitg: fixed conflicting module error when env var NIT_DIR is specified and compiling... X-Git-Tag: v0.6.2~30^2 X-Git-Url: http://nitlanguage.org nitg: fixed conflicting module error when env var NIT_DIR is specified and compiling in /bin Fixes issue #68: NIT_DIR env var creates module conflicts when compiling in /nit dir With NIT_DIR env var setted to /home/ME/nit/, when I compile from /nit/bin like: nitg something.nit I get a compile error saying that there is a module conflict between /home/ME/nit/lib/module1.nit and ../lib/module1.nit. Signed-off-by: Alexandre Terrasa --- diff --git a/src/modelbuilder.nit b/src/modelbuilder.nit index bc41e2a..25a98ef 100644 --- a/src/modelbuilder.nit +++ b/src/modelbuilder.nit @@ -316,7 +316,12 @@ class ModelBuilder if candidate == null then candidate = try_file else if candidate != try_file then - error(anode, "Error: conflicting module file for {name}: {candidate} {try_file}") + # try to disambiguate conflicting modules + var abs_candidate = module_absolute_path(candidate) + var abs_try_file = module_absolute_path(try_file) + if abs_candidate != abs_try_file then + error(anode, "Error: conflicting module file for {name}: {candidate} {try_file}") + end end end try_file = (dirname + "/" + name + "/" + name + ".nit").simplify_path @@ -324,7 +329,12 @@ class ModelBuilder if candidate == null then candidate = try_file else if candidate != try_file then - error(anode, "Error: conflicting module file for {name}: {candidate} {try_file}") + # try to disambiguate conflicting modules + var abs_candidate = module_absolute_path(candidate) + var abs_try_file = module_absolute_path(try_file) + if abs_candidate != abs_try_file then + error(anode, "Error: conflicting module file for {name}: {candidate} {try_file}") + end end end end @@ -341,6 +351,14 @@ class ModelBuilder return res.mmodule.as(not null) end + # Transform relative paths (starting with '../') into absolute paths + private fun module_absolute_path(path: String): String do + if path.has_prefix("..") then + return getcwd.join_path(path).simplify_path + end + return path + end + # Try to load a module using a path. # Display an error if there is a problem (IO / lexer / parser) and return null # Note: usually, you do not need this method, use `get_mmodule_by_name` instead. diff --git a/tests/tests.sh b/tests/tests.sh index 3ea9dca..9f505b6 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -21,6 +21,8 @@ export LANG=C export NIT_TESTING=true +unset NIT_DIR + usage() { e=`basename "$0"`