IDE: Remove IdeIntf dependency from unit Compiler.

This commit is contained in:
Juha 2025-07-25 07:45:38 +03:00
parent c385c1e079
commit 86043a9919
3 changed files with 26 additions and 22 deletions

View File

@ -51,7 +51,7 @@ uses
// IDEIntf // IDEIntf
IDEDialogs, LazIDEIntf, IDEMsgIntf, SrcEditorIntf, InputHistory, IDEDialogs, LazIDEIntf, IDEMsgIntf, SrcEditorIntf, InputHistory,
// IdeUtils // IdeUtils
IdeUtilsPkgStrConsts, IdeUtilsPkgStrConsts, DialogProcs,
// IdeConfig // IdeConfig
LazConf, EnvironmentOpts, ModeMatrixOpts, TransferMacros, IdeConfStrConsts, LazConf, EnvironmentOpts, ModeMatrixOpts, TransferMacros, IdeConfStrConsts,
IDEProcs, etMakeMsgParser, etFPCMsgFilePool, ParsedCompilerOpts, CompilerOptions, IDEProcs, etMakeMsgParser, etFPCMsgFilePool, ParsedCompilerOpts, CompilerOptions,
@ -59,7 +59,7 @@ uses
// IdePackager // IdePackager
IdePackagerStrConsts, IdePackagerStrConsts,
// IDE // IDE
LazarusIDEStrConsts, DialogProcs, ProjectResources, LazarusIDEStrConsts, ProjectResources,
MiscOptions, ExtTools, etFPCMsgParser, etPas2jsMsgParser, Compiler, MiscOptions, ExtTools, etFPCMsgParser, etPas2jsMsgParser, Compiler,
FPCSrcScan, PackageDefs, PackageSystem, Project, ProjectIcon, BaseBuildManager, FPCSrcScan, PackageDefs, PackageSystem, Project, ProjectIcon, BaseBuildManager,
ApplicationBundle, IdeTransferMacros, SearchPathProcs, RunParamOptions; ApplicationBundle, IdeTransferMacros, SearchPathProcs, RunParamOptions;
@ -188,6 +188,7 @@ type
procedure OnProjectDestroy(Sender: TObject); procedure OnProjectDestroy(Sender: TObject);
procedure SetUnitSetCache(const AValue: TFPCUnitSetCache); procedure SetUnitSetCache(const AValue: TFPCUnitSetCache);
function GetProjectDefaultNamespace: string; // read .lpr file function GetProjectDefaultNamespace: string; // read .lpr file
procedure WriteError(const Msg: string);
protected protected
// command line overrides // command line overrides
OverrideTargetOS: string; OverrideTargetOS: string;
@ -614,6 +615,13 @@ begin
tr('EncloseBracket', lisTMFunctionEncloseBrackets); tr('EncloseBracket', lisTMFunctionEncloseBrackets);
end; end;
procedure TBuildManager.WriteError(const Msg: string);
begin
DebugLn(Msg,' [TBuildManager.WriteError]');
if IDEMessagesWindow<>nil then
IDEMessagesWindow.AddCustomMessage(mluError,Msg);
end;
procedure TBuildManager.SetupExternalTools(aToolsClass: TExternalToolsClass); procedure TBuildManager.SetupExternalTools(aToolsClass: TExternalToolsClass);
var var
Tools: TExternalTools; Tools: TExternalTools;
@ -635,6 +643,7 @@ end;
procedure TBuildManager.SetupCompilerInterface; procedure TBuildManager.SetupCompilerInterface;
begin begin
TheCompiler := TCompiler.Create; TheCompiler := TCompiler.Create;
TheCompiler.OnWriteError := @WriteError;
end; end;
procedure TBuildManager.SetupInputHistories(aInputHist: TInputHistories); procedure TBuildManager.SetupInputHistories(aInputHist: TInputHistories);

View File

@ -44,22 +44,21 @@ uses
// Codetools // Codetools
DefineTemplates, LinkScanner, CodeToolManager, DefineTemplates, LinkScanner, CodeToolManager,
// BuildIntf // BuildIntf
IDEExternToolIntf, IDEExternToolIntf, CompOptsIntf,
// IdeIntf
IDEMsgIntf, LazIDEIntf, CompOptsIntf,
// IdeConfig // IdeConfig
TransferMacros, IDECmdLine, CompilerOptions, TransferMacros, IDECmdLine, CompilerOptions,
// IDE // IDE
LazarusIDEStrConsts, Project; LazarusIDEStrConsts, Project;
type type
TOnCmdLineCreate = procedure(var CmdLine: string; var Abort:boolean) of object; //TOnCmdLineCreate = procedure(var CmdLine: string; var Abort:boolean) of object;
TOnWriteError = procedure(const Msg: string) of object;
{ TCompiler } { TCompiler }
TCompiler = class(TObject) TCompiler = class(TObject)
private private
procedure WriteError(const Msg: string); FOnWriteError: TOnWriteError;
public public
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
@ -67,6 +66,7 @@ type
const WorkingDir, CompilerFilename: string; CompilerParams: TStrings; const WorkingDir, CompilerFilename: string; CompilerParams: TStrings;
BuildAll, SkipLinking, SkipAssembler, CurrentDirectoryIsTestDir: boolean; BuildAll, SkipLinking, SkipAssembler, CurrentDirectoryIsTestDir: boolean;
const aCompileHint: string): TModalResult; const aCompileHint: string): TModalResult;
property OnWriteError: TOnWriteError read FOnWriteError write FOnWriteError;
end; end;
// Following classes are for compiler options parsed from "fpc -h" and "fpc -i". // Following classes are for compiler options parsed from "fpc -h" and "fpc -i".
@ -296,9 +296,10 @@ begin
CheckIfFileIsExecutable(CompilerFilename); CheckIfFileIsExecutable(CompilerFilename);
except except
on E: Exception do begin on E: Exception do begin
WriteError(Format(lisCompilerErrorInvalidCompiler, [E.Message])); if Assigned(OnWriteError) then begin
if CompilerFilename='' then begin OnWriteError(Format(lisCompilerErrorInvalidCompiler, [E.Message]));
WriteError(lisCompilerHintYouCanSetTheCompilerPath); if CompilerFilename='' then
OnWriteError(lisCompilerHintYouCanSetTheCompilerPath);
end; end;
exit; exit;
end; end;
@ -356,13 +357,6 @@ begin
DebugLn('Info: (lazarus) [TCompiler.Compile] end'); DebugLn('Info: (lazarus) [TCompiler.Compile] end');
end; end;
procedure TCompiler.WriteError(const Msg: string);
begin
DebugLn(Msg,' [TCompiler.WriteError]');
if IDEMessagesWindow<>nil then
IDEMessagesWindow.AddCustomMessage(mluError,Msg);
end;
// Compiler options parsed from "fpc -h" and "fpc -i". // Compiler options parsed from "fpc -h" and "fpc -i".
var var
@ -848,9 +842,9 @@ function TCompilerOptSet.SelectOptions(aOptAndValue: string): boolean;
// -Criot // -Criot
// -vbnm6060,5087 // -vbnm6060,5087
var var
i, Start, j: Integer; i, j: Integer;
OneOpt, NumberValue: string; NumberValue: string;
OptOk, Negate: Boolean; Negate: Boolean;
c: Char; c: Char;
Item, NumberOpt: TCompilerOpt; Item, NumberOpt: TCompilerOpt;
Bools: array of char; // '+' = on, '-' = off, else not set Bools: array of char; // '+' = on, '-' = off, else not set
@ -1496,7 +1490,7 @@ procedure TCompilerOptThread.StartParsing;
begin begin
if fStartedOnce then if fStartedOnce then
WaitFor; WaitFor;
fReader.CompilerExecutable:=LazarusIDE.GetCompilerFilename; Assert(fReader.CompilerExecutable<>'', 'TCompilerOptThread.StartParsing: CompilerExecutable should be set by caller.');
fReader.UpdateTargetParam; fReader.UpdateTargetParam;
Start; Start;
fStartedOnce:=true; fStartedOnce:=true;

View File

@ -38,7 +38,7 @@ uses
// BuildIntf // BuildIntf
IDEOptionsIntf, CompOptsIntf, IDEOptionsIntf, CompOptsIntf,
// IdeIntf // IdeIntf
IDEOptEditorIntf, IDECommands, IDEOptEditorIntf, IDECommands, LazIDEIntf,
// SynEdit // SynEdit
SynEdit, SynEditKeyCmds, SynCompletion, SynEdit, SynEditKeyCmds, SynCompletion,
// IdeConfig // IdeConfig
@ -409,6 +409,7 @@ begin
end; end;
end end
else begin else begin
FOptionsReader.CompilerExecutable:=LazarusIDE.GetCompilerFilename;
fOptionsThread := TCompilerOptThread.Create(FOptionsReader); fOptionsThread := TCompilerOptThread.Create(FOptionsReader);
fOptionsThread.StartParsing; fOptionsThread.StartParsing;
end; end;