end
var nit_dir = toolcontext.nit_dir
- var libname = nit_dir/"lib"
- if libname.file_exists then paths.add(libname)
- libname = nit_dir/"contrib"
- if libname.file_exists then paths.add(libname)
+ if nit_dir != null then
+ var libname = nit_dir/"lib"
+ if libname.file_exists then paths.add(libname)
+ libname = nit_dir/"contrib"
+ if libname.file_exists then paths.add(libname)
+ end
end
# Load a bunch of modules.
exit 1
end
- nit_dir = compute_nit_dir
+ nit_dir = locate_nit_dir
if option_context.rest.is_empty and not accept_no_arguments then
print tooldescription
end
# The identified root directory of the Nit package
- var nit_dir: String is noinit
+ #
+ # It is assignable but is automatically set by `process_options` with `locate_nit_dir`.
+ var nit_dir: nullable String = null is writable
# Shared files directory.
#
return sharedir
end
- private fun compute_nit_dir: String
+ # Guess a possible nit_dir.
+ #
+ # It uses, in order:
+ #
+ # * the option `opt_no_color`
+ # * the environment variable `NIT_DIR`
+ # * the runpath of the program from argv[0]
+ # * the runpath of the process from /proc
+ # * the search in PATH
+ #
+ # If there is errors (e.g. the indicated path is invalid) or if no
+ # path is found, then an error is displayed and the program exits.
+ #
+ # The result is returned without being assigned to `nit_dir`.
+ # This function is automatically called by `process_options`
+ fun locate_nit_dir: String
do
# the option has precedence
var res = opt_nit_dir.value