diff --git a/changelog/upgrade_check.dd b/changelog/upgrade_check.dd new file mode 100644 index 0000000..6b59134 --- /dev/null +++ b/changelog/upgrade_check.dd @@ -0,0 +1,8 @@ +The regular upgrade check has been removed + +Previously dub would regularly (once a day) check for possible package upgrades before building a packages. +This lead to unexpected build failures, e.g. when internet connectivity was down or dependency resolution failed, and caused unnecessary delays. + +The build flag `--nodeps` now only suppresses resolution of missing dependencies. + +The new upgrade flag `--dry-run` was added to explicitly check for upgradable packages without actually upgrading anything. diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 4120e0c..9ae6774 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -620,7 +620,7 @@ "Define the specified debug version identifier when building - can be used multiple times" ]); args.getopt("nodeps", &m_nodeps, [ - "Do not check/update dependencies before building" + "Do not resolve missing dependencies before building" ]); args.getopt("build-mode", &m_buildMode, [ "Specifies the way the compiler and linker are invoked. Valid values:", @@ -660,8 +660,6 @@ } if (!m_nodeps) { - // TODO: only upgrade(select) if necessary, only upgrade(upgrade) every now and then - // retrieve missing packages dub.project.reinit(); if (!dub.project.hasAllDependencies) { @@ -669,11 +667,6 @@ 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); - } } dub.project.validate(); @@ -1131,6 +1124,7 @@ bool m_forceRemove = false; bool m_missingOnly = false; bool m_verify = false; + bool m_dryRun = false; } this() @@ -1155,6 +1149,9 @@ args.getopt("verify", &m_verify, [ "Updates the project and performs a build. If successful, rewrites the selected versions file ." ]); + args.getopt("dry-run", &m_dryRun, [ + "Only print what would be upgraded, but don't actually upgrade anything." + ]); args.getopt("missing-only", &m_missingOnly, [ "Performs an upgrade only for dependencies that don't yet have a version selected. This is also done automatically before each build." ]); @@ -1173,6 +1170,7 @@ auto options = UpgradeOptions.upgrade|UpgradeOptions.select; if (m_missingOnly) options &= ~UpgradeOptions.upgrade; if (m_prerelease) options |= UpgradeOptions.preRelease; + if (m_dryRun) options |= UpgradeOptions.dryRun; dub.upgrade(options, free_args); return 0; } diff --git a/source/dub/dub.d b/source/dub/dub.d index 12d7d82..61a1b7c 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -525,21 +525,12 @@ } Dependency[string] versions; - if ((options & UpgradeOptions.useCachedResult) && m_project.isUpgradeCacheUpToDate() && !packages_to_upgrade.length) { - logDiagnostic("Using cached upgrade results..."); - versions = m_project.getUpgradeCache(); - } else { - auto resolver = new DependencyVersionResolver(this, options); - foreach (p; packages_to_upgrade) - resolver.addPackageToUpgrade(p); - versions = resolver.resolve(m_project.rootPackage, m_project.selections); - if (options & UpgradeOptions.useCachedResult) { - logDiagnostic("Caching upgrade results..."); - m_project.setUpgradeCache(versions); - } - } + auto resolver = new DependencyVersionResolver(this, options); + foreach (p; packages_to_upgrade) + resolver.addPackageToUpgrade(p); + versions = resolver.resolve(m_project.rootPackage, m_project.selections); - if (options & UpgradeOptions.printUpgradesOnly) { + if (options & UpgradeOptions.dryRun) { bool any = false; string rootbasename = getBasePackageName(m_project.rootPackage.name); @@ -550,7 +541,7 @@ if (basename == rootbasename) continue; if (!m_project.selections.hasSelectedVersion(basename)) { - logInfo("Non-selected package %s is available with version %s.", + logInfo("Package %s would be selected with version %s.", basename, ver); any = true; continue; @@ -558,7 +549,7 @@ auto sver = m_project.selections.getSelectedVersion(basename); if (!sver.path.empty) continue; if (ver.version_ <= sver.version_) continue; - logInfo("Package %s can be upgraded from %s to %s.", + logInfo("Package %s would be upgraded from %s to %s.", basename, sver, ver); any = true; } @@ -603,7 +594,7 @@ m_project.reinit(); - if ((options & UpgradeOptions.select) && !(options & UpgradeOptions.noSaveSelections)) + if ((options & UpgradeOptions.select) && !(options & (UpgradeOptions.noSaveSelections | UpgradeOptions.dryRun))) m_project.saveSelections(); } @@ -1381,8 +1372,9 @@ preRelease = 1<<2, /// inclde pre-release versions in upgrade forceRemove = 1<<3, /// Deprecated, does nothing. select = 1<<4, /// Update the dub.selections.json file with the upgraded versions - printUpgradesOnly = 1<<5, /// Instead of downloading new packages, just print a message to notify the user of their existence - useCachedResult = 1<<6, /// Use cached information stored with the package to determine upgrades + dryRun = 1<<5, /// Instead of downloading new packages, just print a message to notify the user of their existence + /*deprecated*/ printUpgradesOnly = dryRun, /// deprecated, use dryRun instead + /*deprecated*/ useCachedResult = 1<<6, /// deprecated, has no effect noSaveSelections = 1<<7, /// Don't store updated selections on disk } diff --git a/source/dub/project.d b/source/dub/project.d index 277b92b..c2a36b2 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -1067,41 +1067,14 @@ m_selections.save(path); } - /** Checks if the cached upgrade information is still considered up to date. - - The cache will be considered out of date after 24 hours after the last - online check. - */ - bool isUpgradeCacheUpToDate() + deprecated bool isUpgradeCacheUpToDate() { - try { - auto datestr = m_packageSettings["dub"].opt!(Json[string]).get("lastUpgrade", Json("")).get!string; - if (!datestr.length) return false; - auto date = SysTime.fromISOExtString(datestr); - if ((Clock.currTime() - date) > 1.days) return false; - return true; - } catch (Exception t) { - logDebug("Failed to get the last upgrade time: %s", t.msg); - return false; - } + return false; } - /** Returns the currently cached upgrade information. - - The returned dictionary maps from dependency package name to the latest - available version that matches the dependency specifications. - */ - Dependency[string] getUpgradeCache() + deprecated Dependency[string] getUpgradeCache() { - try { - Dependency[string] ret; - foreach (string p, d; m_packageSettings["dub"].opt!(Json[string]).get("cachedUpgrades", Json.emptyObject)) - ret[p] = SelectedVersions.dependencyFromJson(d); - return ret; - } catch (Exception t) { - logDebug("Failed to get cached upgrades: %s", t.msg); - return null; - } + return null; } /** Sets a new set of versions for the upgrade cache. @@ -1446,4 +1419,3 @@ m_selections[p] = Selected(dependencyFromJson(v)); } } -