diff --git a/source/dub/dub.d b/source/dub/dub.d index 7d509ca3f..3940dbb3b 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -447,7 +447,8 @@ class Dub { /// Loads a specific package as the main project package (can be a sub package) void loadPackage(Package pack) { - m_project = new Project(m_packageManager, pack); + auto selections = Project.loadSelections(pack); + m_project = new Project(m_packageManager, pack, selections); } /** Loads a single file package. diff --git a/source/dub/project.d b/source/dub/project.d index 5abfd4571..99eecc16d 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -71,23 +71,41 @@ class Project { this(package_manager, pack); } - /// ditto + /// Ditto this(PackageManager package_manager, Package pack) + { + auto selections = Project.loadSelections(pack); + this(package_manager, pack, selections); + } + + /// ditto + this(PackageManager package_manager, Package pack, SelectedVersions selections) { m_packageManager = package_manager; m_rootPackage = pack; + m_selections = selections; + reinit(); + } - auto selverfile = (m_rootPackage.path ~ SelectedVersions.defaultFile).toNativeString(); - if (existsFile(selverfile)) { - // TODO: Remove `StrictMode.Warn` after v1.40 release - // The default is to error, but as the previous parser wasn't - // complaining, we should first warn the user. - auto selected = parseConfigFileSimple!Selected(selverfile, StrictMode.Warn); - m_selections = !selected.isNull() ? - new SelectedVersions(selected.get()) : new SelectedVersions(); - } else m_selections = new SelectedVersions; + /// + static package SelectedVersions loadSelections(Package pack) + { + auto selverfile = (pack.path ~ SelectedVersions.defaultFile).toNativeString(); - reinit(); + // No file exists + if (!existsFile(selverfile)) + return new SelectedVersions(); + + // TODO: Remove `StrictMode.Warn` after v1.40 release + // The default is to error, but as the previous parser wasn't + // complaining, we should first warn the user. + auto selected = parseConfigFileSimple!Selected(selverfile, StrictMode.Warn); + + // Parsing error, it will be displayed to the user + if (selected.isNull()) + return new SelectedVersions(); + + return new SelectedVersions(selected.get()); } /** List of all resolved dependencies.