diff --git a/source/dub/package_.d b/source/dub/package_.d index 5b50a12..530d5f9 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -141,7 +141,17 @@ @property string name() const { - if (m_parentPackage) return m_parentPackage.name ~ ":" ~ m_info.name; + if (m_parentPackage) { + // HACK + if (m_parentPackage.path == m_path) + return m_parentPackage.name ~ ":" ~ m_info.name; + else { + enforce(m_path.startsWith(m_parentPackage.path)); + enforce(m_path.head.toString() == m_info.name, + "Subpackage name (" ~ m_info.name ~ ") is different than the path-head (" ~ m_path.head.toString() ~ "), this gets confusing."); + return m_parentPackage.name ~ "/" ~ m_path[m_parentPackage.path.length .. $].toString(); + } + } else return m_info.name; } @property string vers() const { return m_parentPackage ? m_parentPackage.vers : m_info.version_; } @@ -783,5 +793,5 @@ /// package itself, if it is already a full package. string getBasePackage(string package_name) { - return package_name.getSubPackagePath()[0]; + return (package_name.getSubPackagePath()[0]).split("/")[0]; } diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index d4ffaf5..d736542 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -120,9 +120,7 @@ foreach (p; getPackageIterator()) if (!p.basePackage && p.path == path) return p; - auto p = new Package(path); - m_temporaryPackages ~= p; - return p; + return addPackages(m_temporaryPackages, new Package(path)); } Package getBestPackage(string name, string version_spec) @@ -283,11 +281,7 @@ if( existsFile(destination~PackageJsonFilename) ) logInfo("%s is present with version %s", package_name, package_version); - auto pack = new Package(destination); - - m_packages ~= pack; - - return pack; + return addPackages(m_packages, new Package(destination)); } /// Removes the given the package. @@ -387,7 +381,7 @@ } } - *packs ~= pack; + addPackages(*packs, pack); writeLocalPackageList(type); @@ -429,9 +423,7 @@ if( "name" !in info ) info["name"] = path.head.toString(); info["version"] = ver.toString(); - auto pack = new Package(info, path); - m_temporaryPackages ~= pack; - return pack; + return addPackages(m_temporaryPackages, new Package(info, path)); } /// For the given type add another path where packages will be looked up. @@ -486,7 +478,7 @@ break; } if (!pp) pp = new Package(info, path); - packs ~= pp; + addPackages(packs, pp); } } catch( Exception e ){ logWarn("Error adding local package: %s", e.msg); @@ -522,7 +514,7 @@ break; } if (!p) p = new Package(pack_path); - m_packages ~= p; + addPackages(m_packages, p); } catch( Exception e ){ logError("Failed to load package in %s: %s", pack_path, e.msg); logDiagnostic("Full error: %s", e.toString().sanitize()); @@ -589,6 +581,38 @@ if( !existsDirectory(path) ) mkdirRecurse(path.toNativeString()); writeJsonFile(path ~ LocalPackagesFilename, Json(newlist)); } + + /// Adds the package and scans for subpackages. + private Package addPackages(ref Package[] dst_repos, Package pack) { + dst_repos ~= pack; + + void scanRecurse(Path directory) { + logDebug("- scanning for subpackages, dir %s", directory); + if (existsFile(directory ~ PackageJsonFilename) ) { + // Add the subpackage. + try { + dst_repos ~= new Package(directory, pack); + } catch( Exception e ){ + logError("Failed to load sub-package in %s: %s", directory, e.msg); + logDiagnostic("Full error: %s", e.toString().sanitize()); + } + } + try foreach( dir; iterateDirectory(directory) ){ + if( !dir.isDirectory ) continue; + scanRecurse(directory ~ dir.name); + } + catch(Exception e) logDiagnostic("Failed to scan %s sub-packages: %s", directory, e.toString()); + } + + try foreach( dir; iterateDirectory(pack.path) ){ + logDebug("scanning for subpackages, dir %s entry %s", pack.path.toNativeString(), dir.name); + if( !dir.isDirectory ) continue; + scanRecurse(pack.path ~ dir.name); + } + catch(Exception e) logDiagnostic("Failed to scan %s sub-packages: %s", pack.path.toNativeString(), e.toString()); + + return pack; + } }