diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 1d3314a..9c27b5e 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -1,7 +1,7 @@ /** Defines the behavior of the DUB command line client. - Copyright: © 2012-2013 Matthias Dondorff + Copyright: © 2012-2013 Matthias Dondorff, Copyright © 2012-2014 Sönke Ludwig License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. Authors: Matthias Dondorff, Sönke Ludwig */ @@ -108,8 +108,7 @@ new AddLocalCommand, new RemoveLocalCommand, new ListCommand, - new ListInstalledCommand, - new SelectCommand + new ListInstalledCommand ) ]; @@ -366,7 +365,7 @@ if (!m_nodeps) { logDiagnostic("Checking dependencies in '%s'", dub.projectPath.toNativeString()); - dub.update(UpdateOptions.none); + dub.update(UpdateOptions.select); } } @@ -672,18 +671,33 @@ /******************************************************************************/ class UpgradeCommand : Command { + /* TODO: + - DependencyGraph select needs to overrule resolution algorithm. + - Fail build, when selected version is not available + - dub update: updating to pinned by default or by flag? + + Done: + - write selected versions + - load selected versions + - init: warning if pinned dependency not found + */ private { bool m_prerelease = false; bool m_forceRemove = false; + bool m_verify = false; } this() { this.name = "upgrade"; - this.argumentsPattern = ""; + this.argumentsPattern = ""; this.description = "Forces an upgrade of all dependencies"; this.helpText = [ - "Upgrades all dependencies of the package by querying the package registry(ies) for new versions." + "Upgrades all dependencies of the package by querying the package registry(ies) for new versions.", + "", + "This will also update the versions stored in the selections file ("~SelectedVersions.defaultFile~") accordingly." + "", + "If a package specified, (only) that package will be upgraded. Otherwise all direct and indirect dependencies of the current package will get upgraded." ]; } @@ -695,17 +709,22 @@ args.getopt("force-remove", &m_forceRemove, [ "Force deletion of fetched packages with untracked files" ]); + args.getopt("verify", &m_verify, [ + "Updates the project and performs a build. If successfull, rewrites the selected versions file ." + ]); } override int execute(Dub dub, string[] free_args, string[] app_args) { - enforceUsage(free_args.length == 0, "Unexpected arguments."); + enforceUsage(free_args.length <= 1, "Unexpected arguments."); enforceUsage(app_args.length == 0, "Unexpected application arguments."); + enforceUsage(!m_verify, "--verify is not yet implemented."); dub.loadPackageFromCwd(); logInfo("Upgrading project in %s", dub.projectPath.toNativeString()); - auto options = UpdateOptions.upgrade; + auto options = UpdateOptions.upgrade|UpdateOptions.select; if (m_prerelease) options |= UpdateOptions.preRelease; if (m_forceRemove) options |= UpdateOptions.forceRemove; + enforceUsage(app_args.length == 0, "Upgrading a specific package is not yet implemented."); dub.update(options); return 0; } @@ -937,51 +956,6 @@ } } -/******************************************************************************/ -/* SELECT */ -/******************************************************************************/ - -class SelectCommand : Command { - private { - bool m_tuneup; - } - this() - { - /* - Development TODOs: - - DependencyGraph select needs to overrule resolution algorithm. - - Fail build, when selected version is not available - - dub update: updating to pinned by default or by flag? - - Done: - - write selected versions - - load selected versions - - init: warning if pinned dependency not found - */ - this.name = "select"; - this.argumentsPattern = ""; - this.description = "Stores the currently used dependent package in a file, this can be used later override the used versions."; - this.helpText = [ - "", - "", - "This stores the used package versions of the main package in the current working directory. The file is " ~ SelectedVersions.defaultFile ~ " and this file can also be used to manually override only certain versions. (This includes switching to a local master )." - ]; - } - override void prepare(scope CommandArgs args) { - args.getopt("tuneup", &m_tuneup, [ - "Updates the project and performs a build. If successfull, rewrites the selected versions file ." - ]); - } - - override int execute(Dub dub, string[] free_args, string[] app_args) - { - logDiagnostic("loadPackageFromCwd"); - dub.loadPackageFromCwd(); - logDiagnostic("Selecting current versions:"); - dub.selectVersions(); - return 0; - } -} /******************************************************************************/ /* LIST */ diff --git a/source/dub/dub.d b/source/dub/dub.d index 5fabf89..adb0476 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -52,7 +52,8 @@ bool m_dryRun = false; PackageManager m_packageManager; PackageSupplier[] m_packageSuppliers; - Path m_rootPath, m_tempPath; + Path m_rootPath; + Path m_tempPath; Path m_userDubPath, m_systemDubPath; Json m_systemConfig, m_userConfig; Path m_projectPath; @@ -168,8 +169,9 @@ void update(UpdateOptions options) { bool[string] masterVersionUpgrades; + auto selections = new SelectedVersions; while (true) { - Action[] allActions = m_project.determineActions(m_packageSuppliers, options); + Action[] allActions = m_project.determineActions(m_packageSuppliers, options, selections); Action[] actions; foreach(a; allActions) if(a.packageId !in masterVersionUpgrades) @@ -206,19 +208,11 @@ m_project.reinit(); } - } - /// AKA "Pinning" or "shrinkwrap" - void selectVersions() { - enforce(m_rootPath == m_projectPath, "Currently, DUB can only select versions directly from the main project's working directory."); - SelectedVersions selectedVersions = new SelectedVersions; - Action[] allActions = m_project.determineActions(m_packageSuppliers, UpdateOptions.none, selectedVersions); - if (allActions.length > 0) { - logError("Cannot select build versions, there are missing updates to be performed."); - throw new Exception("Version selection failed."); + if (options & UpdateOptions.select) { + selections.save(m_projectPath ~ SelectedVersions.defaultFile); + logDiagnostic("Stored currently selected versions into " ~ SelectedVersions.defaultFile); } - selectedVersions.save(m_rootPath ~ Path(SelectedVersions.defaultFile)); - logInfo("Stored currently selected versions into: " ~ SelectedVersions.defaultFile); } /// Generate project files for a specified IDE. diff --git a/source/dub/project.d b/source/dub/project.d index c122e4a..b98db22 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -471,10 +471,12 @@ /// Actions which can be performed to update the application. /// selectedVersions: - Action[] determineActions(PackageSupplier[] packageSuppliers, UpdateOptions option, SelectedVersions selectedVersions = null) + Action[] determineActions(PackageSupplier[] packageSuppliers, UpdateOptions option, SelectedVersions selected_versions = null) { scope(exit) writeDubJson(); + selected_versions.clean(); + if(!m_main) { Action[] a; return a; @@ -526,7 +528,7 @@ actions ~= act; } int[string] upgradePackages; - scope(failure) if (selectedVersions !is null) selectedVersions.clean(); + scope(failure) if (selected_versions) selected_versions.clean(); foreach( string pkg, d; graph.needed() ) { auto basepkg = pkg.getBasePackage(); auto p = basepkg in retrieved; @@ -544,12 +546,9 @@ upgradePackages[basepkg] = 1; addAction(Action.get(basepkg, PlacementLocation.userWide, d.dependency, d.packages)); } - } - else { - logDiagnostic("Required package '"~basepkg~"' found with version '"~p.vers~"'"); - if (selectedVersions !is null) - selectedVersions.selectVersion(pkg, p.ver, d.packages); - } + } else logDiagnostic("Required package '"~basepkg~"' found with version '"~p.vers~"'"); + + if (selected_versions) selected_versions.selectVersion(pkg, p.ver, d.packages); } } @@ -798,7 +797,8 @@ none = 0, upgrade = 1<<1, preRelease = 1<<2, // inclde pre-release versions in upgrade - forceRemove = 1<<3 + forceRemove = 1<<3, + select = 1<<4, /// Update the dub.selections.json file with the upgraded versions }