diff --git a/source/dub/dependency.d b/source/dub/dependency.d index 1aee61b..3a9ba53 100644 --- a/source/dub/dependency.d +++ b/source/dub/dependency.d @@ -24,6 +24,17 @@ static import std.compiler; +/** Encapsulates the name of a package along with its dependency specification. +*/ +struct PackageDependency { + /// Name of the referenced package. + string name; + + /// Dependency specification used to select a particular version of the package. + Dependency spec; +} + + /** Represents a dependency specification. diff --git a/source/dub/package_.d b/source/dub/package_.d index cc6d060..df986ac 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -252,16 +252,17 @@ This list includes all dependencies of all configurations. If different configurations have a dependency to the same package, but with differing - version specifications, only one of them will be returned. + version specifications, only one of them will be returned. Which one + is returned is undefined behavior. + + See_Also: `getAllDependencies` */ + deprecated("Use getAllDependencies instead. Will be removed for version 1.0.0.") @property const(Dependency[string]) dependencies() const { Dependency[string] ret; - foreach (n, d; this.recipe.buildSettings.dependencies) - ret[n] = d; - foreach (ref c; this.recipe.configurations) - foreach (n, d; c.buildSettings.dependencies) - ret[n] = d; + foreach (d; getAllDependencies()) + ret[d.name] = d.spec; return ret; } @@ -526,13 +527,14 @@ This will return the name and version of this package, as well as of all root dependencies. */ + deprecated("Will be removed for version 1.0.0.") string generateInfoString() const { string s; s ~= m_info.name ~ ", version '" ~ m_info.version_ ~ "'"; s ~= "\n Dependencies:"; - foreach(string p, ref const Dependency v; this.dependencies) - s ~= "\n " ~ p ~ ", version '" ~ v.toString() ~ "'"; + foreach(PackageDependency d; this.getAllDependencies()) + s ~= "\n " ~ d.name ~ ", version '" ~ d.spec.toString() ~ "'"; return s; } @@ -577,6 +579,24 @@ return ret; } + /** Returns a list of all possible dependencies of the package. + + This list includes all dependencies of all configurations. The same + package may occur multiple times with possibly different `Dependency` + values. + */ + PackageDependency[] getAllDependencies() + const { + auto ret = appender!(PackageDependency[]); + foreach (n, d; this.recipe.buildSettings.dependencies) + ret ~= PackageDependency(n, d); + foreach (ref c; this.recipe.configurations) + foreach (n, d; c.buildSettings.dependencies) + ret ~= PackageDependency(n, d); + return ret.data; + } + + /** Returns a description of the package for use in IDEs or build tools. */ PackageDescription describe(BuildPlatform platform, string config)