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 // LCL
Forms, Forms,
// LazUtils // LazUtils
IDEExternToolIntf, LazLoggerBase, LazLoggerBase,
// BuildIntf
IDEExternToolIntf,
// IdeIntf // IdeIntf
MenuIntf; MenuIntf;

View File

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

View File

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

View File

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