fix #118 - add support for the new DUB package naming scheme

This commit is contained in:
Basile Burg 2023-06-26 01:09:33 +02:00
parent 63fff3f001
commit bd2a5d16df
1 changed files with 67 additions and 33 deletions

View File

@ -30,6 +30,7 @@ type
strict private strict private
fName : string; fName : string;
fVersions: TSemVerList; fVersions: TSemVerList;
fNewNamingScheme: boolean;
public public
constructor create; constructor create;
destructor destroy; override; destructor destroy; override;
@ -38,6 +39,7 @@ type
function highestInInterval(constref lo, hi: TSemVer): PSemVer; function highestInInterval(constref lo, hi: TSemVer): PSemVer;
function highest: PSemVer; function highest: PSemVer;
property name: string read fName write fName; property name: string read fName write fName;
property newNamingScheme: boolean read fNewNamingScheme write fNewNamingScheme;
end; end;
TDubLocalPackages = class TDubLocalPackages = class
@ -359,10 +361,12 @@ begin
begin begin
v := fVersions[i]^; v := fVersions[i]^;
if v < lo then if v < lo then
continue; continue
if v < hi then else if (v > lo) or (v = lo) then
result := fVersions[i]; result := fVersions[i]
if v > hi then else if (v < hi) and ((assigned(result) and (v > result^)) or (not assigned(result))) then
result := fVersions[i]
else if v > hi then
break; break;
end; end;
end; end;
@ -395,6 +399,23 @@ begin
end; end;
class procedure TDubLocalPackages.update; class procedure TDubLocalPackages.update;
procedure addPackageOrVersion(name, semVer: string; newNamingScheme: Boolean);
var
d: PDubLocalPackage = nil;
begin
if not find(name, d) then
begin
setLength(fLocalPackages, length(fLocalPackages) + 1);
fLocalPackages[high(fLocalPackages)] := TDubLocalPackage.create;
d := @fLocalPackages[high(fLocalPackages)];
d^.name := name;
d^.newNamingScheme := newNamingScheme;
end;
d^.addVersion(semVer);
end;
var var
p: TStringList; p: TStringList;
r: TStringList; r: TStringList;
@ -404,9 +425,10 @@ var
i: integer; i: integer;
j: integer = 0; j: integer = 0;
k: integer; k: integer;
d: PDubLocalPackage = nil;
h: TStringRange = (ptr: nil; pos: 0; len: 0); h: TStringRange = (ptr: nil; pos: 0; len: 0);
x: string; x: string;
u: TStringList;
g: string;
begin begin
@ -441,33 +463,42 @@ begin
j := 0; j := 0;
s := p[i]; s := p[i];
h.init(s); h.init(s);
while true do // after 2.104 <cachePath>/<package>/<version>/<package>
// new naming scheme can be distinguished because '.' is not a legal char in a package name
v := s.extractFileName;
if (Pos('.', v) < 1) and (Pos('master', v) < 1) then
begin begin
h.popUntil('-'); u := TStringList.Create;
if h.empty then try
break; listFolders(u, s + DirectorySeparator);
if (h.popFront^.front in ['0'..'9']) or for g in u do
h.endsWith('master') then addPackageOrVersion(v, 'v' + g.extractFileName, true);
finally
u.free;
end;
end
// before 2.104 <cachePath>/<package>-<version>/<package>
else
begin
while true do
begin begin
j := h.position; h.popUntil('-');
break; if h.empty then
break;
if (h.popFront^.front in ['0'..'9']) or
h.endsWith('master') then
begin
j := h.position;
break;
end;
end;
if not j.equals(0) then
begin
n := s[1..j-1];
n := n.extractFileName;
addPackageOrVersion(n, 'v' + s[j+1 .. length(s)], false);
end; end;
end; end;
if j.equals(0) then
continue;
n := s[1..j-1];
n := n.extractFileName;
if not find(n, d) then
begin
setLength(fLocalPackages, length(fLocalPackages) + 1);
fLocalPackages[high(fLocalPackages)] := TDubLocalPackage.create;
d := @fLocalPackages[high(fLocalPackages)];
d^.name := n;
end;
v := 'v' + s[j+1 .. length(s)];
d^.addVersion(v);
end; end;
finally finally
p.Free; p.Free;
@ -509,7 +540,6 @@ begin
hi.patch := 0; hi.patch := 0;
hi.additional :=''; hi.additional :='';
result := package^.highestInInterval(opVer, hi); result := package^.highestInInterval(opVer, hi);
result := result;
end; end;
end end
else if op = '=' then else if op = '=' then
@ -1742,15 +1772,19 @@ procedure TDubProject.updateImportPathsFromJson;
for k := 0 to b.Count-1 do for k := 0 to b.Count-1 do
begin begin
s := b[k] + n; s := b[k] + n;
p := s + '-' + u^.asString + DirectorySeparator + n + DirectorySeparator; p := s + '-' + u^.asString + DirectorySeparator + n + DirectorySeparator;
// e.g vibe-d:http -> <registrypath>/vibed-<sember>/http // new naming scheme
if not p.dirExists then
p := s + DirectorySeparator + u^.asString + DirectorySeparator + n + DirectorySeparator;
// e.g vibe-d:http -> <registrypath>/vibed/<semver>/vibed/http
// e.g ae:sys-wininet -> <registrypath>/ae/<semver>/ae/sys/wininet
if length(w) <> 0 then if length(w) <> 0 then
p += w; p += strutils.ReplaceText(w, '-', DirectorySeparator);
if not p.dirExists then if not p.dirExists then
continue; continue;
if (p + 'source').dirExists then if (p + 'source').dirExists then
begin begin
fImportPaths.Add(p + 'source') ; fImportPaths.Add(p + 'source');
break; break;
end end
else if (p + 'src').dirExists then else if (p + 'src').dirExists then