diff --git a/source/dub/dub.d b/source/dub/dub.d index 272ae21..7bdf349 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -415,7 +415,7 @@ void cleanPackage(Path path) { logInfo("Cleaning package at %s...", path.toNativeString()); - enforce(Package.isPackageAt(path), "No package found.", path.toNativeString()); + enforce(!Package.findPackageFile(path).empty, "No package found.", path.toNativeString()); // TODO: clear target files and copy files diff --git a/source/dub/package_.d b/source/dub/package_.d index d73e8d3..01da4cf 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -48,31 +48,30 @@ Package[] m_subPackages; Path[] m_exportedPackages; } - - static bool isPackageAt(Path path) + + static Path findPackageFile(Path path) { - foreach (f; packageInfoFilenames) - if (existsFile(path ~ f)) - return true; - return false; + foreach(f; packageInfoFilenames) { + auto filename = path ~ f; + if(existsFile(filename)) return filename; + } + return Path(); } - this(Path root, Package parent = null, string versionOverride = "") + this(Path root, Path infoFile = Path(), Package parent = null, string versionOverride = "") { - Json info; + Json info; + m_infoFile = infoFile; + try { - foreach (f; packageInfoFilenames) { - auto name = root ~ f; - if (existsFile(name)) { - m_infoFile = name; - info = jsonFromFile(m_infoFile); - break; - } + if(m_infoFile.empty) { + m_infoFile = findPackageFile(root); + if(m_infoFile.empty) throw new Exception("no package file was found, expected one of the following: "~to!string(packageInfoFilenames)); } + info = jsonFromFile(m_infoFile); } catch (Exception ex) throw new Exception(format("Failed to load package at %s: %s", root.toNativeString(), ex.msg)); - + enforce(info.type != Json.Type.undefined, format("Missing package description for package at %s", root.toNativeString())); - this(info, root, parent, versionOverride); } @@ -167,7 +166,7 @@ enforce(!p.absolute, "Sub package paths must not be absolute: " ~ sub.get!string); enforce(!p.startsWith(Path("..")), "Sub packages must be in a sub directory, not " ~ sub.get!string); m_exportedPackages ~= p; - if (!path.empty) m_subPackages ~= new Package(path ~ p, this, this.vers); + if (!path.empty) m_subPackages ~= new Package(path ~ p, Path(), this, this.vers); } else { m_subPackages ~= new Package(sub, root, this); } diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 3e9171e..82ab7e8 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -152,13 +152,13 @@ return null; } - Package getOrLoadPackage(Path path) + Package getOrLoadPackage(Path path, Path infoFile = Path()) { path.endsWithSlash = true; foreach (p; getPackageIterator()) if (!p.parentPackage && p.path == path) return p; - auto pack = new Package(path); + auto pack = new Package(path, infoFile); addPackages(m_temporaryPackages, pack); return pack; } @@ -355,7 +355,7 @@ logDiagnostic("%s file(s) copied.", to!string(countFiles)); // overwrite dub.json (this one includes a version field) - auto pack = new Package(destination, null, package_info["version"].get!string); + auto pack = new Package(destination, Path(), null, package_info["version"].get!string); if (pack.packageInfoFile.head != defaultPackageFilename()) { // Storeinfo saved a default file, this could be different to the file from the zip. @@ -554,7 +554,8 @@ } if (!pp) { - if (Package.isPackageAt(path)) pp = new Package(path); + Path infoFile = Package.findPackageFile(path); + if (!infoFile.empty) pp = new Package(path, infoFile); else { logWarn("Locally registered package %s %s was not found. Please run \"dub remove-local %s\".", name, ver, path.toNativeString()); @@ -594,7 +595,8 @@ logDebug("iterating dir %s entry %s", path.toNativeString(), pdir.name); if( !pdir.isDirectory ) continue; auto pack_path = path ~ (pdir.name ~ "/"); - if (!Package.isPackageAt(pack_path)) continue; + Path packageFile = Package.findPackageFile(pack_path); + if (packageFile.empty) continue; Package p; try { if (!refresh_existing_packages) @@ -603,7 +605,7 @@ p = pp; break; } - if (!p) p = new Package(pack_path); + if (!p) p = new Package(pack_path, packageFile); addPackages(m_packages, p); } catch( Exception e ){ logError("Failed to load package in %s: %s", pack_path, e.msg); @@ -724,7 +726,7 @@ } // Add the subpackage. try { - dst_repos ~= new Package(path, pack); + dst_repos ~= new Package(path, Path(), pack); } catch (Exception e) { logError("Package '%s': Failed to load sub-package in %s, error: %s", pack.name, path.toNativeString(), e.msg); logDiagnostic("Full error: %s", e.toString().sanitize()); diff --git a/source/dub/project.d b/source/dub/project.d index c2616cf..c9aad82 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -47,13 +47,14 @@ this(PackageManager package_manager, Path project_path) { Package pack; - if (!Package.isPackageAt(project_path)) { + Path packageFile = Package.findPackageFile(project_path); + if (packageFile.empty) { logWarn("There was no package description found for the application in '%s'.", project_path.toNativeString()); auto json = Json.emptyObject; json.name = "unknown"; pack = new Package(json, project_path); } else { - pack = package_manager.getOrLoadPackage(project_path); + pack = package_manager.getOrLoadPackage(project_path, packageFile); } this(package_manager, pack);