Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only resolve dependencies if necessary. Fixes #831. #861

Merged
merged 2 commits into from
Jun 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,14 @@ abstract class PackageBuildCommand : Command {
// TODO: only upgrade(select) if necessary, only upgrade(upgrade) every now and then

// retrieve missing packages
logDiagnostic("Checking for missing dependencies.");
if (m_single) dub.upgrade(UpgradeOptions.select | UpgradeOptions.noSaveSelections);
else {
dub.upgrade(UpgradeOptions.select);
dub.project.reinit();
if (!dub.project.hasAllDependencies) {
logDiagnostic("Checking for missing dependencies.");
if (m_single) dub.upgrade(UpgradeOptions.select | UpgradeOptions.noSaveSelections);
else dub.upgrade(UpgradeOptions.select);
}

if (!m_single) {
logDiagnostic("Checking for upgrades.");
dub.upgrade(UpgradeOptions.upgrade|UpgradeOptions.printUpgradesOnly|UpgradeOptions.useCachedResult);
}
Expand Down
16 changes: 16 additions & 0 deletions source/dub/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Project {
Package[] m_dependencies;
Package[][Package] m_dependees;
SelectedVersions m_selections;
bool m_hasAllDependencies;
}

/** Loads a project.
Expand Down Expand Up @@ -113,6 +114,14 @@ class Project {
/// Package manager instance used by the project.
@property inout(PackageManager) packageManager() inout { return m_packageManager; }

/** Determines if all dependencies necessary to build have been collected.

If this function returns `false`, it may be necessary to add more entries
to `selections`, or to use `Dub.upgrade` to automatically select all
missing dependencies.
*/
bool hasAllDependencies() const { return m_hasAllDependencies; }

/** Allows iteration of the dependency tree in topological order
*/
int delegate(int delegate(ref Package)) getTopologicalPackageList(bool children_first = false, Package root_package = null, string[string] configs = null)
Expand Down Expand Up @@ -262,6 +271,7 @@ class Project {
void reinit()
{
m_dependencies = null;
m_hasAllDependencies = true;
m_packageManager.refresh(false);

void collectDependenciesRec(Package pack, int depth = 0)
Expand All @@ -274,6 +284,10 @@ class Project {
Dependency vspec = dep.spec;
Package p;

// non-optional and optional-default dependencies (if no selections file exists)
// need to be satisfied
bool is_desired = !vspec.optional || (vspec.default_ && m_selections.bare);

auto basename = getBasePackageName(dep.name);
auto subname = getSubPackageName(dep.name);
if (dep.name == m_rootPackage.basePackage.name) {
Expand All @@ -284,6 +298,7 @@ class Project {
try p = m_packageManager.getSubPackage(m_rootPackage.basePackage, subname, false);
catch (Exception e) {
logDiagnostic("%sError getting sub package %s: %s", indent, dep.name, e.msg);
if (is_desired) m_hasAllDependencies = false;
continue;
}
} else if (m_selections.hasSelectedVersion(basename)) {
Expand Down Expand Up @@ -322,6 +337,7 @@ class Project {

if (!p) {
logDiagnostic("%sMissing dependency %s %s of %s", indent, dep.name, vspec, pack.name);
if (is_desired) m_hasAllDependencies = false;
continue;
}

Expand Down