IdePackager: Remove IDEMsgIntf dependency from PackageSystem.

This commit is contained in:
Juha 2024-04-20 12:48:34 +03:00
parent 83bb996e3c
commit f8a04256ff
4 changed files with 80 additions and 65 deletions

View File

@ -20,7 +20,9 @@ uses
// LCL
Forms,
// LazUtils
IDEExternToolIntf, LazLoggerBase,
LazLoggerBase,
// BuildIntf
IDEExternToolIntf,
// IdeIntf
MenuIntf;

View File

@ -7134,9 +7134,8 @@ begin
debugln(['Error: (lazarus) [TMainIDE.DoBuildProject] SaveStateFile before compile failed']);
exit;
end;
WarnSuspiciousCompilerOptions('Project checks','',CompilerParams);
// Use PackageGraph method also for project compiler options.
PackageGraph.WarnSuspiciousCompilerOptions('Project checks','',CompilerParams);
StartTime:=Now;
Result:=TheCompiler.Compile(Project1,
WorkingDir,CompilerFilename,CmdLineParams,

View File

@ -55,7 +55,7 @@ uses
IDEExternToolIntf, MacroDefIntf, ProjectIntf, CompOptsIntf, LazMsgWorker,
FppkgIntf, PackageDependencyIntf, PackageLinkIntf, PackageIntf, ComponentReg,
// IDEIntf
IDEMsgIntf, LazIDEIntf,
LazIDEIntf,
// Package registration
LazarusPackageIntf,
// IdeUtils
@ -97,9 +97,11 @@ type
pvPkgSearch // write debug messsages what packages are searched and found
);
TPkgVerbosityFlags = set of TPkgVerbosityFlag;
TPkgUninstallFlags = set of TPkgUninstallFlag;
// Events
TShowMsgEvent = function(aUrgency: TMessageLineUrgency;
aMsg, aSrcFilename: string; aLineNumber, aColumn: integer;
aViewCaption: string): TMessageLine of object;
TPkgAddedEvent = procedure(APackage: TLazPackage) of object;
TPkgDeleteEvent = procedure(APackage: TLazPackage) of object;
TPkgUninstall = function(APackage: TLazPackage;
@ -213,6 +215,7 @@ type
FOnDeletePackage: TPkgDeleteEvent;
FOnDependencyModified: TDependencyModifiedEvent;
FOnEndUpdate: TPkgGraphEndUpdateEvent;
FOnShowMessage: TShowMsgEvent;
FOnSrcEditFileIsModified: TSrcEditFileIsModifiedEvent;
FOnTranslatePackage: TPkgTranslate;
FOnUninstallPackage: TPkgUninstall;
@ -251,7 +254,7 @@ type
function LoadPackageCompiledStateFile(APackage: TLazPackage; o: TPkgOutputDir;
StateFile: string; IgnoreErrors, ShowAbort: boolean): TModalResult;
procedure InvalidateStateFile(APackage: TLazPackage);
procedure OnExtToolBuildStopped(Sender: TObject);
procedure ExtToolBuildStopped(Sender: TObject);
procedure PkgModify(Sender: TObject);
protected
procedure IncChangeStamp; override;
@ -449,6 +452,7 @@ type
function SaveAutoInstallConfig: TModalResult;// for the uses section
function IsCompiledInBasePackage(PackageName: string): boolean;
procedure FreeAutoInstallDependencies;
procedure WarnSuspiciousCompilerOptions(ViewCaption, Target: string; CompilerParams: TStrings);
public
// registration
procedure RegisterUnitHandler(const TheUnitName: string;
@ -508,26 +512,27 @@ type
// events
property OnAddPackage: TPkgAddedEvent read FOnAddPackage write FOnAddPackage;
property OnBeforeCompilePackages: TOnBeforeCompilePackages read
FOnBeforeCompilePackages write FOnBeforeCompilePackages;
property OnBeginUpdate: TNotifyEvent read FOnBeginUpdate write FOnBeginUpdate;
property OnChangePackageName: TPkgChangeNameEvent read FOnChangePackageName
write FOnChangePackageName;
property OnCheckInterPkgFiles: TOnCheckInterPkgFiles
read FOnCheckInterPkgFiles write FOnCheckInterPkgFiles;
property OnDependencyModified: TDependencyModifiedEvent
read FOnDependencyModified write FOnDependencyModified;
property OnDeletePackage: TPkgDeleteEvent read FOnDeletePackage
write FOnDeletePackage;
property OnEndUpdate: TPkgGraphEndUpdateEvent read FOnEndUpdate write FOnEndUpdate;
property OnDeleteAmbiguousFiles: TPkgDeleteAmbiguousFiles
read FOnDeleteAmbiguousFiles write FOnDeleteAmbiguousFiles;
property OnDeletePackage: TPkgDeleteEvent read FOnDeletePackage
write FOnDeletePackage;
property OnDependencyModified: TDependencyModifiedEvent
read FOnDependencyModified write FOnDependencyModified;
property OnEndUpdate: TPkgGraphEndUpdateEvent read FOnEndUpdate write FOnEndUpdate;
property OnShowMessage: TShowMsgEvent read FOnShowMessage write FOnShowMessage;
property OnSrcEditFileIsModified: TSrcEditFileIsModifiedEvent read FOnSrcEditFileIsModified
write FOnSrcEditFileIsModified;
property OnTranslatePackage: TPkgTranslate read FOnTranslatePackage
write FOnTranslatePackage;
property OnUninstallPackage: TPkgUninstall read FOnUninstallPackage
write FOnUninstallPackage;
property OnBeforeCompilePackages: TOnBeforeCompilePackages read
FOnBeforeCompilePackages write FOnBeforeCompilePackages;
property OnSrcEditFileIsModified: TSrcEditFileIsModifiedEvent read FOnSrcEditFileIsModified
write FOnSrcEditFileIsModified;
// set during calling Register procedures
property RegistrationFile: TPkgFile read FRegistrationFile;
@ -546,7 +551,6 @@ function ExtractMakefileCompiledParams(CompParams: TStrings;
function FPCParamNeedsBuildAll(const Param: String): boolean;
function FPCParamForBuildAllHasChanged(OldParams, NewParams: TStrings): boolean;
function RemoveFPCVerbosityParams(CompParams: TStrings): TStrings;
procedure WarnSuspiciousCompilerOptions(ViewCaption, Target: string; CompilerParams: TStrings);
function WriteCompilerCfgFile(CfgFilename: string; CompilerParams: TStrings;
out CmdLineParams: TStrings): TCodeBuffer;
@ -735,38 +739,6 @@ begin
end;
end;
procedure WarnSuspiciousCompilerOptions(ViewCaption, Target: string;
CompilerParams: TStrings);
var
ParsedParams: TObjectList;
i: Integer;
Param: TFPCParamValue;
Msg: String;
begin
if IDEMessagesWindow=nil then exit;
ParsedParams:=TObjectList.Create(true);
try
ParseFPCParameters(CompilerParams,ParsedParams);
for i:=0 to ParsedParams.Count-1 do begin
Param:=TFPCParamValue(ParsedParams[i]);
if fpfValueChanged in Param.Flags then begin
Msg:='';
if Param.Kind in [fpkBoolean,fpkValue] then begin
if Param.Name<>'M' then // Many -M options are allowed.
Msg:=Format(lisPassingCompilerOptionTwiceWithDifferentValues, [Param.Name]);
end
else if Param.Kind=fpkDefine then
Msg:=Format(lisPassingCompilerDefineTwiceWithDifferentValues, [Param.Name]);
if Msg='' then continue;
if Target<>'' then Msg:=Target+' '+Msg;
IDEMessagesWindow.AddCustomMessage(mluNote,Msg,'',0,0,ViewCaption);
end;
end;
finally
ParsedParams.Free;
end;
end;
function WriteCompilerCfgFile(CfgFilename: string; CompilerParams: TStrings;
out CmdLineParams: TStrings): TCodeBuffer;
var
@ -986,8 +958,7 @@ end;
{ TLazPkgGraphExtToolData }
constructor TLazPkgGraphExtToolData.Create(aKind, aModuleName, aFilename: string
);
constructor TLazPkgGraphExtToolData.Create(aKind, aModuleName, aFilename: string);
begin
inherited Create(aKind, aModuleName, aFilename);
CompilerParams:=TStringListUTF8Fast.Create;
@ -1131,8 +1102,8 @@ end;
procedure TLazPackageGraph.AddMessage(TheUrgency: TMessageLineUrgency;
const Msg, Filename: string);
begin
if Assigned(IDEMessagesWindow) then
IDEMessagesWindow.AddCustomMessage(TheUrgency,Msg,Filename)
if Assigned(FOnShowMessage) then
FOnShowMessage(TheUrgency, Msg, Filename, 0, 0, '')
else
DebugLn([MessageLineUrgencyNames[TheUrgency],': (lazarus) ',Msg,' Filename="',Filename,'"']);
end;
@ -2131,23 +2102,23 @@ begin
AbortRegistration:=true;
end;
procedure TLazPackageGraph.OnExtToolBuildStopped(Sender: TObject);
procedure TLazPackageGraph.ExtToolBuildStopped(Sender: TObject);
var
PkgCompileTool: TAbstractExternalTool;
Data: TLazPkgGraphExtToolData;
aPackage: TLazPackage;
SrcPPUFile: String;
MsgResult: TModalResult;
SrcF: String;
SrcPPUFileExists: Boolean;
MsgResult: TModalResult;
begin
PkgCompileTool:=Sender as TAbstractExternalTool;
Data:=PkgCompileTool.Data as TLazPkgGraphExtToolData;
aPackage:=Data.Pkg;
//debugln(['TLazPackageGraph.OnExtToolBuildStopped aPackage=',aPackage.IDAsString]);
//debugln(['TLazPackageGraph.ExtToolBuildStopped aPackage=',aPackage.IDAsString]);
// check if main ppu file was created
SrcPPUFile:=Data.SrcPPUFilename;
SrcPPUFileExists:=(SrcPPUFile<>'') and FileExistsUTF8(SrcPPUFile);
SrcF:=Data.SrcPPUFilename;
SrcPPUFileExists:=(SrcF<>'') and FileExistsUTF8(SrcF);
// write state file
MsgResult:=SavePackageCompiledState(APackage,
Data.CompilerFilename,Data.CompilerParams,
@ -2169,8 +2140,8 @@ begin
Data.ErrorMessage:='ConvertPackageRSTFiles failed';
PkgCompileTool.ErrorMessage:=Data.ErrorMessage;
DebugLn('Error: (lazarus) failed to update .po files: ',APackage.IDAsString);
IDEMessagesWindow.AddCustomMessage(mluError,
Format(lisUpdatingPoFilesFailedForPackage, [APackage.IDAsString]));
SrcF:=Format(lisUpdatingPoFilesFailedForPackage, [APackage.IDAsString]);
FOnShowMessage(mluError, SrcF, '', 0, 0, '');
exit;
end;
end;
@ -2533,6 +2504,38 @@ begin
end;
end;
procedure TLazPackageGraph.WarnSuspiciousCompilerOptions(ViewCaption, Target: string;
CompilerParams: TStrings);
var
ParsedParams: TObjectList;
i: Integer;
Param: TFPCParamValue;
Msg: String;
begin
if FOnShowMessage=nil then exit;
ParsedParams:=TObjectList.Create(true);
try
ParseFPCParameters(CompilerParams,ParsedParams);
for i:=0 to ParsedParams.Count-1 do begin
Param:=TFPCParamValue(ParsedParams[i]);
if fpfValueChanged in Param.Flags then begin
Msg:='';
if Param.Kind in [fpkBoolean,fpkValue] then begin
if Param.Name<>'M' then // Many -M options are allowed.
Msg:=Format(lisPassingCompilerOptionTwiceWithDifferentValues, [Param.Name]);
end
else if Param.Kind=fpkDefine then
Msg:=Format(lisPassingCompilerDefineTwiceWithDifferentValues, [Param.Name]);
if Msg='' then continue;
if Target<>'' then Msg:=Target+' '+Msg;
FOnShowMessage(mluNote, Msg, '', 0, 0, ViewCaption);
end;
end;
finally
ParsedParams.Free;
end;
end;
procedure TLazPackageGraph.ClosePackage(APackage: TLazPackage);
begin
if (lpfDestroying in APackage.Flags) or PackageIsNeeded(APackage) then exit;
@ -4499,7 +4502,7 @@ begin
ExtToolData.SrcPPUFilename:=APackage.GetSrcPPUFilename;
ExtToolData.CompilerFilename:=CompilerFilename;
ExtToolData.CompilerParams.Assign(CompilerParams);
PkgCompileTool.AddHandlerOnStopped(@OnExtToolBuildStopped);
PkgCompileTool.AddHandlerOnStopped(@ExtToolBuildStopped);
if BuildItem<>nil then
begin
// run later

View File

@ -143,6 +143,9 @@ type
procedure PackageGraphEndUpdate(Sender: TObject; GraphChanged: boolean);
procedure PackageGraphFindFPCUnit(const AUnitName, Directory: string;
var Filename: string);
function ShowMessageHandler(aUrgency: TMessageLineUrgency;
aMsg, aSrcFilename: string; aLineNumber, aColumn: integer;
aViewCaption: string): TMessageLine;
// menu
procedure MainIDEitmPkgOpenPackageFileClick(Sender: TObject);
procedure MainIDEitmPkgPkgGraphClick(Sender: TObject);
@ -172,8 +175,7 @@ type
Quiet: boolean): TModalResult;
procedure CreateIDEWindow(Sender: TObject; aFormName: string;
var AForm: TCustomForm; DoDisableAutoSizing: boolean);
function PackageGraphSrcEditFileIsModified(const SrcFilename: string
): boolean;
function PackageGraphSrcEditFileIsModified(const SrcFilename: string): boolean;
public
// component palette
procedure IDEComponentPaletteOpenPackage(Sender: TObject); override;
@ -1043,6 +1045,14 @@ begin
Filename:=CodeToolBoss.DirectoryCachePool.FindUnitInUnitLinks(Directory, AUnitName);
end;
function TPkgManager.ShowMessageHandler(aUrgency: TMessageLineUrgency;
aMsg, aSrcFilename: string; aLineNumber, aColumn: integer; aViewCaption: string
): TMessageLine;
begin
Assert(Assigned(IDEMessagesWindow), 'TPkgManager.ShowMessageHandler: IDEMessagesWindow=Nil');
IDEMessagesWindow.AddCustomMessage(aUrgency, aMsg, aSrcFilename, aLineNumber, aColumn, aViewCaption);
end;
function TPkgManager.PackageGraphExplorerUninstallPackage(Sender: TObject;
APackage: TLazPackage): TModalResult;
begin
@ -2898,6 +2908,7 @@ begin
PackageGraph.OnTranslatePackage:=@DoTranslatePackage;
PackageGraph.OnUninstallPackage:=@DoUninstallPackage;
PackageGraph.OnSrcEditFileIsModified:=@PackageGraphSrcEditFileIsModified;
PackageGraph.OnShowMessage:=@ShowMessageHandler;
// package editors
PackageEditors:=TPackageEditors.Create;