From 04d7308bf77048401c3bc5c93e8659da081eeeb2 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sat, 19 Sep 2015 14:03:52 +0200 Subject: [PATCH] initial work on #27, register a libman entry using DUB fetch --- icons/other/dub_small.png | Bin 0 -> 686 bytes src/ce_icons.inc | 30 +++++++++ src/ce_libmaneditor.lfm | 15 ++++- src/ce_libmaneditor.pas | 131 +++++++++++++++++++++++++++++++++++++- 4 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 icons/other/dub_small.png diff --git a/icons/other/dub_small.png b/icons/other/dub_small.png new file mode 100644 index 0000000000000000000000000000000000000000..1e8316213d444a66bfb46c54628fb778dffe36f5 GIT binary patch literal 686 zcmV;f0#W^mP)~S^8iu-}?5wHyze}*{MsH<}!T4_stA5AMh`u zy(MDhwqp^i-WCm_EgJlL1Kz05<@I{Oe2A<%`@ye5;z4%^KktYB&{(AB{f(m3&XU({ zlILVh%L#o1s7$m70Qi14Ag^zOB#Dgh`MCLUWOu92w?blX*KcDDV~O#GzC2zY4-T*0 zYv|d_c|RDC06+$S`p!A?$(2ZR-9DptGlPYy5^hqnNaV>S4)SRxn!nr*RBi6yfX<@t za93>R?e&0=0U&lW9QBoFCz2{QYTY=Z5W6*@e6_|2k#@>Pi{wJksR2%#**ZPsKi@M`PwmjEAkO6VieO&bqGWOVd}&3;eCg^I-uU;^Dd3sC{PVe#T>*m~*ffuNYW5w!4!;eePN z2v~S}$p70&6a9@;Q({V41DIPDMx~SCDK;cU04r%2GYLj(1X5ZBM9xTT8R`FyUy8@y U1y--feE'#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' diff --git a/src/ce_libmaneditor.lfm b/src/ce_libmaneditor.lfm index 8c0812c7..b3095d9f 100644 --- a/src/ce_libmaneditor.lfm +++ b/src/ce_libmaneditor.lfm @@ -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 diff --git a/src/ce_libmaneditor.pas b/src/ce_libmaneditor.pas index 88994428..335b3622 100644 --- a/src/ce_libmaneditor.pas +++ b/src/ce_libmaneditor.pas @@ -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;