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