Skip to content

Commit

Permalink
Add ability to specify version specification for commandline commands
Browse files Browse the repository at this point in the history
As mentioned in the changelog, it was not possible with all commands.
No breaking changes are expected.
  • Loading branch information
deviator authored and Geod24 committed Dec 7, 2020
1 parent 68190df commit b1897fe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
All commands now accept a version specification

Before this release dub could only get an exact version for some commands
(`describe`, `generate`, `fetch`, etc...). All commands now accept a version specification,
such as can be found in `dub.json` / `dub.sdl`:

dub fetch 'foo@>0.2.0'
dub describe foo@'>=0.3.0 <1.0.0'

Note that commands such as `describe` will still not fetch from the network.
13 changes: 6 additions & 7 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,10 @@ abstract class PackageBuildCommand : Command {
protected void setupVersionPackage(Dub dub, string str_package_info, string default_build_type = "debug")
{
PackageAndVersion package_info = splitPackageName(str_package_info);
Version ver = package_info.version_.length ? Version(package_info.version_) : Version.unknown;
setupPackage(dub, package_info.name, default_build_type, ver);
setupPackage(dub, package_info.name, default_build_type, package_info.version_);
}

protected void setupPackage(Dub dub, string package_name, string default_build_type = "debug", Version ver = Version.unknown)
protected void setupPackage(Dub dub, string package_name, string default_build_type = "debug", string ver = "")
{
if (!m_compilerName.length) m_compilerName = dub.defaultCompiler;
if (!m_arch.length) m_arch = dub.defaultArchitecture;
Expand Down Expand Up @@ -1039,7 +1038,7 @@ abstract class PackageBuildCommand : Command {
}
}

private bool loadSpecificPackage(Dub dub, string package_name, Version ver)
private bool loadSpecificPackage(Dub dub, string package_name, string ver)
{
if (m_single) {
enforce(package_name.length, "Missing file name of single-file package.");
Expand All @@ -1061,12 +1060,12 @@ abstract class PackageBuildCommand : Command {

enforce(package_name.length, "No valid root package found - aborting.");

auto pack = ver.isUnknown
auto pack = ver == ""
? dub.packageManager.getLatestPackage(package_name)
: dub.packageManager.getPackage(package_name, ver);
: dub.packageManager.getBestPackage(package_name, ver);

enforce(pack, format!"Failed to find a package named '%s%s' locally."(package_name,
ver.isUnknown ? "" : "@" ~ ver.toString()
ver == "" ? "" : ("@" ~ ver)
));
logInfo("Building package %s in %s", pack.name, pack.path.toNativeString());
dub.loadPackage(pack);
Expand Down
7 changes: 7 additions & 0 deletions test/version-spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ $DUB add-local "$CURR_DIR/version-spec/oldfoo"
[[ $($DUB describe [email protected] | grep path | head -n 1) == *"/newfoo/"* ]]
[[ $($DUB describe [email protected] | grep path | head -n 1) == *"/oldfoo/"* ]]

[[ $($DUB describe foo@'<1.0.0' | grep path | head -n 1) == *"/oldfoo/"* ]]
[[ $($DUB describe foo@'>0.1.0' | grep path | head -n 1) == *"/newfoo/"* ]]
[[ $($DUB describe foo@'>0.2.0' | grep path | head -n 1) == *"/newfoo/"* ]]
[[ $($DUB describe foo@'<=0.2.0' | grep path | head -n 1) == *"/oldfoo/"* ]]
[[ $($DUB describe foo@'*' | grep path | head -n 1) == *"/newfoo/"* ]]
[[ $($DUB describe foo@'>0.0.1 <2.0.0' | grep path | head -n 1) == *"/newfoo/"* ]]

[[ $($DUB test foo | head -n 1) == *"/newfoo/" ]]
[[ $($DUB test [email protected] | head -n 1) == *"/newfoo/" ]]
[[ $($DUB test [email protected] | head -n 1) == *"/oldfoo/" ]]
Expand Down

0 comments on commit b1897fe

Please sign in to comment.