From 88780a9aaa9403a12d6c8a61dca47e217086e4eb Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 18 Feb 2014 18:26:04 +0000 Subject: [PATCH] IDE: use compiler of project for FPCVer and codetools macro values git-svn-id: trunk@44141 - --- components/codetools/definetemplates.pas | 30 +++++++++++++++++ components/ideintf/lazideintf.pas | 1 + ide/basebuildmanager.pas | 1 + ide/buildmanager.pas | 41 +++++++++++++++++------- ide/compiler.pp | 4 +-- ide/compileroptions.pp | 5 +-- ide/environmentopts.pp | 1 + ide/idefpcinfo.pas | 13 +++++--- ide/ideinfodlg.pas | 17 +++++++--- ide/main.pp | 6 ++++ 10 files changed, 95 insertions(+), 24 deletions(-) diff --git a/components/codetools/definetemplates.pas b/components/codetools/definetemplates.pas index f93b04ae42..4f9d4602e7 100644 --- a/components/codetools/definetemplates.pas +++ b/components/codetools/definetemplates.pas @@ -950,6 +950,7 @@ function ParseFPCInfo(FPCInfo: string; InfoTypes: TFPCInfoTypes; out Infos: TFPCInfoStrings): boolean; function RunFPCInfo(const CompilerFilename: string; InfoTypes: TFPCInfoTypes; const Options: string =''): string; +function IsFPCompiler(AFilename: string): boolean; function ExtractFPCFrontEndParameters(const CmdLine: string): string; function SplitFPCVersion(const FPCVersionString: string; out FPCVersion, FPCRelease, FPCPatch: integer): boolean; @@ -1359,6 +1360,35 @@ begin end; end; +function IsFPCompiler(aFilename: string): boolean; +var + ShortFilename: String; +begin + Result:=false; + AFilename:=ResolveDots(aFilename); + //debugln(['IsFPCompiler START ',aFilename]); + if aFilename='' then + exit; + if not FileExistsCached(AFilename) then + exit; + if DirPathExistsCached(AFilename) then + exit; + if not FileIsExecutableCached(AFilename) then + exit; + + // allow scripts like fpc.sh and fpc.bat + ShortFilename:=ExtractFileNameOnly(AFilename); + //debugln(['IsFPCompiler Short=',ShortFilename]); + if CompareFilenames(ShortFilename,'fpc')=0 then + exit(true); + + // allow ppcxxx.exe + if (CompareFilenames(copy(ShortFilename,1,3),'ppc')=0) + and ((ExeExt='') or (LazFileUtils.CompareFileExt(ShortFilename,ExeExt)=0)) + then + exit(true); +end; + function ExtractFPCFrontEndParameters(const CmdLine: string): string; // extract the parameters for the FPC frontend tool fpc.exe // The result is normalized: diff --git a/components/ideintf/lazideintf.pas b/components/ideintf/lazideintf.pas index 42f51f751f..85767d101d 100644 --- a/components/ideintf/lazideintf.pas +++ b/components/ideintf/lazideintf.pas @@ -263,6 +263,7 @@ type NewOwner: TObject; Flags: TSearchIDEFileFlags; TryWithoutNumber: boolean): string; virtual; abstract; function GetTestBuildDirectory: string; virtual; abstract; + function GetFPCompilerFilename: string; virtual; abstract; // codetools function BeginCodeTools: boolean; virtual; abstract; diff --git a/ide/basebuildmanager.pas b/ide/basebuildmanager.pas index bd89156541..0b48391e55 100644 --- a/ide/basebuildmanager.pas +++ b/ide/basebuildmanager.pas @@ -54,6 +54,7 @@ type function GetLCLWidgetType: string; virtual; abstract; function GetRunCommandLine: string; virtual; abstract; + function GetFPCompilerFilename: string; virtual; abstract; function GetProjectPublishDir: string; virtual; abstract; function GetProjectTargetFilename(aProject: TProject): string; virtual; abstract; function GetProjectUsesAppBundle: Boolean; virtual; abstract; diff --git a/ide/buildmanager.pas b/ide/buildmanager.pas index f5f4571010..a92627821c 100644 --- a/ide/buildmanager.pas +++ b/ide/buildmanager.pas @@ -179,6 +179,7 @@ type function GetLCLWidgetType: string; override; function GetRunCommandLine: string; override; + function GetFPCompilerFilename: string; override; function GetProjectPublishDir: string; override; function GetProjectTargetFilename(aProject: TProject): string; override; function GetProjectUsesAppBundle: Boolean; override; @@ -589,6 +590,22 @@ begin end; end; +function TBuildManager.GetFPCompilerFilename: string; +begin + Result:=''; + if (Project1<>nil) + and ([crCompile,crBuild]*Project1.CompilerOptions.CompileReasons<>[]) + and (Project1.CompilerOptions.CompilerPath<>'') + then begin + Result:=Project1.GetCompilerFilename; + //debugln(['TBuildManager.GetFPCompilerFilename project compiler="',Result,'"']); + end; + if not IsFPCompiler(Result) then begin + //if Result<>'' then debugln(['TBuildManager.GetFPCompilerFilename project compiler NOT fpc: "',Result,'"']); + Result:=EnvironmentOptions.GetParsedCompilerFilename; + end; +end; + function TBuildManager.GetProjectPublishDir: string; begin Result:=''; @@ -786,10 +803,10 @@ begin // use current TargetOS, TargetCPU, compilerfilename and FPC source dir TargetOS:=GetTargetOS; TargetCPU:=GetTargetCPU; - CompilerFilename:=EnvironmentOptions.GetParsedCompilerFilename; FPCSrcDir:=EnvironmentOptions.GetParsedFPCSourceDirectory; // needs FPCVer macro + CompilerFilename:=GetFPCompilerFilename; - {$IFDEF VerboseFPCSrcScan} + { $IFDEF VerboseFPCSrcScan} debugln(['TMainIDE.RescanCompilerDefines A ', ' CompilerFilename=',CompilerFilename, ' TargetOS=',TargetOS, @@ -798,22 +815,24 @@ begin ' FPCSrcDir=',FPCSrcDir, ' WaitTillDone=',WaitTillDone, ' Quiet=',Quiet, + ' ClearCaches=',ClearCaches, '']); - {$ENDIF} - - if CompilerFilename='' then begin - UnitSetCache:=nil; - exit; - end; + { $ENDIF} + // first check the default targetos, targetcpu of the default compiler if FileExistsCached(EnvironmentOptions.GetParsedCompilerFilename) then begin - // first check the default targetos, targetcpu of the default compiler UnitSetCache:=CodeToolBoss.FPCDefinesCache.FindUnitSet( EnvironmentOptions.GetParsedCompilerFilename,'','','',FPCSrcDir,true); UnitSetCache.GetConfigCache(true); end; + // then check the project's compiler + if not IsFPCompiler(CompilerFilename) then begin + UnitSetCache:=nil; + exit; + end; + // create a cache for the current project settings UnitSetCache:=CodeToolBoss.FPCDefinesCache.FindUnitSet( CompilerFilename,TargetOS,TargetCPU,'',FPCSrcDir,true); @@ -1951,8 +1970,8 @@ function TBuildManager.MacroFuncFPCVer(const Param: string; const Data: PtrInt; if CodeToolBoss<>nil then begin // fetch the FPC version from the current compiler // Not from the fpc.exe, but from the real compiler - CompilerFilename:=EnvironmentOptions.GetParsedCompilerFilename; - if CompilerFilename='' then exit; + CompilerFilename:=GetFPCompilerFilename; + if not IsFPCompiler(CompilerFilename) then exit; TargetOS:=GetTargetOS; TargetCPU:=GetTargetCPU; ConfigCache:=CodeToolBoss.FPCDefinesCache.ConfigCaches.Find( diff --git a/ide/compiler.pp b/ide/compiler.pp index 4f45ea4f66..0b05f29acc 100644 --- a/ide/compiler.pp +++ b/ide/compiler.pp @@ -45,7 +45,7 @@ uses {$ELSE} OutputFilter, {$ENDIF} - UTF8Process, InfoBuild, IDEMsgIntf, CompOptsIntf, + UTF8Process, InfoBuild, IDEMsgIntf, CompOptsIntf, LazIDEIntf, DefineTemplates, TransferMacros, EnvironmentOpts, LazFileUtils; type @@ -1368,7 +1368,7 @@ var begin StartTime := Now; try - fReader.CompilerExecutable := EnvironmentOptions.GetParsedCompilerFilename; + fReader.CompilerExecutable := LazarusIDE.GetFPCompilerFilename; fReader.ReadAndParseOptions; except on E: Exception do diff --git a/ide/compileroptions.pp b/ide/compileroptions.pp index 423373b488..06b82c8516 100644 --- a/ide/compileroptions.pp +++ b/ide/compileroptions.pp @@ -49,7 +49,8 @@ uses ProjectIntf, MacroIntf, IDEExternToolIntf, SrcEditorIntf, CompOptsIntf, IDEOptionsIntf, // IDE - LazarusIDEStrConsts, IDEProcs, IDEMsgIntf, LazConf, TransferMacros, + LazarusIDEStrConsts, IDEProcs, IDEMsgIntf, LazIDEIntf, LazConf, + TransferMacros, {$IFDEF EnableNewExtTools} etFPCMsgParser, {$ENDIF} @@ -2830,7 +2831,7 @@ begin if (VariablesInRegisters) then Switches := Switches + ' -OoREGVAR'; - CompilerFilename:=EnvironmentOptions.GetParsedCompilerFilename; + CompilerFilename:=LazarusIDE.GetFPCompilerFilename; CodeToolBoss.FPCDefinesCache.ConfigCaches.GetDefaultCompilerTarget( CompilerFilename,'',DefaultTargetOS,DefaultTargetCPU); diff --git a/ide/environmentopts.pp b/ide/environmentopts.pp index 751d646239..8fe9a99ab9 100644 --- a/ide/environmentopts.pp +++ b/ide/environmentopts.pp @@ -2040,6 +2040,7 @@ end; function TEnvironmentOptions.MacroFuncCompPath(const s: string; const Data: PtrInt; var Abort: boolean): string; +// CompPath returns the default compiler file name of the environment options begin Result:=GetParsedCompilerFilename; end; diff --git a/ide/idefpcinfo.pas b/ide/idefpcinfo.pas index 1826b8873d..3a9f87fa8d 100644 --- a/ide/idefpcinfo.pas +++ b/ide/idefpcinfo.pas @@ -33,7 +33,7 @@ uses Classes, SysUtils, AVL_Tree, FileUtil, lazutf8classes, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls, FileProcs, DefineTemplates, CodeToolManager, BaseBuildManager, Project, EnvironmentOpts, - LazarusIDEStrConsts, AboutFrm, IDEWindowIntf; + LazarusIDEStrConsts, AboutFrm, IDEWindowIntf, LazIDEIntf; type @@ -114,7 +114,7 @@ begin TargetOS:=BuildBoss.GetTargetOS; TargetCPU:=BuildBoss.GetTargetCPU; - CompilerFilename:=EnvironmentOptions.GetParsedCompilerFilename; + CompilerFilename:=LazarusIDE.GetFPCompilerFilename; FPCSrcDir:=EnvironmentOptions.GetParsedFPCSourceDirectory; // needs FPCVer macro UnitSetCache:=CodeToolBoss.FPCDefinesCache.FindUnitSet( CompilerFilename,TargetOS,TargetCPU,'',FPCSrcDir,true); @@ -145,7 +145,7 @@ begin List:=nil; try sl.Add('The IDE asks the compiler with the following command for the real OS/CPU:'); - CompilerFilename:=EnvironmentOptions.GetParsedCompilerFilename; + CompilerFilename:=LazarusIDE.GetFPCompilerFilename; CompilerOptions:=''; Cfg:=CodeToolBoss.FPCDefinesCache.ConfigCaches.Find( CompilerFilename,CompilerOptions,'','',true); @@ -241,8 +241,11 @@ begin sl.add('Global IDE options:'); sl.Add('LazarusDirectory='+EnvironmentOptions.LazarusDirectory); sl.Add('Resolved LazarusDirectory='+EnvironmentOptions.GetParsedLazarusDirectory); - sl.Add('CompilerFilename='+EnvironmentOptions.CompilerFilename); - sl.Add('Resolved CompilerFilename='+EnvironmentOptions.GetParsedCompilerFilename); + if Project1<>nil then + sl.Add('Project''s CompilerFilename='+Project1.CompilerOptions.CompilerPath); + sl.Add('Resolved Project''s CompilerFilename='+Project1.GetCompilerFilename); + sl.Add('Default CompilerFilename='+EnvironmentOptions.CompilerFilename); + sl.Add('Resolved default compilerFilename='+EnvironmentOptions.GetParsedCompilerFilename); sl.Add('CompilerMessagesFilename='+EnvironmentOptions.CompilerMessagesFilename); sl.Add('Resolved CompilerMessagesFilename='+EnvironmentOptions.GetParsedCompilerMessagesFilename); sl.Add(''); diff --git a/ide/ideinfodlg.pas b/ide/ideinfodlg.pas index debec6fd73..16c88bd1f6 100644 --- a/ide/ideinfodlg.pas +++ b/ide/ideinfodlg.pas @@ -32,7 +32,7 @@ interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls, LCLProc, LazHelpHTML, LazHelpIntf, DefineTemplates, CodeToolManager, - EnvironmentOpts, AboutFrm, LazConf, IDEHelpIntf, IDEWindowIntf, + EnvironmentOpts, AboutFrm, LazConf, IDEHelpIntf, IDEWindowIntf, LazIDEIntf, LazarusIDEStrConsts, Project, SourceEditor, InitialSetupDlgs, PackageSystem, PackageDefs; @@ -241,20 +241,29 @@ begin then sl.Add('WARNING: '+Note); - sl.Add('CompilerFilename='+EnvironmentOptions.CompilerFilename); - sl.Add('Real CompilerFilename='+EnvironmentOptions.GetParsedCompilerFilename); + sl.Add('Default CompilerFilename='+EnvironmentOptions.CompilerFilename); + sl.Add('Real Default CompilerFilename='+EnvironmentOptions.GetParsedCompilerFilename); if CheckCompilerQuality(EnvironmentOptions.GetParsedCompilerFilename,Note, CodeToolBoss.FPCDefinesCache.TestFilename)<>sddqCompatible then sl.Add('WARNING: '+Note); + if Project1<>nil then begin + sl.Add('Project CompilerFilename='+Project1.CompilerOptions.CompilerPath); + sl.Add('Real Project CompilerFilename='+LazarusIDE.GetFPCompilerFilename); + if CheckCompilerQuality(LazarusIDE.GetFPCompilerFilename,Note, + CodeToolBoss.FPCDefinesCache.TestFilename)<>sddqCompatible + then + sl.Add('WARNING: '+Note); + end; + sl.Add('CompilerMessagesFilename='+EnvironmentOptions.CompilerMessagesFilename); sl.Add('Real CompilerMessagesFilename='+EnvironmentOptions.GetParsedCompilerMessagesFilename); sl.Add('FPC source directory='+EnvironmentOptions.FPCSourceDirectory); sl.Add('Real FPC source directory='+EnvironmentOptions.GetParsedFPCSourceDirectory); CfgCache:=CodeToolBoss.FPCDefinesCache.ConfigCaches.Find( - EnvironmentOptions.GetParsedCompilerFilename,'','','',true); + LazarusIDE.GetFPCompilerFilename,'','','',true); if CheckFPCSrcDirQuality(EnvironmentOptions.GetParsedFPCSourceDirectory,Note, CfgCache.GetFPCVer)<>sddqCompatible then diff --git a/ide/main.pp b/ide/main.pp index d7189d2d5f..0b0cf4d040 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -978,6 +978,7 @@ type // methods for debugging, compiling and external tools function GetTestBuildDirectory: string; override; + function GetFPCompilerFilename: string; override; procedure GetIDEFileState(Sender: TObject; const AFilename: string; NeededFlags: TIDEFileStateFlags; out ResultFlags: TIDEFileStateFlags); override; @@ -9211,6 +9212,11 @@ begin Result:=MainBuildBoss.GetTestBuildDirectory; end; +function TMainIDE.GetFPCompilerFilename: string; +begin + Result:=MainBuildBoss.GetFPCompilerFilename; +end; + function TMainIDE.FindUnitFile(const AFilename: string; TheOwner: TObject; Flags: TFindUnitFileFlags): string;