IDE: further migration external tools

git-svn-id: trunk@42289 -
This commit is contained in:
mattias 2013-08-03 15:56:10 +00:00
parent b484158b05
commit a7d3638143
5 changed files with 59 additions and 44 deletions

View File

@ -129,7 +129,6 @@ type
function CTMacroFuncProjectUnitPath(Data: Pointer): boolean;
function CTMacroFuncProjectIncPath(Data: Pointer): boolean;
function CTMacroFuncProjectSrcPath(Data: Pointer): boolean;
procedure OnCmdLineCreate(var CmdLine: string; var Abort: boolean);
function OnRunCompilerWithOptions(ExtTool: TIDEExternalToolOptions;
CompOptions: TBaseCompilerOptions): TModalResult;
procedure SetUnitSetCache(const AValue: TFPCUnitSetCache);
@ -492,10 +491,11 @@ end;
procedure TBuildManager.SetupCompilerInterface;
begin
TheCompiler := TCompiler.Create;
{$IFNDEF EnableNewExtTools}
with TheCompiler do begin
OnCommandLineCreate:=@OnCmdLineCreate;
OutputFilter:=TheOutputFilter;
end;
{$ENDIF}
end;
procedure TBuildManager.SetupInputHistories;
@ -2100,12 +2100,6 @@ begin
end;
end;
procedure TBuildManager.OnCmdLineCreate(var CmdLine: string; var Abort: boolean);
// replace all transfer macros in command line
begin
Abort:=not GlobalMacroList.SubstituteStr(CmdLine);
end;
function TBuildManager.OnRunCompilerWithOptions(
ExtTool: TIDEExternalToolOptions; CompOptions: TBaseCompilerOptions): TModalResult;
begin

View File

@ -105,11 +105,9 @@ type
function DoTestAll: TModalResult;
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function RunTool(ExtTool: TExternalToolOptions; ShowAbort: Boolean): TModalResult;
procedure Add(const Msg, CurDir: String; ProgressLine: boolean;
OriginalIndex: integer);
procedure AddMsg(const Msg, CurDir: String; OriginalIndex: integer);
procedure AddProgress(Line: TIDEScanMessageLine);
procedure AddHint(const Msg: string);
procedure AddWarning(const Msg: string);
procedure AddMsg(const Level: TCompilerCheckMsgLvl; const Msg: string);
@ -301,7 +299,11 @@ var
TestDir: String;
BogusFilename: String;
CmdLineParams: String;
{$IFDEF EnableNewExtTools}
CompileTool: TAbstractExternalTool;
{$ELSE}
CompileTool: TExternalToolOptions;
{$ENDIF}
begin
// compile bogus file
FTest:=cotCompileBogusFiles;
@ -330,7 +332,16 @@ begin
CmdLineParams:=Options.MakeOptionsString(BogusFilename,
[ccloAddVerboseAll,ccloDoNotAppendOutFileOption,ccloAbsolutePaths])
+' '+BogusFilename;
{$IFDEF EnableNewExtTools}
CompileTool:=ExternalToolList.Add(dlgCCOTestToolCompilingEmptyFile);
CompileTool.AddParsers(SubToolFPC);
CompileTool.AddParsers(SubToolMake);
CompileTool.Process.CurrentDirectory:=TestDir;
CompileTool.Process.Executable:=CompilerFilename;
CompileTool.CmdLineParams:=CmdLineParams;
CompileTool.Execute;
CompileTool.WaitForExit;
{$ELSE}
CompileTool:=TExternalToolOptions.Create;
CompileTool.Title:=dlgCCOTestToolCompilingEmptyFile;
CompileTool.ScanOutputForFPCMessages:=true;
@ -338,9 +349,10 @@ begin
CompileTool.WorkingDirectory:=TestDir;
CompileTool.Filename:=CompilerFilename;
CompileTool.CmdLineParams:=CmdLineParams;
Result:=RunTool(CompileTool,false);
TestMemo.Lines.Text:=CompileTool.Filename+' '+CompileTool.CmdLineParams;
Result:=EnvironmentOptions.ExternalTools.Run(CompileTool,MacroList,false);
FreeThenNil(CompileTool);
{$ENDIF}
finally
DeleteFileUTF8(BogusFilename);
end;
@ -836,7 +848,11 @@ end;
function TCheckCompilerOptsDlg.DoTestAll: TModalResult;
var
CompilerFilename: String;
{$IFDEF EnableNewExtTools}
CompileTool: TAbstractExternalTool;
{$ELSE}
CompileTool: TExternalToolOptions;
{$ENDIF}
CompilerFiles: TStrings;
FPCCfgUnitPath: string;
TargetUnitPath: String;
@ -976,13 +992,6 @@ begin
inherited Destroy;
end;
function TCheckCompilerOptsDlg.RunTool(ExtTool: TExternalToolOptions;
ShowAbort: Boolean): TModalResult;
begin
TestMemo.Lines.Text:=ExtTool.Filename+' '+ExtTool.CmdLineParams;
Result:=EnvironmentOptions.ExternalTools.Run(ExtTool,MacroList,ShowAbort);
end;
procedure TCheckCompilerOptsDlg.Add(const Msg, CurDir: String;
ProgressLine: boolean; OriginalIndex: integer);
var
@ -1006,11 +1015,6 @@ begin
Add(Msg,CurDir,false,OriginalIndex);
end;
procedure TCheckCompilerOptsDlg.AddProgress(Line: TIDEScanMessageLine);
begin
Add(Line.Line,Line.WorkingDirectory,false,Line.LineNumber);
end;
procedure TCheckCompilerOptsDlg.AddHint(const Msg: string);
begin
AddMsg(ccmlHint,Msg);

View File

@ -44,7 +44,7 @@ uses
{$ELSE}
OutputFilter,
{$ENDIF}
UTF8Process, InfoBuild, IDEMsgIntf, CompOptsIntf;
UTF8Process, InfoBuild, IDEMsgIntf, CompOptsIntf, IDEExternToolIntf;
type
TOnCmdLineCreate = procedure(var CmdLine: string; var Abort:boolean) of object;
@ -54,8 +54,10 @@ type
TCompiler = class(TObject)
private
FOnCmdLineCreate : TOnCmdLineCreate;
{$IFNDEF EnableNewExtTools}
FOutputFilter: TOutputFilter;
FTheProcess: TProcessUTF8;
{$ENDIF}
public
constructor Create;
destructor Destroy; override;
@ -64,10 +66,10 @@ type
BuildAll, SkipLinking, SkipAssembler: boolean
): TModalResult;
procedure WriteError(const Msg: string);
property OnCommandLineCreate: TOnCmdLineCreate read FOnCmdLineCreate
write FOnCmdLineCreate;
{$IFNDEF EnableNewExtTools}
property OutputFilter: TOutputFilter read FOutputFilter write FOutputFilter;
property TheProcess: TProcessUTF8 read FTheProcess;
{$ENDIF}
end;
// Following classes are for compiler options parsed from "fpc -h" and "fpc -i".
@ -211,7 +213,9 @@ end;
------------------------------------------------------------------------------}
destructor TCompiler.Destroy;
begin
{$IFNDEF EnableNewExtTools}
FreeAndNil(FTheProcess);
{$ENDIF}
inherited Destroy;
end;
@ -225,6 +229,9 @@ function TCompiler.Compile(AProject: TProject;
var
CmdLine : String;
Abort : Boolean;
{$IFDEF EnableNewExtTools}
Tool: TAbstractExternalTool;
{$ENDIF}
begin
Result:=mrCancel;
if ConsoleVerbosity>=0 then
@ -233,27 +240,18 @@ begin
// if we want to show the compile progress, it's now time to show the dialog
CompileProgress.Show;
CmdLine := CompilerFilename;
if Assigned(FOnCmdLineCreate) then begin
Abort:=false;
FOnCmdLineCreate(CmdLine,Abort);
if Abort then begin
Result:=mrAbort;
exit;
end;
end;
try
CheckIfFileIsExecutable(CmdLine);
CheckIfFileIsExecutable(CompilerFilename);
except
on E: Exception do begin
WriteError(Format(lisCompilerErrorInvalidCompiler, [E.Message]));
if CmdLine='' then begin
if CompilerFilename='' then begin
WriteError(lisCompilerHintYouCanSetTheCompilerPath);
end;
exit;
end;
end;
CmdLine := '';
if BuildAll then
CmdLine := CmdLine+' -B';
if SkipLinking and SkipAssembler then
@ -262,7 +260,7 @@ begin
CmdLine := CmdLine+' -Cn';
if CompilerParams<>'' then
CmdLine := CmdLine+' '+CompilerParams;
CmdLine := CmdLine+' '+CompilerParams;
if Assigned(FOnCmdLineCreate) then begin
Abort:=false;
FOnCmdLineCreate(CmdLine,Abort);
@ -274,6 +272,18 @@ begin
if ConsoleVerbosity>=0 then
DebugLn('[TCompiler.Compile] CmdLine="',CmdLine,'"');
{$IFDEF EnableNewExtTools}
Tool:=ExternalToolList.Add('Compling Project');
Tool.Process.Executable:=CompilerFilename;
Tool.CmdLineParams:=CmdLine;
Tool.Process.CurrentDirectory:=WorkingDir;
Tool.AddParsers(SubToolFPC);
Tool.AddParsers(SubToolMake);
Tool.Execute;
Tool.WaitForExit;
if Tool.ErrorMessage='' then
Result:=mrOK;
{$ELSE}
try
if TheProcess=nil then
FTheProcess := TOutputFilterProcess.Create(nil);
@ -321,6 +331,7 @@ begin
exit;
end;
end;
{$ENDIF}
if ConsoleVerbosity>=0 then
DebugLn('[TCompiler.Compile] end');
end;
@ -328,11 +339,15 @@ end;
procedure TCompiler.WriteError(const Msg: string);
begin
DebugLn('TCompiler.WriteError ',Msg);
{$IFDEF EnableNewExtTools}
if IDEMessagesWindow<>nil then
IDEMessagesWindow.AddCustomMessage(mluError,Msg);
{$ELSE}
if OutputFilter <> nil then
OutputFilter.ReadConstLine(Msg, True);
{$ENDIF}
end;
// Compiler options parsed from "fpc -h" and "fpc -i".
var

View File

@ -25,7 +25,7 @@ unit CustomDefines;
interface
uses
Classes, Forms, StdCtrls, Buttons, ButtonPanel, CheckLst, LCLType,
Classes, Forms, StdCtrls, Buttons, ButtonPanel, CheckLst, LCLType, Controls,
IDEHelpIntf, LazarusIDEStrConsts, Compiler;
type
@ -169,6 +169,7 @@ begin
end;
DefinesCheckList.Checked[ListInd] := True;
end;
Result:=mrOK;
end;
function TCustomDefinesForm.ToCustomOptions(aStrings: TStrings): TModalResult;
@ -184,6 +185,7 @@ begin
if Checked[i] then begin
aStrings.Add('-d' + Items[i]);
end;
Result:=mrOk;
end;
end.

View File

@ -107,7 +107,7 @@ type
read fOnNeedsOutputFilter write fOnNeedsOutputFilter;
end;
{$ENDIF EnableNewExtTools}
type
{ TExternalToolDialog -
the dialog to edit all external tools }