initial work on #27, register a libman entry using DUB fetch

This commit is contained in:
Basile Burg 2015-09-19 14:03:52 +02:00
parent ef7488316a
commit 04d7308bf7
4 changed files with 172 additions and 4 deletions

BIN
icons/other/dub_small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 686 B

View File

@ -1365,6 +1365,36 @@ LazarusResources.Add('cut','PNG',[
+'^'#236#134#137#11#174#219#151'm'#251'n'#146#186#228#1#143#145#183#8#186#26#0
+#201'8'#158#215#157#131#186#137#0#0#0#0'IEND'#174'B`'#130
]);
LazarusResources.Add('dub_small','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#16#0#0#0#16#8#6#0#0#0#31#243#255'a'
+#0#0#0#6'bKGD'#0#255#0#255#0#255#160#189#167#147#0#0#0#9'pHYs'#0#0#1'j'#0#0#1
+'j'#1'{'#173#216'6'#0#0#0#7'tIME'#7#223#9#19#10#8#11'2'#156'H'#12#0#0#2';IDA'
+'T8'#203#213'ROHTq'#16#254#230#247#222's'#221#213']um'#205'?'#209#10'n'#238
+#174#187#238#193'.v_'#162#131'x'#19':'#228'%'#139#8#140#2#165#2'%'#16'K"'#5
+#149#254#144'x'#136#8':t'#9#186#20'XP'#145#17#6#26#134#187#22#132#253'YQD'
+#211#221'U'#223#250#246#189'7'#29#214'}'#217#169'K'#151#230'2|'#195#247#205
+#12'3'#31#240'/'#163#189'%b'#229#182'c'#17#171#222#22#13#162'-'#26#252'{'#3
+#222#168#207#229#245'z'#193'|'#136#172':'#251#193#175'B'#226'Aw'#8'?'#239#135
+#254#208'X'#164#231#253#141#162#212#206#146#215'm'#146#231'dL'#203#9'}'#4#168
+'L'#180#8#0#248'~7 '#175'o'#131'$'#137#140#240#249#184#249'qdw'#171#207#183
+'Bbo'#215'oc'#13'c'#137#241#134#190'<^'#30#15#14#175#221'k'#232#217#203'y?'
+#24#144#0'@'#6#128#250#206'9'#243#201#149'Hs'#221'>'#163'w3'#131#133#170#18
+'nR'#179'H'#228#201'%'#14#242'i&'#154#191#220#14'Tm'#238#224#128#206#162#239
+'pWl'#230#237#245#128#144#1' v3'#28#245#149'g'''#146'*6j'#221'8'#162#16#187
+'5'#161'|'#181#198#9#145'v'#202'F'#139#228'B'#208#169#1'N'#155#217':='#228'?'
+#222#212'='#255'H<'#238#141#216#138#20#190#150#204'`'#210#211#17'/+:'#17'/O'
+#237#208#170' '#206#228#245#138'`^'#219#162'dq'#251'|iE'#199'|'#233#234#22
+#222#248#247#211')'#224#160',4'#29#210#150#6#175']'#193'b^'#160#235#148'2M'
+#179'6'#143#179#186'Y'#195#204'K'#214'BD?'#152#225#172#244#22#20#16#0#204#142
+#132#207'z'#203#140';'#219#26'M'#184#10#153#136#16'e'#0#154#206'O'#179#6'9'
+#29#10'7'#203#18#228'L'#22'/wth'#246#2#28']I'#241#5'_'#231#167#209#221'7vav'
+#228#217#25#135#130#203'&XO'#170't'#206'U'#200'6'#1#30#149#4'T'#221#192#165
+#165#20#147#175#2#23#211'*'#170']v'#234#169'>'#29#127#152'3'#201#187':'#235
+'VS'#131'a'#241#226'j'#216'z'#233#235#129#160#152#186#17#180#240#135#225#128
+#152#28#8'Xxz'#200#255#219'H'#19#253#141'TSbJY'#3#152'['#22'F'#165#147#225')'
+'6$E'#0'+i'#24'3'#9'Fk'#4'RZ'#5'D'#206'Hl'#25#233#255#142'_'#138#199#223#5'V'
+#175#200'}'#0#0#0#0'IEND'#174'B`'#130
]);
LazarusResources.Add('flash','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#16#0#0#0#16#8#6#0#0#0#31#243#255'a'
+#0#0#0#25'tEXtSoftware'#0'Adobe ImageReadyq'#201'e<'#0#0#2'MIDATx'#218#148'S'

View File

@ -1,7 +1,7 @@
inherited CELibManEditorWidget: TCELibManEditorWidget
Left = 1424
Left = 985
Height = 349
Top = 284
Top = 275
Width = 466
Caption = 'Library manager'
ClientHeight = 349
@ -124,6 +124,17 @@ inherited CELibManEditorWidget: TCELibManEditorWidget
Spacing = 0
TabOrder = 8
end
object btnDubFetch: TBitBtn
Left = 140
Height = 26
Hint = 'register from the current project'
Top = 0
Width = 28
Align = alLeft
OnClick = btnDubFetchClick
Spacing = 0
TabOrder = 9
end
end
object List: TListView[1]
Left = 4

View File

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
Menus, ComCtrls, Buttons, ce_widget, ce_interfaces, ce_nativeproject, ce_dmdwrap,
ce_common, ce_dialogs, ce_sharedres;
ce_common, ce_dialogs, ce_sharedres, process, ce_dubproject, ce_observer;
type
@ -17,6 +17,7 @@ type
btnMoveDown: TBitBtn;
btnMoveUp: TBitBtn;
btnReg: TBitBtn;
btnDubFetch: TBitBtn;
btnSelFile: TBitBtn;
btnAddLib: TBitBtn;
btnRemLib: TBitBtn;
@ -26,6 +27,7 @@ type
List: TListView;
Panel1: TPanel;
procedure btnAddLibClick(Sender: TObject);
procedure btnDubFetchClick(Sender: TObject);
procedure btnEditAliasClick(Sender: TObject);
procedure btnRegClick(Sender: TObject);
procedure btnRemLibClick(Sender: TObject);
@ -37,7 +39,6 @@ type
procedure ListEdited(Sender: TObject; Item: TListItem; var AValue: string);
private
fProj: ICECommonProject;
//TODO-cDUB: register a static lib in libman via a DUB project
procedure updateRegistrable;
procedure projNew(aProject: ICECommonProject);
procedure projChanged(aProject: ICECommonProject);
@ -75,6 +76,7 @@ begin
AssignPng(btnSelfoldOfFiles, 'bricks');
AssignPng(btnSelRoot, 'folder_add');
AssignPng(btnReg, 'book_link');
AssignPng(btnDubFetch, 'dub_small');
end;
procedure TCELibManEditorWidget.updateRegistrable;
@ -132,6 +134,131 @@ begin
itm.Selected := True;
end;
procedure TCELibManEditorWidget.btnDubFetchClick(Sender: TObject);
var
dub: TProcess;
nme: string = '';
msg: string;
pth: string;
str: TStringList;
itf: ICEMessagesDisplay;
err: integer;
idx: integer;
prj: TCEDubProject;
cdy: string;
begin
if not InputQuery('DUB library import', 'please enter the name of the package',
nme) then exit;
if List.Items.FindCaption(0, nme, false, false, false) <> nil then
begin
dlgOkInfo(format('a library item with the alias "%s" already exists, delete it before trying again.',
[nme]));
exit;
end;
{$IFDEF WINDOWS}
pth := GetEnvironmentVariable('APPDATA') + '\dub\packages\' + nme + '-master';
{$ELSE}
pth := GetEnvironmentVariable('HOME') + '/.dub/packages/' + nme + '-master';
{$ENDIF}
// fetch
dub := TProcess.Create(nil);
try
dub.Executable:= 'dub';
dub.Options:= [poUsePipes, poStderrToOutPut];
dub.Parameters.Add('fetch');
dub.Parameters.Add(nme);
// fetch project, version handling, pth is hard to set because of semVer suffix.
// needed: a folder monitor to detect the one created by dub.
dub.Parameters.Add('--version=~master');
dub.Execute;
while dub.Running do sleep(10);
err := dub.ExitStatus;
str := TStringList.Create;
try
processOutputToStrings(dub, str);
itf := getMessageDisplay;
for msg in str do
itf.message(msg, nil, amcMisc, amkAuto);
finally
str.Free;
end;
finally
dub.Free;
end;
if err <> 0 then
begin
itf.message('error, failed to fetch the repository using DUB', nil, amcApp, amkErr);
exit;
end;
// build
dub := TProcess.Create(nil);
try
dub.Executable:= 'dub';
dub.Options:= [poUsePipes, poStderrToOutPut];
dub.Parameters.Add('build');
dub.Parameters.Add('--build=release');
dub.CurrentDirectory:= pth;
dub.Execute;
while dub.Running do sleep(10);
err := dub.ExitStatus;
str := TStringList.Create;
try
processOutputToStrings(dub, str);
itf := getMessageDisplay;
for msg in str do
itf.message(msg, nil, amcMisc, amkAuto);
finally
str.Free;
end;
finally
dub.Free;
end;
if err <> 0 then
begin
itf.message('error, failed to compile the library to register', nil, amcApp, amkErr);
exit;
end;
// TODO-cbugfix: entity connector, AV when CE terminates due to the begin/end update trick.
// project used to get the infos
EntitiesConnector.beginUpdate;
prj := TCEDubProject.create(nil);
EntitiesConnector.removeSubject(prj);
try
prj := TCEDubProject.create(nil);
if FileExists(pth + DirectorySeparator + 'dub.json') then
prj.loadFromFile(pth + DirectorySeparator + 'dub.json')
else if FileExists(pth + DirectorySeparator + 'package.json') then
prj.loadFromFile(pth + DirectorySeparator + 'package.json');
str := TStringList.Create;
try
for idx := 0 to prj.sourcesCount-1 do
str.Add(prj.sourceAbsolute(idx));
with List.Items.Add do
begin
Caption := nme;
SubItems.Add(prj.outputFilename);
if str.Count = 1 then
cdy := ExtractFileDir(str.Strings[0])
else begin
cdy := commonFolder(str);
cdy := ExtractFileDir(cdy);
end;
SubItems.Add(cdy);
Selected:=true;
end;
finally
str.Free;
end;
finally
prj.Free;
EntitiesConnector.endUpdate;
gridToData;
end;
end;
procedure TCELibManEditorWidget.btnEditAliasClick(Sender: TObject);
var
al: string;