diff --git a/source/dub/package_.d b/source/dub/package_.d index cf8b7e6..cc6d060 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -78,6 +78,7 @@ instead of the one declared in the package recipe, or the one determined by invoking the VCS (GIT currently). */ + deprecated("Use load() instead. Will be removed for version 1.0.0.") this(Path root, Path recipe_file = Path.init, Package parent = null, string version_override = "") { import dub.recipe.io; @@ -164,6 +165,36 @@ return Path.init; } + /** Constructs a `Package` using a package that is physically present on the local file system. + + Params: + root = The directory in which the package resides. + recipe_file = Optional path to the package recipe file. If left + empty, the `root` directory will be searched for a recipe file. + parent = Reference to the parent package, if the new package is a + sub package. + version_override = Optional version to associate to the package + instead of the one declared in the package recipe, or the one + determined by invoking the VCS (GIT currently). + */ + static Package load(Path root, Path recipe_file = Path.init, Package parent = null, string version_override = "") + { + import dub.recipe.io; + + if (recipe_file.empty) recipe_file = findPackageFile(root); + + enforce(!recipe_file.empty, + "No package file found in %s, expected one of %s" + .format(root.toNativeString(), + packageInfoFiles.map!(f => cast(string)f.filename).join("/"))); + + auto recipe = readPackageRecipe(recipe_file, parent ? parent.name : null); + + auto ret = new Package(recipe, root, parent, version_override); + ret.m_infoFile = recipe_file; + return ret; + } + /** Returns the qualified name of the package. The qualified name includes any possible parent package if this package diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 9edfa83..f4dad84 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -178,7 +178,7 @@ foreach (p; getPackageIterator()) if (p.path == path && (!p.parentPackage || (allow_sub_packages && p.parentPackage.path != p.path))) return p; - auto pack = new Package(path, recipe_path); + auto pack = Package.load(path, recipe_path); addPackages(m_temporaryPackages, pack); return pack; } @@ -404,7 +404,7 @@ logDiagnostic("%s file(s) copied.", to!string(countFiles)); // overwrite dub.json (this one includes a version field) - auto pack = new Package(destination, Path.init, null, package_info["version"].get!string); + auto pack = Package.load(destination, Path.init, null, package_info["version"].get!string); if (pack.recipePath.head != defaultPackageFilename) // Storeinfo saved a default file, this could be different to the file from the zip. @@ -448,7 +448,7 @@ Package addLocalPackage(Path path, string verName, LocalPackageType type) { path.endsWithSlash = true; - auto pack = new Package(path); + auto pack = Package.load(path); enforce(pack.name.length, "The package has no name, defined in: " ~ path.toString()); if (verName.length) pack.version_ = Version(verName); @@ -545,7 +545,7 @@ if (!pp) { auto infoFile = Package.findPackageFile(path); - if (!infoFile.empty) pp = new Package(path, infoFile); + if (!infoFile.empty) pp = Package.load(path, infoFile); else { logWarn("Locally registered package %s %s was not found. Please run \"dub remove-local %s\".", name, ver, path.toNativeString()); @@ -607,7 +607,7 @@ p = pp; break; } - if (!p) p = new Package(pack_path, packageFile); + if (!p) p = Package.load(pack_path, packageFile); addPackages(m_packages, p); } catch( Exception e ){ logError("Failed to load package in %s: %s", pack_path, e.msg); @@ -732,7 +732,7 @@ logError("Package %s declared a sub-package, definition file is missing: %s", pack.name, path.toNativeString()); continue; } - sp = new Package(path, Path.init, pack); + sp = Package.load(path, Path.init, pack); } else sp = new Package(spr.recipe, pack.path, pack); // Add the subpackage.