Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt getPackagePath to PackageName API #2804

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading