Skip to content

Commit

Permalink
Adapt getPackagePath to PackageName API
Browse files Browse the repository at this point in the history
Now that we have the PackageName type, we need to
go through API and decide what the string means.
Multiple places expect a main package, and only
some expect a subpackage. Starting from the bottom,
it is impossible to call getPackagePath with
a subpackage, as the package path of that subpackage
depends on the main package. However, we want to be
lax here, so always return the main package path.
  • Loading branch information
Geod24 committed Jan 17, 2024
1 parent 91ddb00 commit 4173f72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
27 changes: 20 additions & 7 deletions source/dub/packagemanager.d
Original file line number Diff line number Diff line change
Expand Up @@ -408,19 +408,20 @@ class PackageManager {
in { assert(!repo.empty); }
do {
Package pack;
const name_ = PackageName(name);

final switch (repo.kind)
{
case repo.Kind.git:
pack = loadGitPackage(name, repo);
pack = loadGitPackage(name_, repo);
}
if (pack !is null) {
addPackages(this.m_internal.fromPath, pack);
}
return pack;
}

private Package loadGitPackage(string name, in Repository repo)
private Package loadGitPackage(in PackageName name, in Repository repo)
{
import dub.internal.git : cloneRepository;

Expand Down Expand Up @@ -449,7 +450,7 @@ class PackageManager {
*
* See `Location.getPackagePath`.
*/
package(dub) NativePath getPackagePath (PlacementLocation base, string name, string vers)
package(dub) NativePath getPackagePath(PlacementLocation base, in PackageName name, string vers)
{
assert(this.m_repositories.length == 3, "getPackagePath called in bare mode");
return this.m_repositories[base].getPackagePath(name, vers);
Expand Down Expand Up @@ -721,7 +722,9 @@ class PackageManager {
*/
Package store(NativePath src, PlacementLocation dest, string name, Version vers)
{
NativePath dstpath = this.getPackagePath(dest, name, vers.toString());
const name_ = PackageName(name);
assert(!name_.sub.length, "Cannot store a subpackage, use main package instead");
NativePath dstpath = this.getPackagePath(dest, name_, vers.toString());
ensureDirectory(dstpath.parentPath());
const lockPath = dstpath.parentPath() ~ ".lock";

Expand Down Expand Up @@ -1437,7 +1440,7 @@ package struct Location {
return pkg;

string versStr = vers.toString();
const path = this.getPackagePath(name.main, versStr);
const path = this.getPackagePath(name, versStr);
if (!path.existsDirectory())
return null;

Expand All @@ -1460,10 +1463,20 @@ package struct Location {
*
* Hence the final format returned is `$BASE/$NAME/$VERSION/$NAME`,
* `$BASE` is `this.packagePath`.
*
* Params:
* name = The package name - if the name is that of a subpackage,
* only the path to the main package is returned, as the
* subpackage path can only be known after reading the recipe.
* vers = A version string. Typed as a string because git hashes
* can be used with this function.
*
* Returns:
* An absolute `NativePath` nested in this location.
*/
NativePath getPackagePath (string name, string vers)
NativePath getPackagePath (in PackageName name, string vers)
{
NativePath result = this.packagePath ~ name ~ vers ~ name;
NativePath result = this.packagePath ~ name.main ~ vers ~ name.main;
result.endsWithSlash = true;
return result;
}
Expand Down
3 changes: 2 additions & 1 deletion source/dub/test/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,9 @@ package class TestPackageManager : PackageManager
if (!repo.ref_.startsWith("~") && !repo.ref_.isGitHash)
return null;

const name_ = PackageName(name);
string gitReference = repo.ref_.chompPrefix("~");
NativePath destination = this.getPackagePath(PlacementLocation.user, name, repo.ref_);
NativePath destination = this.getPackagePath(PlacementLocation.user, name_, repo.ref_);

foreach (p; getPackageIterator(name))
if (p.path == destination)
Expand Down

0 comments on commit 4173f72

Please sign in to comment.