mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-11 23:39:09 +02:00
IDE: refactoring for functions that build Lazarus. Make them a class, but don't move parameters to private vars yet.
git-svn-id: trunk@43994 -
This commit is contained in:
parent
1e92012ce1
commit
9cff7878ec
@ -15,7 +15,7 @@ object ConfigureBuildLazarusDlg: TConfigureBuildLazarusDlg
|
||||
OnResize = FormResize
|
||||
OnShow = FormShow
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.1'
|
||||
LCLVersion = '1.3'
|
||||
object CBLDBtnPanel: TPanel
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 0
|
||||
@ -359,12 +359,11 @@ object ConfigureBuildLazarusDlg: TConfigureBuildLazarusDlg
|
||||
Height = 15
|
||||
Top = 345
|
||||
Width = 684
|
||||
AutoSize = True
|
||||
Caption = 'CommonsDividerBevel'
|
||||
Anchors = [akLeft, akRight, akBottom]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Right = 6
|
||||
BorderSpacing.Bottom = 6
|
||||
Caption = 'CommonsDividerBevel'
|
||||
Font.Style = [fsBold]
|
||||
ParentFont = False
|
||||
end
|
||||
|
@ -146,23 +146,28 @@ type
|
||||
procedure UpdateProfileNamesUI;
|
||||
end;
|
||||
|
||||
function ShowConfigureBuildLazarusDlg(AProfiles: TBuildLazarusProfiles): TModalResult;
|
||||
{ TLazarusBuilder }
|
||||
|
||||
function MakeLazarus(Profile: TBuildLazarusProfile;
|
||||
{$IFNDEF EnableNewExtTools}ExternalTools: TBaseExternalToolList;{$ENDIF}
|
||||
Macros: TTransferMacroList;
|
||||
const PackageOptions, CompilerPath, MakePath: string;
|
||||
Flags: TBuildLazarusFlags; var ProfileChanged: boolean): TModalResult;
|
||||
TLazarusBuilder = class
|
||||
private
|
||||
function CreateIDEMakeOptions(Profile: TBuildLazarusProfile;
|
||||
Macros: TTransferMacroList; const PackageOptions: string;
|
||||
Flags: TBuildLazarusFlags; var ExtraOptions: string;
|
||||
out UpdateRevisionInc: boolean; out OutputDirRedirected: boolean;
|
||||
out TargetFilename: string): TModalResult;
|
||||
public
|
||||
function ShowConfigureBuildLazarusDlg(AProfiles: TBuildLazarusProfiles): TModalResult;
|
||||
|
||||
function CreateIDEMakeOptions(Profile: TBuildLazarusProfile;
|
||||
Macros: TTransferMacroList; const PackageOptions: string;
|
||||
Flags: TBuildLazarusFlags; var ExtraOptions: string;
|
||||
out UpdateRevisionInc: boolean; out OutputDirRedirected: boolean;
|
||||
out TargetFilename: string): TModalResult;
|
||||
function MakeLazarus(Profile: TBuildLazarusProfile;
|
||||
{$IFNDEF EnableNewExtTools}ExternalTools: TBaseExternalToolList;{$ENDIF}
|
||||
Macros: TTransferMacroList;
|
||||
const PackageOptions, CompilerPath, MakePath: string;
|
||||
Flags: TBuildLazarusFlags; var ProfileChanged: boolean): TModalResult;
|
||||
|
||||
function SaveIDEMakeOptions(Profile: TBuildLazarusProfile;
|
||||
Macros: TTransferMacroList;
|
||||
const PackageOptions: string; Flags: TBuildLazarusFlags): TModalResult;
|
||||
function SaveIDEMakeOptions(Profile: TBuildLazarusProfile;
|
||||
Macros: TTransferMacroList;
|
||||
const PackageOptions: string; Flags: TBuildLazarusFlags): TModalResult;
|
||||
end;
|
||||
|
||||
function GetMakeIDEConfigFilename: string;
|
||||
function GetBackupExeFilename(Filename: string): string;
|
||||
@ -174,7 +179,22 @@ implementation
|
||||
const
|
||||
DefaultIDEMakeOptionFilename = 'idemake.cfg';
|
||||
|
||||
function ShowConfigureBuildLazarusDlg(AProfiles: TBuildLazarusProfiles): TModalResult;
|
||||
function GetMakeIDEConfigFilename: string;
|
||||
begin
|
||||
Result:=AppendPathDelim(GetPrimaryConfigPath)+DefaultIDEMakeOptionFilename;
|
||||
end;
|
||||
|
||||
function GetBackupExeFilename(Filename: string): string;
|
||||
var
|
||||
Ext: String;
|
||||
begin
|
||||
Ext:=ExtractFileExt(Filename);
|
||||
Result:=LeftStr(Filename,length(Filename)-length(Ext))+'.old'+Ext;
|
||||
end;
|
||||
|
||||
{ TLazarusBuilder }
|
||||
|
||||
function TLazarusBuilder.ShowConfigureBuildLazarusDlg(AProfiles: TBuildLazarusProfiles): TModalResult;
|
||||
// mrOk=save
|
||||
// mrYes=save and compile
|
||||
// mrAll=save and compile all selected profiles
|
||||
@ -193,7 +213,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function MakeLazarus(Profile: TBuildLazarusProfile;
|
||||
function TLazarusBuilder.MakeLazarus(Profile: TBuildLazarusProfile;
|
||||
{$IFNDEF EnableNewExtTools}ExternalTools: TBaseExternalToolList;{$ENDIF}
|
||||
Macros: TTransferMacroList;
|
||||
const PackageOptions, CompilerPath, MakePath: string;
|
||||
@ -475,7 +495,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function CreateIDEMakeOptions(Profile: TBuildLazarusProfile;
|
||||
function TLazarusBuilder.CreateIDEMakeOptions(Profile: TBuildLazarusProfile;
|
||||
Macros: TTransferMacroList; const PackageOptions: string;
|
||||
Flags: TBuildLazarusFlags; var ExtraOptions: string;
|
||||
out UpdateRevisionInc: boolean; out OutputDirRedirected: boolean;
|
||||
@ -778,7 +798,7 @@ begin
|
||||
//DebugLn(['CreateBuildLazarusOptions ',MMDef.Name,' ',ExtraOptions]);
|
||||
end;
|
||||
|
||||
function SaveIDEMakeOptions(Profile: TBuildLazarusProfile;
|
||||
function TLazarusBuilder.SaveIDEMakeOptions(Profile: TBuildLazarusProfile;
|
||||
Macros: TTransferMacroList;
|
||||
const PackageOptions: string; Flags: TBuildLazarusFlags): TModalResult;
|
||||
|
||||
@ -867,19 +887,6 @@ begin
|
||||
Result:=mrOk;
|
||||
end;
|
||||
|
||||
function GetMakeIDEConfigFilename: string;
|
||||
begin
|
||||
Result:=AppendPathDelim(GetPrimaryConfigPath)+DefaultIDEMakeOptionFilename;
|
||||
end;
|
||||
|
||||
function GetBackupExeFilename(Filename: string): string;
|
||||
var
|
||||
Ext: String;
|
||||
begin
|
||||
Ext:=ExtractFileExt(Filename);
|
||||
Result:=LeftStr(Filename,length(Filename)-length(Ext))+'.old'+Ext;
|
||||
end;
|
||||
|
||||
{ TConfigureBuildLazarusDlg }
|
||||
|
||||
constructor TConfigureBuildLazarusDlg.Create(TheOwner: TComponent);
|
||||
|
101
ide/lazbuild.lpr
101
ide/lazbuild.lpr
@ -519,6 +519,7 @@ var
|
||||
i: Integer;
|
||||
s: String;
|
||||
ProfileChanged: boolean;
|
||||
Builder: TLazarusBuilder;
|
||||
begin
|
||||
Result:=false;
|
||||
if not Init then exit;
|
||||
@ -588,63 +589,67 @@ begin
|
||||
end;
|
||||
|
||||
// clean
|
||||
ProfileChanged:=false;
|
||||
if BuildLazProfiles.Current.IdeBuildMode=bmCleanAllBuild then begin
|
||||
CurResult:=MakeLazarus(BuildLazProfiles.Current,
|
||||
EnvironmentOptions.ExternalTools,GlobalMacroList,
|
||||
'',EnvironmentOptions.GetParsedCompilerFilename,
|
||||
EnvironmentOptions.GetParsedMakeFilename,
|
||||
Flags+[blfDontBuild],
|
||||
ProfileChanged);
|
||||
Builder:=TLazarusBuilder.Create;
|
||||
try
|
||||
ProfileChanged:=false;
|
||||
if BuildLazProfiles.Current.IdeBuildMode=bmCleanAllBuild then begin
|
||||
CurResult:=Builder.MakeLazarus(BuildLazProfiles.Current,
|
||||
EnvironmentOptions.ExternalTools,GlobalMacroList,
|
||||
'',EnvironmentOptions.GetParsedCompilerFilename,
|
||||
EnvironmentOptions.GetParsedMakeFilename,
|
||||
Flags+[blfDontBuild],ProfileChanged);
|
||||
if CurResult<>mrOk then begin
|
||||
if ConsoleVerbosity>=-1 then
|
||||
DebugLn('TLazBuildApplication.BuildLazarusIDE: Clean all failed.');
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
// save configs for 'make'
|
||||
CurResult:=PackageGraph.SaveAutoInstallConfig;
|
||||
if CurResult<>mrOk then begin
|
||||
if ConsoleVerbosity>=-1 then
|
||||
DebugLn('TLazBuildApplication.BuildLazarusIDE: Clean all failed.');
|
||||
DebugLn('TLazBuildApplication.BuildLazarusIDE: failed saving IDE make config files.');
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
// save configs for 'make'
|
||||
CurResult:=PackageGraph.SaveAutoInstallConfig;
|
||||
if CurResult<>mrOk then begin
|
||||
if ConsoleVerbosity>=-1 then
|
||||
DebugLn('TLazBuildApplication.BuildLazarusIDE: failed saving IDE make config files.');
|
||||
exit;
|
||||
end;
|
||||
// compile auto install static packages
|
||||
if not CompileAutoInstallPackages(BuildLazProfiles.Current.IdeBuildMode<>bmBuild)
|
||||
then begin
|
||||
if ConsoleVerbosity>=-1 then
|
||||
DebugLn('TLazBuildApplication.BuildLazarusIDE: Compile AutoInstall Packages failed.');
|
||||
exit;
|
||||
end;
|
||||
|
||||
// compile auto install static packages
|
||||
if not CompileAutoInstallPackages(BuildLazProfiles.Current.IdeBuildMode<>bmBuild)
|
||||
then begin
|
||||
if ConsoleVerbosity>=-1 then
|
||||
DebugLn('TLazBuildApplication.BuildLazarusIDE: Compile AutoInstall Packages failed.');
|
||||
exit;
|
||||
end;
|
||||
|
||||
// create inherited compiler options
|
||||
PkgOptions:=PackageGraph.GetIDEInstallPackageOptions(InheritedOptionStrings{%H-});
|
||||
// create inherited compiler options
|
||||
PkgOptions:=PackageGraph.GetIDEInstallPackageOptions(InheritedOptionStrings{%H-});
|
||||
|
||||
// save
|
||||
CurResult:=SaveIDEMakeOptions(BuildLazProfiles.Current,GlobalMacroList,
|
||||
PkgOptions,Flags+[blfBackupOldExe]);
|
||||
if CurResult<>mrOk then begin
|
||||
if ConsoleVerbosity>=-1 then
|
||||
DebugLn('TLazBuildApplication.BuildLazarusIDE: failed saving idemake.cfg');
|
||||
exit;
|
||||
end;
|
||||
// save
|
||||
CurResult:=Builder.SaveIDEMakeOptions(BuildLazProfiles.Current,GlobalMacroList,
|
||||
PkgOptions,Flags+[blfBackupOldExe]);
|
||||
if CurResult<>mrOk then begin
|
||||
if ConsoleVerbosity>=-1 then
|
||||
DebugLn('TLazBuildApplication.BuildLazarusIDE: failed saving idemake.cfg');
|
||||
exit;
|
||||
end;
|
||||
|
||||
// compile IDE
|
||||
CurResult:=MakeLazarus(BuildLazProfiles.Current,
|
||||
EnvironmentOptions.ExternalTools,GlobalMacroList,
|
||||
PkgOptions,EnvironmentOptions.GetParsedCompilerFilename,
|
||||
EnvironmentOptions.GetParsedMakeFilename,
|
||||
Flags+[blfUseMakeIDECfg,blfOnlyIDE],
|
||||
ProfileChanged);
|
||||
if CurResult<>mrOk then begin
|
||||
if ConsoleVerbosity>=-1 then
|
||||
DebugLn('TLazBuildApplication.BuildLazarusIDE: Building IDE failed.');
|
||||
exit;
|
||||
end;
|
||||
// compile IDE
|
||||
CurResult:=Builder.MakeLazarus(BuildLazProfiles.Current,
|
||||
EnvironmentOptions.ExternalTools,GlobalMacroList,
|
||||
PkgOptions,EnvironmentOptions.GetParsedCompilerFilename,
|
||||
EnvironmentOptions.GetParsedMakeFilename,
|
||||
Flags+[blfUseMakeIDECfg,blfOnlyIDE],
|
||||
ProfileChanged);
|
||||
if CurResult<>mrOk then begin
|
||||
if ConsoleVerbosity>=-1 then
|
||||
DebugLn('TLazBuildApplication.BuildLazarusIDE: Building IDE failed.');
|
||||
exit;
|
||||
end;
|
||||
|
||||
Result:=true;
|
||||
Result:=true;
|
||||
finally
|
||||
Builder.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TLazBuildApplication.CompileAutoInstallPackages(Clean: boolean): boolean;
|
||||
|
32
ide/main.pp
32
ide/main.pp
@ -391,6 +391,7 @@ type
|
||||
procedure mnuChgBuildModeClicked(Sender: TObject);
|
||||
procedure mnuSetBuildModeClick(Sender: TObject); // event for drop down items
|
||||
private
|
||||
fBuilder: TLazarusBuilder;
|
||||
function DoBuildLazarusSub(Flags: TBuildLazarusFlags): TModalResult;
|
||||
{$IFNDEF EnableNewExtTools}
|
||||
function ExternalTools: TExternalToolList;
|
||||
@ -4656,8 +4657,10 @@ var
|
||||
DlgResult: TModalResult;
|
||||
begin
|
||||
MainBuildBoss.SetBuildTargetIDE;
|
||||
fBuilder := TLazarusBuilder.Create; // Build profile is not known yet.
|
||||
try
|
||||
DlgResult:=ShowConfigureBuildLazarusDlg(MiscellaneousOptions.BuildLazProfiles);
|
||||
try
|
||||
DlgResult:=fBuilder.ShowConfigureBuildLazarusDlg(MiscellaneousOptions.BuildLazProfiles);
|
||||
finally
|
||||
MainBuildBoss.SetBuildTargetProject1(true);
|
||||
end;
|
||||
@ -4684,6 +4687,9 @@ begin
|
||||
DoBuildLazarus([]);
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
FreeAndNil(fBuilder);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainIDE.mnuCustomExtToolClick(Sender: TObject);
|
||||
@ -7564,6 +7570,7 @@ var
|
||||
PkgOptions: string;
|
||||
InheritedOptionStrings: TInheritedCompOptsStrings;
|
||||
FPCVersion, FPCRelease, FPCPatch: integer;
|
||||
Builder: TLazarusBuilder;
|
||||
begin
|
||||
// create uses section addition for lazarus.pp
|
||||
Result:=PkgBoss.DoSaveAutoInstallConfig;
|
||||
@ -7581,9 +7588,13 @@ begin
|
||||
if (FPCVersion=0) or (FPCRelease=0) or (FPCPatch=0) then ;
|
||||
|
||||
// save extra options
|
||||
Result:=SaveIDEMakeOptions(MiscellaneousOptions.BuildLazProfiles.Current,
|
||||
GlobalMacroList,PkgOptions,Flags+[blfOnlyIDE]);
|
||||
if Result<>mrOk then exit;
|
||||
Builder:=TLazarusBuilder.Create;
|
||||
try
|
||||
Result:=Builder.SaveIDEMakeOptions(MiscellaneousOptions.BuildLazProfiles.Current,
|
||||
GlobalMacroList,PkgOptions,Flags+[blfOnlyIDE]);
|
||||
finally
|
||||
Builder.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TMainIDE.DoExampleManager: TModalResult;
|
||||
@ -7600,6 +7611,7 @@ var
|
||||
FPCVersion, FPCRelease, FPCPatch: integer;
|
||||
PkgCompileFlags: TPkgCompileFlags;
|
||||
ProfileChanged: Boolean;
|
||||
BuilderCreated: Boolean;
|
||||
begin
|
||||
if ToolStatus<>itNone then begin
|
||||
IDEMessageDialog(lisNotNow,
|
||||
@ -7615,6 +7627,9 @@ begin
|
||||
exit;
|
||||
end;
|
||||
|
||||
BuilderCreated := fBuilder = Nil;
|
||||
if BuilderCreated then
|
||||
fBuilder:=TLazarusBuilder.Create;
|
||||
{$IFNDEF EnableNewExtTools}
|
||||
MessagesView.BeginBlock;
|
||||
{$ENDIF}
|
||||
@ -7630,7 +7645,7 @@ begin
|
||||
PkgCompileFlags:=PkgCompileFlags+[pcfCompileDependenciesClean];
|
||||
if BuildLazProfiles.Current.IdeBuildMode=bmCleanAllBuild then begin
|
||||
SourceEditorManager.ClearErrorLines;
|
||||
Result:=MakeLazarus(BuildLazProfiles.Current,
|
||||
Result:=fBuilder.MakeLazarus(BuildLazProfiles.Current,
|
||||
{$IFNDEF EnableNewExtTools}ExternalTools,{$ENDIF}
|
||||
GlobalMacroList,
|
||||
'',EnvironmentOptions.GetParsedCompilerFilename,
|
||||
@ -7676,7 +7691,7 @@ begin
|
||||
|
||||
// save extra options
|
||||
IDEBuildFlags:=Flags;
|
||||
Result:=SaveIDEMakeOptions(BuildLazProfiles.Current,GlobalMacroList,PkgOptions,
|
||||
Result:=fBuilder.SaveIDEMakeOptions(BuildLazProfiles.Current,GlobalMacroList,PkgOptions,
|
||||
IDEBuildFlags-[blfUseMakeIDECfg,blfDontClean]+[blfBackupOldExe]);
|
||||
if Result<>mrOk then begin
|
||||
DebugLn('TMainIDE.DoBuildLazarus: Save IDEMake options failed.');
|
||||
@ -7686,7 +7701,7 @@ begin
|
||||
// make lazarus ide
|
||||
SourceEditorManager.ClearErrorLines;
|
||||
IDEBuildFlags:=IDEBuildFlags+[blfUseMakeIDECfg,blfDontClean];
|
||||
Result:=MakeLazarus(BuildLazProfiles.Current,
|
||||
Result:=fBuilder.MakeLazarus(BuildLazProfiles.Current,
|
||||
{$IFNDEF EnableNewExtTools}ExternalTools,{$ENDIF}
|
||||
GlobalMacroList,
|
||||
PkgOptions,EnvironmentOptions.GetParsedCompilerFilename,
|
||||
@ -7697,8 +7712,9 @@ begin
|
||||
if ProfileChanged then
|
||||
MiscellaneousOptions.Save;
|
||||
finally
|
||||
if BuilderCreated then
|
||||
FreeAndNil(fBuilder);
|
||||
MainBuildBoss.SetBuildTargetProject1(true);
|
||||
|
||||
DoCheckFilesOnDisk;
|
||||
{$IFNDEF EnableNewExtTools}
|
||||
MessagesView.EndBlock;
|
||||
|
Loading…
Reference in New Issue
Block a user