diff --git a/source/dub/dub.d b/source/dub/dub.d index 1f487da..f0a8466 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -804,17 +804,10 @@ logDebug("Acquiring package zip file"); - auto clean_package_version = ver[ver.startsWith("~") ? 1 : 0 .. $]; - clean_package_version = clean_package_version.replace("+", "_"); // + has special meaning for Optlink - if (!placement.existsFile()) - mkdirRecurse(placement.toNativeString()); - NativePath dstpath = placement ~ (basePackageName ~ "-" ~ clean_package_version); + NativePath dstpath = PackageManager.getPackagePath(placement, basePackageName, ver); if (!dstpath.existsFile()) mkdirRecurse(dstpath.toNativeString()); - - // Support libraries typically used with git submodules like ae. - // Such libraries need to have ".." as import path but this can create - // import path leakage. + // For libraries leaking their import path dstpath = dstpath ~ basePackageName; import std.datetime : seconds; diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 2ef6d81..845f4ca 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -318,8 +318,12 @@ } string gitReference = versionSpec.chompPrefix("~"); - const destination = m_repositories[LocalPackageType.user].packagePath ~ - NativePath(name ~ "-" ~ gitReference) ~ (name~"/"); + NativePath destination = getPackagePath( + m_repositories[LocalPackageType.user].packagePath, + name, versionSpec); + // For libraries leaking their import path + destination ~= name; + destination.endsWithSlash = true; foreach (p; getPackageIterator(name)) { if (p.path == destination) { @@ -332,7 +336,26 @@ } return Package.load(destination); - } + } + + /** + * Get the final destination a specific package needs to be stored in. + * + * Note that there needs to be an extra level for libraries like `ae` + * which expects their containing folder to have an exact name and use + * `importPath "../"`. + * + * Hence the final format should be `$BASE/$NAME-$VERSION/$NAME`, + * but this function returns `$BASE/$NAME-$VERSION/` + */ + package(dub) static NativePath getPackagePath (NativePath base, string name, string vers) + { + // + has special meaning for Optlink + string clean_vers = vers.chompPrefix("~").replace("+", "_"); + NativePath result = base ~ (name ~ "-" ~ clean_vers); + result.endsWithSlash = true; + return result; + } /** Searches for the latest version of a package matching the given dependency. */