Merged revision(s) 60539 #74f40164bd, 60541 #4f1d217a02, 60543 #33c555282c, 60551-60552 #70529aa22d-#70529aa22d from trunk:

IDE: compile package: quote src if needed
........
IDE: fixed compiler kind if project/package compiler is set
........
IDE: use project compiler for codetools even if disabled
........
IDE/codetools: unified compiler check, fixed testing compiler twice
........
IDE: fixed fpc version check for resources
........

git-svn-id: branches/fixes_2_0@60604 -
This commit is contained in:
maxim 2019-03-06 23:04:39 +00:00
parent 7c745991a7
commit b72dacab07
7 changed files with 95 additions and 47 deletions

View File

@ -373,7 +373,8 @@ type
UseCache: boolean = true): string;// value of macro #FPCUnitPath
procedure GetFPCVersionForDirectory(const Directory: string;
out FPCVersion, FPCRelease, FPCPatch: integer);
function GetPCVersionForDirectory(const Directory: string): integer;
function GetPCVersionForDirectory(const Directory: string): integer; deprecated 'use below'; // 2.0.1
function GetPCVersionForDirectory(const Directory: string; out Kind: TPascalCompiler): integer;
function GetNamespacesForDirectory(const Directory: string;
UseCache: boolean = true): string;// value of macro #Namespaces
@ -1706,19 +1707,32 @@ end;
function TCodeToolManager.GetPCVersionForDirectory(const Directory: string
): integer;
var
Kind: TPascalCompiler;
begin
Result:=GetPCVersionForDirectory(Directory,Kind);
if Kind=pcFPC then ;
end;
function TCodeToolManager.GetPCVersionForDirectory(const Directory: string; out
Kind: TPascalCompiler): integer;
var
Evaluator: TExpressionEvaluator;
s: String;
begin
Result:=0;
Kind:=pcFPC;
Evaluator:=DefineTree.GetDefinesForDirectory(Directory,true);
if Evaluator=nil then exit;
if Evaluator=nil then
exit;
s:=Evaluator['FPC_FULLVERSION'];
if s<>'' then
exit(StrToIntDef(s,0));
s:=Evaluator['PAS2JS_FULLVERSION'];
if s<>'' then
if s<>'' then begin
Kind:=pcPas2js;
exit(StrToIntDef(s,0));
end;
end;
function TCodeToolManager.GetNamespacesForDirectory(const Directory: string;

View File

@ -1016,7 +1016,10 @@ type
property TestFilename: string read GetTestFilename write SetTestFilename; // an empty file to test the compiler, will be auto created
property ExtraOptions: string read GetExtraOptions write SetExtraOptions; // additional compiler options not used as key, e.g. -Fr<language file>
function GetFPCVersion(const CompilerFilename, TargetOS, TargetCPU: string;
UseCompiledVersionAsDefault: boolean): string;
UseCompiledVersionAsDefault: boolean): string; deprecated 'use GetPCVersion'; // 2.0.1
function GetPCVersion(const CompilerFilename, TargetOS, TargetCPU: string;
UseCompiledVersionAsDefault: boolean;
out Kind: TPascalCompiler): string;
function FindUnitSet(const CompilerFilename, TargetOS, TargetCPU,
Options, FPCSrcDir: string;
CreateIfNotExists: boolean): TFPCUnitSetCache;
@ -1048,11 +1051,11 @@ function GetFPCTargetCPU(TargetCPU: string): string; // normalize
function IsCTExecutable(AFilename: string; out ErrorMsg: string): boolean; // not thread-safe
function GuessPascalCompilerFromExeName(Filename: string): TPascalCompiler;
function GuessPascalCompilerFromExeName(Filename: string): TPascalCompiler; // thread-safe
function IsCompilerExecutable(AFilename: string; out ErrorMsg: string;
out Kind: TPascalCompiler; Run: boolean): boolean; // not thread-safe
function IsFPCExecutable(AFilename: string; out ErrorMsg: string; Run: boolean): boolean; // not thread-safe
function IsPas2JSExecutable(AFilename: string; out ErrorMsg: string; Run: boolean): boolean; // not thread-safe
function IsFPCExecutable(AFilename: string; out ErrorMsg: string; Run: boolean): boolean; deprecated; // 2.1, not thread-safe
function IsPas2JSExecutable(AFilename: string; out ErrorMsg: string; Run: boolean): boolean; deprecated; // 2.1, not thread-safe
// functions to quickly setup some defines
function CreateDefinesInDirectories(const SourcePaths, FlagName: string
@ -3756,14 +3759,14 @@ function GuessPascalCompilerFromExeName(Filename: string): TPascalCompiler;
var
ShortFilename: String;
begin
ShortFilename:=ExtractFileNameOnly(Filename);
ShortFilename:=LowerCase(ExtractFileNameOnly(Filename));
// pas2js*
if CompareText(LeftStr(ShortFilename,6),'pas2js')=0 then
// *pas2js*
if Pos('pas2js',ShortFilename)>0 then
exit(pcPas2js);
// dcc*.exe
if (CompareFilenames(LeftStr(ShortFilename,3),'dcc')=0)
if (LeftStr(ShortFilename,3)='dcc')
and ((ExeExt='') or (CompareFileExt(Filename,ExeExt)=0))
then
exit(pcDelphi);
@ -3788,8 +3791,7 @@ begin
//debugln(['IsFPCompiler Short=',ShortFilename]);
// check ppc*.exe
if (CompareFilenames(LeftStr(ShortFilename,3),'ppc')=0)
then
if CompareText(LeftStr(ShortFilename,3),'ppc')=0 then
exit(true);
// check pas2js*
@ -3842,6 +3844,7 @@ begin
exit(true);
ErrorMsg:='fpc executable should start with fpc or ppc';
Result:=false;
end;
function IsFPCExecutable(AFilename: string; out ErrorMsg: string; Run: boolean
@ -3858,14 +3861,14 @@ begin
Result:=IsCTExecutable(AFilename,ErrorMsg);
if not Result then exit;
// allow scripts like fpc.sh and fpc.bat
ShortFilename:=ExtractFileNameOnly(AFilename);
// allow scripts like fpc*.sh and fpc*.bat
ShortFilename:=LowerCase(ExtractFileNameOnly(AFilename));
//debugln(['IsFPCompiler Short=',ShortFilename]);
if CompareFilenames(ShortFilename,'fpc')=0 then
if (LeftStr(ShortFilename,3)='fpc') then
exit(true);
// allow ppcxxx.exe
if (CompareFilenames(LeftStr(ShortFilename,3),'ppc')=0)
if (LeftStr(ShortFilename,3)='ppc')
and ((ExeExt='') or (CompareFileExt(AFilename,ExeExt)=0))
then
exit(true);
@ -3887,9 +3890,9 @@ begin
Result:=IsCTExecutable(AFilename,ErrorMsg);
if not Result then exit;
// allow scripts like pas2js*
ShortFilename:=ExtractFileNameOnly(AFilename);
if CompareText(LeftStr(ShortFilename,6),'pas2js')=0 then
// allow scripts like *pas2js*
ShortFilename:=LowerCase(ExtractFileNameOnly(AFilename));
if Pos('pas2js',ShortFilename)>0 then
exit(true);
ErrorMsg:='pas2js executable should start with pas2js';
@ -9537,10 +9540,21 @@ end;
function TCompilerDefinesCache.GetFPCVersion(const CompilerFilename, TargetOS,
TargetCPU: string; UseCompiledVersionAsDefault: boolean): string;
var
Kind: TPascalCompiler;
begin
Result:=GetPCVersion(CompilerFilename,TargetOS,TargetCPU,UseCompiledVersionAsDefault,Kind);
if Kind=pcFPC then ;
end;
function TCompilerDefinesCache.GetPCVersion(const CompilerFilename, TargetOS,
TargetCPU: string; UseCompiledVersionAsDefault: boolean; out
Kind: TPascalCompiler): string;
var
CfgCache: TPCTargetConfigCache;
ErrorMsg: string;
begin
Kind:=pcFPC;
if UseCompiledVersionAsDefault then
Result:={$I %FPCVersion%}
else
@ -9551,6 +9565,7 @@ begin
if CfgCache.NeedsUpdate
and not CfgCache.Update(TestFilename,ExtraOptions) then
exit;
Kind:=CfgCache.Kind;
if CfgCache.FullVersion='' then exit;
Result:=CfgCache.FullVersion;
end;

View File

@ -647,8 +647,8 @@ begin
begin
Opts:=FBuildTarget.CompilerOptions;
//debugln(['TBuildManager.GetCompilerFilename FBuildTarget=',DbgSName(FBuildTarget),' Path=',Opts.CompilerPath,' Build=',[crCompile,crBuild]*Opts.CompileReasons<>[],' Parsing=',Opts.ParsedOpts.Values[pcosCompilerPath].Parsing]);
if ([crCompile,crBuild]*Opts.CompileReasons<>[])
and (Opts.CompilerPath<>'')
// Note: even if Opts.CompileReasons are disabled, the project compiler path is used by codetools
if (Opts.CompilerPath<>'')
and (not Opts.ParsedOpts.Values[pcosCompilerPath].Parsing) then
begin
Result:=Opts.CompilerPath;
@ -888,7 +888,7 @@ begin
debugln(['TBuildManager.RescanCompilerDefines GetParsedFPCSourceDirectory needs FPCVer...']);
{$ENDIF}
CompilerFilename:=GetCompilerFilename;
IsCompilerExecutable(CompilerFilename,CompilerErrorMsg,CompilerKind,true);
IsCompilerExecutable(CompilerFilename,CompilerErrorMsg,CompilerKind,{$IFDEF VerboseFPCSrcScan}true{$ELSE}false{$ENDIF});
FPCSrcDir:=EnvironmentOptions.GetParsedFPCSourceDirectory; // needs FPCVer macro
FPCOptions:=GetFPCFrontEndOptions;
@ -908,16 +908,20 @@ begin
{$ENDIF}
// first check the default targetos, targetcpu of the default compiler
if FileExistsCached(EnvironmentOptions.GetParsedCompilerFilename) then
DefCompilerFilename:=EnvironmentOptions.GetParsedCompilerFilename;
if FileExistsCached(DefCompilerFilename) then
begin
{$IFDEF VerboseFPCSrcScan}
debugln(['TBuildManager.RescanCompilerDefines reading default compiler settings']);
{$ENDIF}
UnitSetCache:=CodeToolBoss.CompilerDefinesCache.FindUnitSet(
EnvironmentOptions.GetParsedCompilerFilename,'','','',FPCSrcDir,true);
DefCompilerFilename,'','','',FPCSrcDir,true);
UnitSetCache.GetConfigCache(true);
end;
if CompilerFilename<>DefCompilerFilename then
IsCompilerExecutable(CompilerFilename,CompilerErrorMsg,CompilerKind,true);
// then check the project's compiler
if (CompilerErrorMsg<>'') then begin
Msg:='';
@ -932,7 +936,6 @@ begin
end;
end;
DefCompilerFilename:=EnvironmentOptions.GetParsedCompilerFilename;
if not IsCompilerExecutable(DefCompilerFilename,DefCompilerErrorMsg,DefCompilerKind,true)
then begin
Msg+='Environment compiler: "'+DefCompilerFilename+'": '+DefCompilerErrorMsg+#13;

View File

@ -2866,8 +2866,10 @@ begin
Quiet:=ConsoleVerbosity<=-3; // lazbuild -q -q, lazarus -q -q -q
CompilerFilename:=ParsedOpts.GetParsedValue(pcosCompilerPath);
if CompilerFilename<>'' then
RealCompilerFilename:=CompilerFilename
if CompilerFilename<>'' then begin
RealCompilerFilename:=CompilerFilename;
Kind:=CodeToolBoss.GetPascalCompilerForDirectory(BaseDirectory);
end
else begin
// use default compiler
RealCompilerFilename:=EnvironmentOptions.GetParsedCompilerFilename;

View File

@ -35,8 +35,8 @@ uses
// RTL
Classes, SysUtils, strutils, math,
// CodeTools
KeywordFuncLists, CodeToolsFPCMsgs, CodeCache, FileProcs,
CodeToolManager, DirectoryCacher, BasicCodeTools, DefineTemplates, SourceLog,
KeywordFuncLists, CodeToolsFPCMsgs, CodeCache, FileProcs, CodeToolManager,
DirectoryCacher, BasicCodeTools, DefineTemplates, SourceLog, LinkScanner,
// LazUtils
LConvEncoding, LazUTF8, FileUtil, LazFileUtils, LazFileCache, LazUtilities,
AvgLvlTree,
@ -1006,6 +1006,7 @@ var
FPCVer: String;
FPCSrcDir: String;
aFilename: String;
CompilerKind: TPascalCompiler;
begin
if fMsgFileStamp<>CompilerParseStamp then begin
fCurrentEnglishFile:=DefaultEnglishFile;
@ -1013,7 +1014,10 @@ begin
// English msg file
// => use fpcsrcdir/compiler/msg/errore.msg
// the fpcsrcdir might depend on the FPC version
FPCVer:=CodeToolBoss.CompilerDefinesCache.GetFPCVersion(CompilerFilename,TargetOS,TargetCPU,false);
FPCVer:=CodeToolBoss.CompilerDefinesCache.GetPCVersion(
CompilerFilename,TargetOS,TargetCPU,false,CompilerKind);
if CompilerKind<>pcFPC then
;// ToDo
FPCSrcDir:=EnvironmentOptions.GetParsedFPCSourceDirectory(FPCVer);
if FilenameIsAbsolute(FPCSrcDir) then begin
// FPCSrcDir exists => use the errore.msg
@ -3078,9 +3082,12 @@ begin
end;
function TIDEFPCParser.GetDefaultPCFullVersion: LongWord;
var
Kind: TPascalCompiler;
begin
// get FPC version
Result:=LongWord(CodeToolBoss.GetPCVersionForDirectory(Tool.WorkerDirectory));
// get compiler version
Result:=LongWord(CodeToolBoss.GetPCVersionForDirectory(Tool.WorkerDirectory,Kind));
if Kind=pcFPC then ;
end;
function TIDEFPCParser.ToUTF8(const Line: string): string;

View File

@ -6644,11 +6644,12 @@ var
UnitOutputDirectory: String;
TargetExeName: String;
TargetExeDirectory: String;
FPCVersion, FPCRelease, FPCPatch: integer;
CompilerVersion: integer;
aCompileHint, ShortFilename: String;
OldToolStatus: TIDEToolStatus;
IsComplete: Boolean;
StartTime: TDateTime;
CompilerKind: TPascalCompiler;
begin
if DoAbortBuild(true)<>mrOK then begin
debugln(['Error: (lazarus) [TMainIDE.DoBuildProject] DoAbortBuild failed']);
@ -6692,9 +6693,14 @@ begin
if (Project1.ProjResources.ResourceType=rtRes) then begin
// FPC resources are only supported with FPC 2.4+
CodeToolBoss.GetFPCVersionForDirectory(
ExtractFilePath(Project1.MainFilename),FPCVersion,FPCRelease,FPCPatch);
if (FPCVersion=2) and (FPCRelease<4) then begin
CompilerVersion:=CodeToolBoss.GetPCVersionForDirectory(
ExtractFilePath(Project1.MainFilename),CompilerKind);
{debugln(['TMainIDE.DoBuildProject ',PascalCompilerNames[CompilerKind],' Version=',CompilerVersion]);
if CompilerVersion=0 then begin
CodeToolBoss.DefineTree.GetDefinesForDirectory(ExtractFilePath(Project1.MainFilename),true).WriteDebugReport;
end;}
if (CompilerKind=pcFPC) and (CompilerVersion>0) and (CompilerVersion<20400)
then begin
IDEMessageDialog(lisFPCTooOld,
lisTheProjectUsesFPCResourcesWhichRequireAtLeast,
mtError,[mbCancel]);
@ -7485,18 +7491,18 @@ end;
function TMainIDE.DoSaveBuildIDEConfigs(Flags: TBuildLazarusFlags): TModalResult;
var
InheritedOptionStrings: TInheritedCompOptsStrings;
FPCVersion, FPCRelease, FPCPatch: integer;
Builder: TLazarusBuilder;
CompilerKind: TPascalCompiler;
begin
// create uses section addition for lazarus.pp
Result:=PkgBoss.DoSaveAutoInstallConfig;
if Result<>mrOk then exit;
// check ambiguous units
CodeToolBoss.GetFPCVersionForDirectory(
CodeToolBoss.GetPCVersionForDirectory(
EnvironmentOptions.GetParsedLazarusDirectory,
FPCVersion,FPCRelease,FPCPatch);
if (FPCVersion=0) or (FPCRelease=0) or (FPCPatch=0) then ;
CompilerKind);
if CompilerKind=pcFPC then ;
// save extra options
Builder:=TLazarusBuilder.Create;
@ -7522,9 +7528,10 @@ var
IDEBuildFlags: TBuildLazarusFlags;
InheritedOptionStrings: TInheritedCompOptsStrings;
CompiledUnitExt: String;
FPCVersion, FPCRelease, FPCPatch: integer;
CompilerVersion: integer;
PkgCompileFlags: TPkgCompileFlags;
OldToolStatus: TIDEToolStatus;
CompilerKind: TPascalCompiler;
begin
if ToolStatus<>itNone then begin
IDEMessageDialog(lisNotNow,lisYouCanNotBuildLazarusWhileDebuggingOrCompiling,
@ -7604,10 +7611,10 @@ begin
fBuilder.PackageOptions:=PackageGraph.GetIDEInstallPackageOptions(InheritedOptionStrings{%H-});
// check ambiguous units
CodeToolBoss.GetFPCVersionForDirectory(EnvironmentOptions.GetParsedLazarusDirectory,
FPCVersion,FPCRelease,FPCPatch);
if FPCPatch=0 then ;
CompiledUnitExt:=GetDefaultCompiledUnitExt(FPCVersion,FPCRelease);
CompilerVersion:=CodeToolBoss.GetPCVersionForDirectory(
EnvironmentOptions.GetParsedLazarusDirectory,CompilerKind);
if CompilerKind=pcFPC then ;
CompiledUnitExt:=GetDefaultCompiledUnitExt(CompilerVersion div 10000,CompilerVersion div 100);
Result:=MainBuildBoss.CheckUnitPathForAmbiguousPascalFiles(
EnvironmentOptions.GetParsedLazarusDirectory+PathDelim+'ide',
InheritedOptionStrings[icoUnitPath],

View File

@ -1053,7 +1053,7 @@ function TLazPackageGraph.GetPackageCompilerParams(APackage: TLazPackage
begin
Result:=APackage.CompilerOptions.MakeOptionsString(
APackage.CompilerOptions.DefaultMakeOptionsFlags+[ccloAbsolutePaths])
+' '+CreateRelativePath(APackage.GetSrcFilename,APackage.Directory);
+' '+PrepareCmdLineOption(CreateRelativePath(APackage.GetSrcFilename,APackage.Directory));
end;
constructor TLazPackageGraph.Create;