Merge pull request #2285 from dlang/upgrade_sub_packages
Add a command line option for upgrading all sub packages.

Signed-off-by: Jan Jurzitza <gh@webfreak.org>
Signed-off-by: Nicholas Wilson <thewilsonator@users.noreply.github.com>
Merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
commit 609b9806c16b19c6f31ef2a50e9b59a933be3161
2 parents d53bbee + bb817d2
@The Dlang Bot The Dlang Bot authored on 2 Jul 2022
GitHub committed on 2 Jul 2022
Showing 5 changed files
View
6
changelog/subpackage_upgrade.dd 0 → 100644
Upgrading all sub packages at once
 
A new "-s" switch allows to "dub upgrade" all sub packages together with the
base package. This aims to provide a better workflow for fully reproducible
builds and tests.
View
39
source/dub/commandline.d
 
class UpgradeCommand : Command {
private {
bool m_prerelease = false;
bool m_includeSubPackages = false;
bool m_forceRemove = false;
bool m_missingOnly = false;
bool m_verify = false;
bool m_dryRun = false;
{
args.getopt("prerelease", &m_prerelease, [
"Uses the latest pre-release version, even if release versions are available"
]);
args.getopt("s|sub-packages", &m_includeSubPackages, [
"Also upgrades dependencies of all directory based sub packages"
]);
args.getopt("verify", &m_verify, [
"Updates the project and performs a build. If successful, rewrites the selected versions file <to be implemented>."
]);
args.getopt("dry-run", &m_dryRun, [
if (m_missingOnly) options &= ~UpgradeOptions.upgrade;
if (m_prerelease) options |= UpgradeOptions.preRelease;
if (m_dryRun) options |= UpgradeOptions.dryRun;
dub.upgrade(options, free_args);
 
auto spacks = dub.project.rootPackage
.subPackages
.filter!(sp => sp.path.length);
 
if (m_includeSubPackages) {
bool any_error = false;
 
// Go through each path based sub package, load it as a new instance
// and perform an upgrade as if the upgrade had been run from within
// the sub package folder. Note that we have to use separate Dub
// instances, because the upgrade always works on the root package
// of a project, which in this case are the individual sub packages.
foreach (sp; spacks) {
try {
auto fullpath = (dub.projectPath ~ sp.path).toNativeString();
logInfo("Upgrading sub package in %s", fullpath);
auto sdub = new Dub(fullpath, dub.packageSuppliers, SkipPackageSuppliers.all);
sdub.defaultPlacementLocation = dub.defaultPlacementLocation;
sdub.loadPackage();
sdub.upgrade(options, free_args);
} catch (Exception e) {
logError("Failed to update sub package at %s: %s",
sp.path, e.msg);
any_error = true;
}
}
 
if (any_error) return 1;
} else if (!spacks.empty) {
foreach (sp; spacks)
logInfo("Not upgrading sub package in %s", sp.path);
logInfo("\nNote: specify -s to also upgrade sub packages.");
}
 
return 0;
}
}
 
View
source/dub/dub.d
View
test/test-upgrade-subpackages.sh 0 → 100755
View
test/timeout.sh