Skip to content

Commit 46d319f

Browse files
committed
Fixed:
Redub wasn't handling dub add-path Redub now also exists the program right after printing --version or --help
1 parent b377303 commit 46d319f

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

source/redub/api.d

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ bool cleanProject(ProjectDetails d, bool showMessages)
550550

551551
ArgsDetails resolveArguments(string[] args, bool isDescribeOnly = false)
552552
{
553+
import core.stdc.stdlib;
553554
import std.algorithm.comparison:either;
554555
import std.getopt;
555556
import std.file;
@@ -567,14 +568,14 @@ ArgsDetails resolveArguments(string[] args, bool isDescribeOnly = false)
567568
{
568569
import std.getopt;
569570
defaultGetoptPrinter(RedubVersionShort~" build information: \n\t"~baseHelpInfo, res.options);
570-
return ArgsDetails.init;
571+
exit(0);
571572
}
572573

573574
if(bArgs.version_)
574575
{
575576
import std.stdio;
576577
writeln(RedubVersion);
577-
return ArgsDetails.init;
578+
exit(0);
578579
}
579580

580581
updateVerbosity(bArgs.cArgs);

source/redub/package_searching/dub.d

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ ReducedPackageInfo redubDownloadPackage(string packageName, string repo, string
6363
*/
6464
private ReducedPackageInfo getPackageInFolder(string folder, string packageName, string subPackage, string packageVersion)
6565
{
66-
import std.path;
6766
import redub.misc.path;
67+
import std.path;
6868
import std.file;
6969
import std.algorithm.sorting;
7070
import std.algorithm.iteration;
@@ -114,7 +114,6 @@ private ReducedPackageInfo getPackageInFolder(string folder, string packageName,
114114
PackageInfo getPackage(string packageName, string repo, string packageVersion, string requiredBy)
115115
{
116116
import std.file;
117-
import std.path;
118117
import redub.misc.path;
119118
import std.algorithm;
120119
import std.array;
@@ -170,11 +169,32 @@ private ReducedPackageInfo getPackageInJSON(JSONValue json, string packageName,
170169
{
171170
const(JSONValue)* nameJson = "name" in v;
172171
const(JSONValue)* ver = "version" in v;
173-
SemVer packageVer = SemVer(ver.str);
174-
if (nameJson && nameJson.str == packageName && packageVer.satisfies(requirement))
172+
const(JSONValue)* pathJson = "path" in v;
173+
if(nameJson)
175174
{
176-
vlog("Using local package found at ", v["path"].str, " with version ", ver.str);
177-
return ReducedPackageInfo(ver.str, v["path"].str);
175+
if(!pathJson)
176+
{
177+
warn("Corrupted JSON ", getLocalPackagesPath(), " local-packages.json must always have a 'path'");
178+
continue;
179+
}
180+
if(!ver)
181+
{
182+
static bool hasShown = false;
183+
if(!hasShown)
184+
{
185+
warn("dub add-path is not currently implemented. Please add your custom packages with dub add-local instead.",
186+
"Warning generated for path ", pathJson.str,
187+
". Local packages is at ", getLocalPackagesPath());
188+
hasShown = true;
189+
continue;
190+
}
191+
}
192+
SemVer packageVer = SemVer(ver.str);
193+
if (nameJson.str == packageName && packageVer.satisfies(requirement))
194+
{
195+
vlog("Using local package found at ", pathJson.str, " with version ", ver.str);
196+
return ReducedPackageInfo(ver.str, pathJson.str);
197+
}
178198
}
179199
}
180200
return ReducedPackageInfo.init;
@@ -202,7 +222,7 @@ private ReducedPackageInfo getPackageInLocalPackages(string packageName, string
202222
return getPackageInJSON(localCache, packageName, packageVersion);
203223
}
204224
isCached = true;
205-
string locPackages = buildNormalizedPath(getDefaultLookupPathForPackages(), "local-packages.json");
225+
string locPackages = getLocalPackagesPath();
206226
if(std.file.exists(locPackages))
207227
localCache = parseJSON(std.file.readText(locPackages));
208228
return getPackageInLocalPackages(packageName, packageVersion);
@@ -260,6 +280,15 @@ private string getDefaultLookupPathForPackages()
260280
return buildNormalizedPath(getDubWorkspacePath, "packages");
261281
}
262282

283+
private string getLocalPackagesPath()
284+
{
285+
import redub.misc.path;
286+
static string localPackages;
287+
if(!localPackages)
288+
localPackages = buildNormalizedPath(getDefaultLookupPathForPackages(), "local-packages.json");
289+
return localPackages;
290+
}
291+
263292
/**
264293
* Git style (~master)
265294
* Params:

0 commit comments

Comments
 (0)