FDXPCompileLog.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. unit FDXPCompileLog;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, DXPExpertModule, ComCtrls, FDXPProgress;
  6. type
  7. TDXPCompileLog = class(TForm)
  8. PageControl: TPageControl;
  9. TSRaw: TTabSheet;
  10. MERaw: TMemo;
  11. TSConfigFile: TTabSheet;
  12. MECfgFile: TMemo;
  13. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  14. private
  15. { Déclarations privées }
  16. public
  17. { Déclarations publiques }
  18. DXPExpertModule : TDMDXPExpertModule;
  19. procedure ExecuteOnFPC(const prjFileName, logFileName, linkLogFileName : String;
  20. expertModule : TDMDXPExpertModule;
  21. progress : TDXPProgress);
  22. end;
  23. function DXPCompileLog : TDXPCompileLog;
  24. procedure ReleaseDXPCompileLog;
  25. function DXPCompileLogVisible : Boolean;
  26. implementation
  27. {$R *.dfm}
  28. uses ToolsAPI, DXPExpertUnit, DXPGlobals;
  29. var
  30. vDXPCompileLog : TDXPCompileLog;
  31. // DXPCompileLog
  32. //
  33. function DXPCompileLog : TDXPCompileLog;
  34. begin
  35. if vDXPCompileLog=nil then
  36. vDXPCompileLog:=TDXPCompileLog.Create(nil);
  37. Result:=vDXPCompileLog;
  38. end;
  39. // ReleaseDXPCompileLog
  40. //
  41. procedure ReleaseDXPCompileLog;
  42. begin
  43. if Assigned(vDXPCompileLog) then begin
  44. if vDXPCompileLog.Visible then
  45. vDXPCompileLog.Close
  46. else vDXPCompileLog.Free;
  47. vDXPCompileLog:=nil;
  48. end;
  49. end;
  50. // DXPCompileLogVisible
  51. //
  52. function DXPCompileLogVisible : Boolean;
  53. begin
  54. if Assigned(vDXPCompileLog) then
  55. Result:=vDXPCompileLog.Visible
  56. else Result:=False;
  57. end;
  58. // FormClose
  59. //
  60. procedure TDXPCompileLog.FormClose(Sender: TObject; var Action: TCloseAction);
  61. begin
  62. vDXPCompileLog:=nil;
  63. Action:=caFree;
  64. end;
  65. // ExecuteOnFPC
  66. //
  67. procedure TDXPCompileLog.ExecuteOnFPC(const prjFileName, logFileName, linkLogFileName : String;
  68. expertModule : TDMDXPExpertModule;
  69. progress : TDXPProgress);
  70. var
  71. i, pOpen, pClose, pComma, pDots, colNb, lineNb : Integer;
  72. line, fName, msgText, location, msgType : String;
  73. msgServices : IOTAMessageServices;
  74. msgGroup : IOTAMessageGroup;
  75. lineRef : Pointer;
  76. linkerErrors : TStrings;
  77. nbErrors, nbWarnings, nbHints, nbNotes : Integer;
  78. begin
  79. DXPExpertModule:=expertModule;
  80. msgServices:=(BorlandIDEServices as IOTAMessageServices);
  81. msgServices.ClearToolMessages;
  82. msgServices.ClearCompilerMessages;
  83. msgGroup:=msgServices.GetGroup('FreePascal');
  84. if msgGroup=nil then
  85. msgGroup:=msgServices.AddMessageGroup('FreePascal')
  86. else msgServices.ClearToolMessages(msgGroup);
  87. if FileExists(logFileName) then begin
  88. MERaw.Lines.LoadFromFile(logFileName);
  89. end else begin
  90. MERaw.Lines.Text:='No compiler error output.';
  91. msgServices.AddCompilerMessage(prjFileName, 'No compiler output', 'FPC',
  92. otamkFatal, 0, 0, nil, lineRef);
  93. end;
  94. if FileExists(vFPC_BinaryPath+'\fpc.cfg') then
  95. MECfgFile.Lines.LoadFromFile(vFPC_BinaryPath+'\fpc.cfg')
  96. else MECfgFile.Clear;
  97. MERaw.Lines.Insert(0, DateTimeToStr(Now));
  98. nbErrors:=0;
  99. nbWarnings:=0;
  100. nbHints:=0;
  101. nbNotes:=0;
  102. // parse
  103. for i:=0 to MERaw.Lines.Count-1 do begin
  104. line:=MERaw.Lines[i];
  105. pOpen:=Pos('(', line);
  106. pClose:=Pos(') ', line);
  107. pComma:=Pos(',', line);
  108. if (pOpen>0) and (pClose>0) and (pComma>pOpen) and (pComma<pClose) then begin
  109. fName:=Copy(line, 1, pOpen-1);
  110. location:=Copy(line, pOpen+1, pClose-pOpen-1);
  111. msgText:=Copy(line, pClose+2, MaxInt);
  112. pDots:=Pos(':', msgText);
  113. msgType:=LowerCase(Copy(msgText, 1, pDots-1));
  114. if CompareText(msgType, 'warning')=0 then
  115. Inc(nbWarnings)
  116. else if CompareText(msgType, 'hint')=0 then
  117. Inc(nbHints)
  118. else if CompareText(msgType, 'note')=0 then
  119. Inc(nbNotes)
  120. else Inc(nbErrors);
  121. pComma:=Pos(',', location);
  122. lineNb:=StrToIntDef(Copy(location, 1, pComma-1), 1);
  123. colNb:=StrToIntDef(Copy(location, pComma+1, MaxInt), 1);
  124. msgServices.AddToolMessage(DMDXPExpertModule.FPCLocateFile(fName),
  125. msgText, 'FPC', lineNb, colNb, nil,
  126. lineRef, msgGroup);
  127. end else if CompareText(Copy(line, 1, 6), 'Fatal:')=0 then begin
  128. msgServices.AddToolMessage(prjFileName, line, 'FPC',
  129. 0, 0, nil, lineRef, msgGroup);
  130. Inc(nbErrors);
  131. end;
  132. end;
  133. // Linker errors
  134. if FileExists(linkLogFileName) then begin
  135. linkerErrors:=TStringList.Create;
  136. try
  137. linkerErrors.LoadFromFile(linkLogFileName);
  138. for i:=0 to linkerErrors.Count-1 do begin
  139. line:=linkerErrors[i];
  140. if line<>'' then begin
  141. msgServices.AddToolMessage(prjFileName, line, 'LD',
  142. 0, 0, nil, lineRef, msgGroup);
  143. end;
  144. Inc(nbErrors);
  145. end;
  146. finally
  147. linkerErrors.Free;
  148. end;
  149. end;
  150. progress.SetStat(nbErrors, nbWarnings, nbHints, nbNotes);
  151. msgServices.ShowMessageView(msgGroup);
  152. if vFPC_ShowCompileLog then
  153. Show;
  154. end;
  155. end.