toolcontext: nit_dir tries another heuristic on PATH if procfs is not available
authorJean Privat <jean@pryen.org>
Sun, 2 Nov 2014 16:02:56 +0000 (11:02 -0500)
committerJean Privat <jean@pryen.org>
Mon, 3 Nov 2014 15:02:10 +0000 (10:02 -0500)
procfs (/proc/) does not exists on some system (macosx).
Therefore the heuristic used to find nit_dir will fail on those system
when the command is invoked from the PATH.

The solution is to add another heuristic, where the program_name is
manually searched inside the directories of PATH in order to find the
original directory.

Reported-by: Alexandre Blondin Massé <alexandre.blondin.masse@gmail.com>
Signed-off-by: Jean Privat <jean@pryen.org>

src/toolcontext.nit

index e174145..a443b0a 100644 (file)
@@ -422,6 +422,13 @@ The Nit language documentation and the source code of its tools and libraries ma
                        if res.file_exists and "{res}/src/nit.nit".file_exists then return res.simplify_path
                end
 
+               # search in the PATH
+               var ps = "PATH".environ.split(":")
+               for p in ps do
+                       res = p/".."
+                       if res.file_exists and "{res}/src/nit.nit".file_exists then return res.simplify_path
+               end
+
                return null
        end
 end