From 9b6c23b28091f4f3bb8fa22415e412c8cd4f16e7 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Fri, 1 Nov 2024 04:09:48 +0100 Subject: [PATCH] [take 2 - fix PackageManager instead] --- source/dub/packagemanager.d | 34 +++++++++++++++++++++++++++------- source/dub/project.d | 11 ++++------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 79029cc4b..66c527635 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -523,10 +523,9 @@ class PackageManager { } else if (!this.gitClone(repo.remote, gitReference, destination)) return null; - Package result = this.load(destination); - if (result !is null) - this.addPackages(this.m_internal.fromPath, result); - return result; + Package p = this.load(destination); + if (p is null) return null; + return this.addPackagesAndResolveSubPackage(this.m_internal.fromPath, p, name); } /** @@ -1323,6 +1322,28 @@ symlink_exit: } } } + + /// Adds the package, scans for sub-packages, and returns the added package matching + /// the specified name (of the package itself or a sub-package). + /// Returns null if the sub-package doesn't exist. + private Package addPackagesAndResolveSubPackage(ref Package[] dst_repos, Package pack, + in PackageName nameToResolve) + in(pack.name == nameToResolve.main.toString(), + "nameToResolve must be the added package or one of its sub-packages") + { + this.addPackages(dst_repos, pack); + + if (nameToResolve.sub.empty) + return pack; + + // available sub-packages have been appended + foreach_reverse (sp; dst_repos) { + if (sp.parentPackage is pack && sp.name == nameToResolve.toString()) + return sp; + } + + return null; + } } deprecated(OverrideDepMsg) @@ -1742,9 +1763,8 @@ package struct Location { enforce( p.version_ == vers, format("Package %s located in %s has a different version than its path: Got %s, expected %s", - name, path, p.version_, vers)); - mgr.addPackages(this.fromPath, p); - return p; + name.main, path, p.version_, vers)); + return mgr.addPackagesAndResolveSubPackage(this.fromPath, p, name); } /** diff --git a/source/dub/project.d b/source/dub/project.d index 065c9b8ed..f2496378a 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -557,14 +557,12 @@ class Project { return resolveSubPackage(tmp, subname, true); }, (Repository repo) { - auto tmp = m_packageManager.loadSCMPackage(basename, repo); - return resolveSubPackage(tmp, subname, true); + return m_packageManager.loadSCMPackage(dep.name, repo); }, (VersionRange range) { // See `dub.recipe.selection : SelectedDependency.fromYAML` assert(range.isExactVersion()); - auto tmp = m_packageManager.getPackage(basename, vspec.version_); - return resolveSubPackage(tmp, subname, true); + return m_packageManager.getPackage(dep.name, vspec.version_); }, ); } else if (m_dependencies.canFind!(d => PackageName(d.name).main == basename)) { @@ -581,11 +579,10 @@ class Project { if (p is null) { if (!vspec.repository.empty) { - p = m_packageManager.loadSCMPackage(basename, vspec.repository); + p = m_packageManager.loadSCMPackage(dep.name, vspec.repository); enforce(p !is null, "Unable to fetch '%s@%s' using git - does the repository and version exist?".format( - basename, vspec.repository)); - p = resolveSubPackage(p, subname, false); + dep.name, vspec.repository)); } else if (!vspec.path.empty && is_desired) { NativePath path = vspec.path; if (!path.absolute) path = pack.path ~ path;