From 1b48dc89de30945cfac2ef41cf317f5b837d869b Mon Sep 17 00:00:00 2001 From: mattias Date: Fri, 7 Jan 2011 18:42:24 +0000 Subject: [PATCH] IDE: replaced globaloptions with macros, bug #18179, #18421, #18143 git-svn-id: trunk@28897 - --- ide/buildmanager.pas | 2 -- ide/buildprofilemanager.pas | 13 -------- ide/checkcompileropts.pas | 2 +- ide/compileroptions.pp | 64 +++++++++++-------------------------- ide/main.pp | 2 +- ide/project.pp | 18 ----------- ide/showcompileropts.pas | 2 +- packager/basepkgmanager.pas | 3 +- packager/packagesystem.pas | 27 ++++++---------- packager/pkgmanager.pas | 22 ++++--------- 10 files changed, 39 insertions(+), 116 deletions(-) diff --git a/ide/buildmanager.pas b/ide/buildmanager.pas index 96e342027a..3f5b822bd7 100644 --- a/ide/buildmanager.pas +++ b/ide/buildmanager.pas @@ -1874,7 +1874,6 @@ var NewLCLWidgetSet: String; begin with MiscellaneousOptions do begin - BuildLazProfiles.UpdateGlobals; NewTargetOS:=BuildLazOpts.TargetOS; NewTargetCPU:=BuildLazOpts.TargetCPU; NewLCLWidgetSet:=LCLPlatformDirNames[BuildLazOpts.TargetPlatform]; @@ -1895,7 +1894,6 @@ var BuildIDE: Boolean; begin with MiscellaneousOptions do begin - BuildLazProfiles.UpdateGlobals; NewTargetOS:=LowerCase(BuildLazOpts.TargetOS); NewTargetCPU:=LowerCase(BuildLazOpts.TargetCPU); NewLCLWidgetSet:=BuildLazOpts.TargetPlatform; diff --git a/ide/buildprofilemanager.pas b/ide/buildprofilemanager.pas index 455eef5a6f..b947011f95 100644 --- a/ide/buildprofilemanager.pas +++ b/ide/buildprofilemanager.pas @@ -159,7 +159,6 @@ type TBuildLazarusProfiles = class(TObjectList) private - fGlobals: TGlobalCompilerOptions; fMakeModeDefs: TMakeModeDefs; fRestartAfterBuild: boolean; fConfirmBuild: boolean; @@ -180,9 +179,7 @@ type procedure Load(XMLConfig: TXMLConfig; const Path: string; const FileVersion: integer); procedure Save(XMLConfig: TXMLConfig; const Path: string); procedure Move(CurIndex, NewIndex: Integer); // Replaces TList.Move - procedure UpdateGlobals; public - property Globals: TGlobalCompilerOptions read fGlobals; property MakeModeDefs: TMakeModeDefs read fMakeModeDefs; property RestartAfterBuild: boolean read fRestartAfterBuild write fRestartAfterBuild; property ConfirmBuild: boolean read fConfirmBuild write fConfirmBuild; @@ -551,7 +548,6 @@ end; constructor TBuildLazarusProfiles.Create; begin inherited Create; - fGlobals:=TGlobalCompilerOptions.Create; fMakeModeDefs:=TMakeModeDefs.Create; fRestartAfterBuild:=True; fConfirmBuild:=True; @@ -563,7 +559,6 @@ end; destructor TBuildLazarusProfiles.Destroy; begin fMakeModeDefs.Free; - fGlobals.Free; inherited Destroy; // Clear is called by inherited Destroy. Must be freed later. fStaticAutoInstallPackages.Free; @@ -585,8 +580,6 @@ var SrcItem, NewItem: TBuildLazarusProfile; begin Clear; - fGlobals.TargetCPU:=Source.fGlobals.TargetCPU; - fGlobals.TargetOS:=Source.fGlobals.TargetOS; fMakeModeDefs.Assign(Source.MakeModeDefs); RestartAfterBuild :=Source.RestartAfterBuild; ConfirmBuild:=Source.ConfirmBuild; @@ -785,12 +778,6 @@ begin fCurrentIndex:=NewIndex; end; -procedure TBuildLazarusProfiles.UpdateGlobals; -begin - Globals.TargetOS:=Current.FPCTargetOS; - Globals.TargetCPU:=Current.FPCTargetCPU; -end; - function TBuildLazarusProfiles.GetCurrentProfile: TBuildLazarusProfile; begin Result:=Items[fCurrentIndex]; diff --git a/ide/checkcompileropts.pas b/ide/checkcompileropts.pas index 2b5319432c..c5e88f3ef9 100644 --- a/ide/checkcompileropts.pas +++ b/ide/checkcompileropts.pas @@ -390,7 +390,7 @@ begin end; try // create compiler command line options - CmdLineParams:=Options.MakeOptionsString(BogusFilename,nil, + CmdLineParams:=Options.MakeOptionsString(BogusFilename, [ccloAddVerboseAll,ccloDoNotAppendOutFileOption,ccloAbsolutePaths]) +' '+BogusFilename; diff --git a/ide/compileroptions.pp b/ide/compileroptions.pp index 240806f2cb..8703e3b17a 100644 --- a/ide/compileroptions.pp +++ b/ide/compileroptions.pp @@ -138,20 +138,6 @@ type procedure Assign(Source: TLazBuildMacros); end; - { TGlobalCompilerOptions - compiler options overrides } - - TGlobalCompilerOptions = class - private - FTargetCPU: string; - FTargetOS: string; - procedure SetTargetCPU(const AValue: string); - procedure SetTargetOS(const AValue: string); - public - property TargetCPU: string read FTargetCPU write SetTargetCPU; - property TargetOS: string read FTargetOS write SetTargetOS; - end; - - type TInheritedCompilerOption = ( icoNone, @@ -517,10 +503,8 @@ type function CreateDiff(CompOpts: TBaseCompilerOptions; Tool: TCompilerDiffTool = nil): boolean; virtual;// true if differ - function MakeOptionsString(Globals: TGlobalCompilerOptions; - Flags: TCompilerCmdLineOptions): String; + function MakeOptionsString(Flags: TCompilerCmdLineOptions): String; function MakeOptionsString(const MainSourceFileName: string; - Globals: TGlobalCompilerOptions; Flags: TCompilerCmdLineOptions): String; virtual; function GetSyntaxOptionsString: string; virtual; function CreateTargetFilename(const MainSourceFileName: string): string; virtual; @@ -2190,10 +2174,10 @@ end; {------------------------------------------------------------------------------ TBaseCompilerOptions MakeOptionsString ------------------------------------------------------------------------------} -function TBaseCompilerOptions.MakeOptionsString(Globals: TGlobalCompilerOptions; +function TBaseCompilerOptions.MakeOptionsString( Flags: TCompilerCmdLineOptions): String; begin - Result:=MakeOptionsString(GetDefaultMainSourceFileName,Globals,Flags); + Result:=MakeOptionsString(GetDefaultMainSourceFileName,Flags); end; function GetIgnoredMsgsIndexes(msglist: TCompilerMessagesList; const Separator: string): string; @@ -2214,13 +2198,12 @@ end; {------------------------------------------------------------------------------ function TBaseCompilerOptions.MakeOptionsString( const MainSourceFilename: string; - Globals: TGlobalCompilerOptions; Flags: TCompilerCmdLineOptions): String; Get all the options and create a string that can be passed to the compiler ------------------------------------------------------------------------------} function TBaseCompilerOptions.MakeOptionsString( - const MainSourceFilename: string; Globals: TGlobalCompilerOptions; + const MainSourceFilename: string; Flags: TCompilerCmdLineOptions): String; var switches, tempsw, t: String; @@ -2237,6 +2220,8 @@ var CurCustomOptions: String; OptimizeSwitches: String; LinkerAddition: String; + Vars: TCTCfgScriptVariables; + v: string; begin CurMainSrcFile:=MainSourceFileName; if CurMainSrcFile='' then @@ -2537,16 +2522,19 @@ begin OS2 = OS/2 (2.x) using the EMX extender. WIN32 = Windows 32 bit. ... } - { Target OS } - if (Globals<>nil) and (Globals.TargetOS<>'') then - switches := switches + ' -T' + Globals.TargetOS - else if (TargetOS<>'') then - switches := switches + ' -T' + TargetOS; - { Target CPU } - if (Globals<>nil) and (Globals.TargetCPU<>'') then - switches := switches + ' -P' + Globals.TargetCPU - else if (TargetCPU<>'') then - switches := switches + ' -P' + TargetCPU; + debugln(['TBaseCompilerOptions.MakeOptionsString ']); + Vars:=GetBuildMacroValues(Self,true); + if Vars<>nil then + begin + { Target OS } + v:=GetFPCTargetOS(Vars.Values['TargetOS']); + if (v<>'') and (v<>GetDefaultTargetOS) then + switches := switches + ' -T' + v; + { Target CPU } + v:=GetFPCTargetCPU(Vars.Values['TargetCPU']); + if (v<>'') and (v<>GetDefaultTargetCPU) then + switches := switches + ' -P' + v; + end; end; { --------------- Linking Tab ------------------- } @@ -3818,20 +3806,6 @@ begin if assigned(OnChanged) then OnChanged(Self); end; -{ TGlobalCompilerOptions } - -procedure TGlobalCompilerOptions.SetTargetCPU(const AValue: string); -begin - if FTargetCPU=AValue then exit; - FTargetCPU:=AValue; -end; - -procedure TGlobalCompilerOptions.SetTargetOS(const AValue: string); -begin - if FTargetOS=AValue then exit; - FTargetOS:=AValue; -end; - { TIDEBuildMacro } procedure TIDEBuildMacro.SetIdentifier(const AValue: string); diff --git a/ide/main.pp b/ide/main.pp index 22e783cd4f..aa0d62db69 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -11054,7 +11054,7 @@ begin //DebugLn(['TMainIDE.DoBuildProject CompilerFilename="',CompilerFilename,'" CompilerPath="',Project1.CompilerOptions.CompilerPath,'"']); // Note: use absolute paths, because some external tools resolve symlinked directories CompilerParams := - Project1.CompilerOptions.MakeOptionsString(SrcFilename,nil,[ccloAbsolutePaths]) + Project1.CompilerOptions.MakeOptionsString(SrcFilename,[ccloAbsolutePaths]) + ' ' + PrepareCmdLineOption(SrcFilename); //DebugLn('TMainIDE.DoBuildProject WorkingDir="',WorkingDir,'" SrcFilename="',SrcFilename,'" CompilerFilename="',CompilerFilename,'" CompilerParams="',CompilerParams,'"'); diff --git a/ide/project.pp b/ide/project.pp index 827b974804..f2e0b19b49 100644 --- a/ide/project.pp +++ b/ide/project.pp @@ -496,7 +496,6 @@ type TProjectCompilerOptions = class(TBaseCompilerOptions) private - FGlobals: TGlobalCompilerOptions; FProject: TProject; FCompileReasons: TCompileReasons; protected @@ -511,7 +510,6 @@ type procedure SetUnitPaths(const AValue: string); override; procedure SetUnitOutputDir(const AValue: string); override; procedure SetConditionals(const AValue: string); override; - procedure UpdateGlobals; virtual; public constructor Create(const AOwner: TObject); override; destructor Destroy; override; @@ -533,7 +531,6 @@ type function GetEffectiveLCLWidgetType: string; override; public property LazProject: TProject read FProject; - property Globals: TGlobalCompilerOptions read FGlobals; published property CompileReasons: TCompileReasons read FCompileReasons write FCompileReasons; end; @@ -5754,15 +5751,11 @@ end; procedure TProjectCompilerOptions.SetTargetCPU(const AValue: string); begin inherited SetTargetCPU(AValue); - if IsActive then - FGlobals.TargetCPU:=GetFPCTargetCPU(TargetCPU); end; procedure TProjectCompilerOptions.SetTargetOS(const AValue: string); begin inherited SetTargetOS(AValue); - if IsActive then - FGlobals.TargetOS:=GetFPCTargetOS(TargetOS); end; procedure TProjectCompilerOptions.SetCustomOptions(const AValue: string); @@ -5847,7 +5840,6 @@ begin FCompileReasons := [crCompile, crBuild, crRun]; // keep BuildModes end; - UpdateGlobals; end; function TProjectCompilerOptions.IsEqual(CompOpts: TBaseCompilerOptions @@ -5886,13 +5878,6 @@ begin Result:=LCLPlatformDirNames[lpNoGUI]; end; -procedure TProjectCompilerOptions.UpdateGlobals; -begin - if not IsActive then exit; - FGlobals.TargetCPU:=TargetCPU; - FGlobals.TargetOS:=TargetOS; -end; - class function TProjectCompilerOptions.GetInstance: TAbstractIDEOptions; begin Result := Project1.CompilerOptions; @@ -5905,7 +5890,6 @@ end; constructor TProjectCompilerOptions.Create(const AOwner: TObject); begin - FGlobals := TGlobalCompilerOptions.Create; FCompileReasons := [crCompile, crBuild, crRun]; inherited Create(AOwner, TProjectCompilationToolOptions); with TProjectCompilationToolOptions(ExecuteBefore) do begin @@ -5916,7 +5900,6 @@ begin DefaultCompileReasons:=crAll; CompileReasons:=DefaultCompileReasons; end; - UpdateGlobals; if AOwner <> nil then FProject := AOwner as TProject; end; @@ -5924,7 +5907,6 @@ end; destructor TProjectCompilerOptions.Destroy; begin inherited Destroy; - FreeAndNil(FGlobals); end; function TProjectCompilerOptions.IsActive: boolean; diff --git a/ide/showcompileropts.pas b/ide/showcompileropts.pas index 3b2c6d607a..8228320c6e 100644 --- a/ide/showcompileropts.pas +++ b/ide/showcompileropts.pas @@ -107,7 +107,7 @@ begin Flags:=CompilerOpts.DefaultMakeOptionsFlags; if not RelativePathsCheckBox.Checked then Include(Flags,ccloAbsolutePaths); - CurOptions := CompilerOpts.MakeOptionsString(nil,Flags); + CurOptions := CompilerOpts.MakeOptionsString(Flags); CmdLineMemo.Lines.Text:=CurOptions; end; diff --git a/packager/basepkgmanager.pas b/packager/basepkgmanager.pas index 8752c5ad4a..9dd2ddbd2b 100644 --- a/packager/basepkgmanager.pas +++ b/packager/basepkgmanager.pas @@ -132,8 +132,7 @@ type function DoCompileProjectDependencies(AProject: TProject; Flags: TPkgCompileFlags): TModalResult; virtual; abstract; function DoCompilePackage(APackage: TLazPackage; Flags: TPkgCompileFlags; - ShowAbort: boolean; - Globals: TGlobalCompilerOptions = nil): TModalResult; virtual; abstract; + ShowAbort: boolean): TModalResult; virtual; abstract; // package installation procedure LoadInstalledPackages; virtual; abstract; diff --git a/packager/packagesystem.pas b/packager/packagesystem.pas index 891b9b0a04..b5774f7f42 100644 --- a/packager/packagesystem.pas +++ b/packager/packagesystem.pas @@ -284,14 +284,11 @@ type Flags: TPkgCompileFlags; ShowAbort: boolean): TModalResult; function CompileRequiredPackages(APackage: TLazPackage; FirstDependency: TPkgDependency; - Globals: TGlobalCompilerOptions; Policies: TPackageUpdatePolicies): TModalResult; function CompilePackage(APackage: TLazPackage; Flags: TPkgCompileFlags; - ShowAbort: boolean; - Globals: TGlobalCompilerOptions = nil): TModalResult; + ShowAbort: boolean): TModalResult; function ConvertPackageRSTFiles(APackage: TLazPackage): TModalResult; - function WriteMakeFile(APackage: TLazPackage; - Globals: TGlobalCompilerOptions): TModalResult; + function WriteMakeFile(APackage: TLazPackage): TModalResult; public // installed packages FirstAutoInstallDependency: TPkgDependency; @@ -3154,8 +3151,7 @@ begin end; function TLazPackageGraph.CompileRequiredPackages(APackage: TLazPackage; - FirstDependency: TPkgDependency; Globals: TGlobalCompilerOptions; - Policies: TPackageUpdatePolicies): TModalResult; + FirstDependency: TPkgDependency; Policies: TPackageUpdatePolicies): TModalResult; var AutoPackages: TFPList; i: Integer; @@ -3172,7 +3168,7 @@ begin while imrOk then exit; inc(i); end; @@ -3187,8 +3183,7 @@ begin end; function TLazPackageGraph.CompilePackage(APackage: TLazPackage; - Flags: TPkgCompileFlags; ShowAbort: boolean; Globals: TGlobalCompilerOptions - ): TModalResult; + Flags: TPkgCompileFlags; ShowAbort: boolean): TModalResult; function GetIgnoreIdentifier: string; begin @@ -3222,8 +3217,7 @@ begin CompilePolicies:=[pupAsNeeded]; if pcfCompileDependenciesClean in Flags then Include(CompilePolicies,pupOnRebuildingAll); - Result:=CompileRequiredPackages(APackage,nil,Globals, - CompilePolicies); + Result:=CompileRequiredPackages(APackage,nil,CompilePolicies); if Result<>mrOk then begin DebugLn(['TLazPackageGraph.CompilePackage CompileRequiredPackages failed: ',APackage.IDAsString]); exit; @@ -3233,7 +3227,7 @@ begin SrcFilename:=APackage.GetSrcFilename; CompilerFilename:=APackage.GetCompilerFilename; // Note: use absolute paths, because some external tools resolve symlinked directories - CompilerParams:=APackage.CompilerOptions.MakeOptionsString(Globals, + CompilerParams:=APackage.CompilerOptions.MakeOptionsString( APackage.CompilerOptions.DefaultMakeOptionsFlags+[ccloAbsolutePaths]) +' '+CreateRelativePath(SrcFilename,APackage.Directory); //DebugLn(['TLazPackageGraph.CompilePackage SrcFilename="',SrcFilename,'" CompilerFilename="',CompilerFilename,'" CompilerParams="',CompilerParams,'" TargetCPU=',Globals.TargetCPU,' TargetOS=',Globals.TargetOS]); @@ -3286,7 +3280,7 @@ begin // create Makefile if ((pcfCreateMakefile in Flags) or (APackage.CompilerOptions.CreateMakefileOnBuild)) then begin - Result:=WriteMakeFile(APackage,Globals); + Result:=WriteMakeFile(APackage); if Result<>mrOk then begin DebugLn('TLazPackageGraph.CompilePackage DoWriteMakefile failed: ',APackage.IDAsString); exit; @@ -3459,8 +3453,7 @@ begin Result:=mrOK; end; -function TLazPackageGraph.WriteMakeFile(APackage: TLazPackage; - Globals: TGlobalCompilerOptions): TModalResult; +function TLazPackageGraph.WriteMakeFile(APackage: TLazPackage): TModalResult; var PathDelimNeedsReplace: Boolean; @@ -3549,7 +3542,7 @@ begin coptParsedPlatformIndependent); CustomOptions:=APackage.CompilerOptions.GetCustomOptions( coptParsedPlatformIndependent); - OtherOptions:=APackage.CompilerOptions.MakeOptionsString(Globals, + OtherOptions:=APackage.CompilerOptions.MakeOptionsString( [ccloDoNotAppendOutFileOption,ccloNoMacroParams]); try diff --git a/packager/pkgmanager.pas b/packager/pkgmanager.pas index 42debdbf83..b5b35c6889 100644 --- a/packager/pkgmanager.pas +++ b/packager/pkgmanager.pas @@ -292,8 +292,7 @@ type function DoCompileProjectDependencies(AProject: TProject; Flags: TPkgCompileFlags): TModalResult; override; function DoCompilePackage(APackage: TLazPackage; Flags: TPkgCompileFlags; - ShowAbort: boolean; - Globals: TGlobalCompilerOptions = nil): TModalResult; override; + ShowAbort: boolean): TModalResult; override; function DoCreatePackageMakefile(APackage: TLazPackage; ShowAbort: boolean): TModalResult; @@ -648,17 +647,12 @@ function TPkgManager.OnPackageEditorCompilePackage(Sender: TObject; APackage: TLazPackage; CompileClean, CompileRequired: boolean): TModalResult; var Flags: TPkgCompileFlags; - Globals: TGlobalCompilerOptions; begin Flags:=[]; if CompileClean then Include(Flags,pcfCleanCompile); if CompileRequired then Include(Flags,pcfCompileDependenciesClean); - if Project1<>nil then - Globals:=Project1.CompilerOptions.Globals - else - Globals:=nil; //debugln('TPkgManager.OnPackageEditorCompilePackage OS=',Globals.TargetOS); - Result:=DoCompilePackage(APackage,Flags,false,Globals); + Result:=DoCompilePackage(APackage,Flags,false); end; function TPkgManager.OnPackageEditorCreateMakefile(Sender: TObject; @@ -2563,7 +2557,6 @@ begin if not (pcfDoNotCompileDependencies in Flags) then begin Result:=PackageGraph.CompileRequiredPackages(nil, AProject.FirstRequiredDependency, - AProject.CompilerOptions.Globals, [pupAsNeeded]); if Result<>mrOk then exit; end; @@ -2575,8 +2568,7 @@ begin end; function TPkgManager.DoCompilePackage(APackage: TLazPackage; - Flags: TPkgCompileFlags; ShowAbort: boolean; Globals: TGlobalCompilerOptions - ): TModalResult; + Flags: TPkgCompileFlags; ShowAbort: boolean): TModalResult; begin Result:=mrCancel; @@ -2605,14 +2597,14 @@ begin Result:=WarnAboutMissingPackageFiles(APackage); if Result<>mrOk then exit; - Result:=PackageGraph.CompilePackage(APackage,Flags,false,Globals); + Result:=PackageGraph.CompilePackage(APackage,Flags,false); end; function TPkgManager.DoCreatePackageMakefile(APackage: TLazPackage; ShowAbort: boolean): TModalResult; begin Result:=DoCompilePackage(APackage,[pcfDoNotCompileDependencies, - pcfDoNotCompilePackage,pcfCreateMakefile],ShowAbort,nil); + pcfDoNotCompilePackage,pcfCreateMakefile],ShowAbort); end; function TPkgManager.OnRenameFile(const OldFilename, NewFilename: string; @@ -3983,9 +3975,7 @@ begin end; // compile all auto install dependencies - MiscellaneousOptions.BuildLazProfiles.UpdateGlobals; - Result:=PackageGraph.CompileRequiredPackages(nil,Dependencies, - MiscellaneousOptions.BuildLazProfiles.Globals,[pupAsNeeded]); + Result:=PackageGraph.CompileRequiredPackages(nil,Dependencies,[pupAsNeeded]); if Result<>mrOk then exit; finally