import modelbuilder_base
import ini
-import picnit_shared
+import nitpm_shared
redef class ToolContext
# Option --path
# Setup the paths value
paths.append(toolcontext.opt_path.value)
- # Packages managed by picnit, only use when not testing with tests.sh
+ # Packages managed by nitpm, only use when not testing with tests.sh
if "NIT_TESTING_TESTS_SH".environ != "true" then
- paths.add picnit_lib_dir
+ paths.add nitpm_lib_dir
end
var path_env = "NIT_PATH".environ
end
end
+ if mgroup != null then
+ var alias = mgroup.mpackage.import_alias(name)
+ if alias != null then name = alias
+ end
+
var loc = null
if anode != null then loc = anode.hot_location
var candidate = search_module_in_paths(loc, name, lookpaths)
# If found, the module is returned.
private fun search_module_in_paths(location: nullable Location, name: String, lookpaths: Collection[String]): nullable MModule
do
+ var name_no_version
+ if name.has('=') then
+ name_no_version = name.split('=').first
+ else name_no_version = name
+
var res = new ArraySet[MModule]
for dirname in lookpaths do
# Try a single module file
var g = identify_group((dirname/name).simplify_path)
if g != null then
scan_group(g)
- res.add_all g.mmodules_by_name(name)
+ res.add_all g.mmodules_by_name(name_no_version)
end
end
if res.is_empty then return null
# Attach homonymous `ini` file to the package
var inipath = path.dirname / "{pn}.ini"
if inipath.file_exists then
- var ini = new ConfigTree(inipath)
+ var ini = new IniFile.from_file(inipath)
mpackage.ini = ini
end
end
var parent = null
var inipath = dirpath / "package.ini"
if inipath.file_exists then
- ini = new ConfigTree(inipath)
+ ini = new IniFile.from_file(inipath)
end
if ini == null then
# If no module yet, then assume that the first element of the path
# Is to be searched in the path.
var root_name = n_name.n_path.first.text
+
+ # Search for an alias in required external packages
+ if mgroup != null then
+ var alias = mgroup.mpackage.import_alias(root_name)
+ if alias != null then root_name = alias
+ end
+
var roots = search_group_in_paths(root_name, paths)
if roots.is_empty then
error(n_name, "Error: cannot find `{root_name}`. Tried: {paths.join(", ")}.")
# The `ini` file is given as is and might contain invalid or missing information.
#
# Some packages, like stand-alone packages or virtual packages have no `ini` file associated.
- var ini: nullable ConfigTree = null
+ var ini: nullable IniFile = null
# Array of relative source paths excluded according to the `source.exclude` key of the `ini`
var excludes: nullable Array[String] is lazy do
end
return true
end
+
+ # Get the name to search for, for a `root_name` declared as `import` in `ini`
+ fun import_alias(root_name: String): nullable String
+ do
+ var map = import_aliases_parsed
+ if map == null then return null
+
+ var val = map.get_or_null(root_name)
+ if val == null then return null
+
+ return val.dir_name
+ end
+
+ private var import_aliases_parsed: nullable Map[String, ExternalPackage] is lazy do
+ var ini = ini
+ if ini == null then return null
+
+ var import_line = ini["package.import"]
+ if import_line == null then return null
+
+ var map = import_line.parse_import
+ if map.is_empty then return null
+
+ return map
+ end
end
redef class MGroup