ide+codetools: fpc config cache: support working directory and @ param, fixed #40603

This commit is contained in:
mattias 2023-11-20 16:40:48 +01:00
parent 14e1844066
commit c9aa80149c
5 changed files with 168 additions and 75 deletions

View File

@ -1144,7 +1144,7 @@ var
FPCDefines: TDefineTemplate;
FPCSrcDefines: TDefineTemplate;
LazarusSrcDefines: TDefineTemplate;
CurFPCOptions: String;
CurFPCOptions, WorkDir: String;
UnitSetCache: TFPCUnitSetCache;
//CfgCache: TPCTargetConfigCache;
@ -1171,8 +1171,13 @@ begin
if CompilerDefinesCache.TestFilename='' then
CompilerDefinesCache.TestFilename:=GetTempFilename('fpctest.pas','');
WorkDir:='';
if FilenameIsAbsolute(Config.ProjectDir) and HasFPCParamsRelativeFilename(Config.FPCOptions) then
WorkDir:=Config.ProjectDir;
UnitSetCache:=CompilerDefinesCache.FindUnitSet(Config.FPCPath,
Config.TargetOS,Config.TargetProcessor,Config.Subtarget,Config.FPCOptions,Config.FPCSrcDir,
Config.TargetOS,Config.TargetProcessor,Config.Subtarget,
Config.FPCOptions,Config.FPCSrcDir,WorkDir,
true);
// parse compiler settings, fpc sources
UnitSetCache.Init;

View File

@ -840,6 +840,7 @@ type
Subtarget: string; // will be passed lowercase
Compiler: string; // full file name
CompilerOptions: string; // e.g. -V<version> -Xp<path>
WorkingDir: string;
// values
Kind: TPascalCompiler;
CompilerDate: longint;
@ -912,7 +913,7 @@ type
CreateIfNotExists: boolean): TPCTargetConfigCache;
function Find(CompilerFilename, CompilerOptions, TargetOS, TargetCPU: string;
CreateIfNotExists: boolean): TPCTargetConfigCache;
function Find(CompilerFilename, CompilerOptions, TargetOS, TargetCPU, Subtarget: string;
function Find(CompilerFilename, CompilerOptions, TargetOS, TargetCPU, Subtarget, WorkDir: string;
CreateIfNotExists: boolean): TPCTargetConfigCache;
procedure GetDefaultCompilerTarget(const CompilerFilename,CompilerOptions: string;
out TargetOS, TargetCPU: string);
@ -1003,14 +1004,16 @@ type
fUnitStampOfFPC: integer; // FConfigCache.ChangeStamp at creation of fUnitToSourceTree
fUnitStampOfRules: integer; // fSourceRules.ChangeStamp at creation of fUnitToSourceTree
fUnitToSourceTree: TStringToStringTree; // unit name to file name (maybe relative)
procedure SetCompilerFilename(const AValue: string);
FWorkingDir: string;
procedure ClearConfigCache;
procedure ClearSourceCache;
procedure SetCompilerFilename(AValue: string);
procedure SetCompilerOptions(const AValue: string);
procedure SetFPCSourceDirectory(const AValue: string);
procedure SetFPCSourceDirectory(AValue: string);
procedure SetSubtarget(AValue: string);
procedure SetTargetCPU(const AValue: string);
procedure SetTargetOS(const AValue: string);
procedure ClearConfigCache;
procedure ClearSourceCache;
procedure SetWorkingDir(AValue: string);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation);
override;
@ -1020,12 +1023,16 @@ type
procedure Clear;
procedure Init;
property Caches: TCompilerDefinesCache read FCaches;
// key:
property CompilerFilename: string read FCompilerFilename write SetCompilerFilename;
property CompilerOptions: string read FCompilerOptions write SetCompilerOptions;
property TargetOS: string read FTargetOS write SetTargetOS; // case insensitive, will be passed lowercase
property TargetCPU: string read FTargetCPU write SetTargetCPU; // case insensitive, will be passed lowercase
property Subtarget: string read FSubtarget write SetSubtarget; // case insensitive, will be passed lowercase
property WorkingDir: string read FWorkingDir write SetWorkingDir;
property FPCSourceDirectory: string read FFPCSourceDirectory write SetFPCSourceDirectory;
function GetConfigCache(AutoUpdate: boolean): TPCTargetConfigCache;
function GetSourceCache(AutoUpdate: boolean): TFPCSourceCache;
function GetSourceRules(AutoUpdate: boolean): TFPCSourceRules;
@ -1082,14 +1089,14 @@ type
Options, FPCSrcDir: string;
CreateIfNotExists: boolean): TFPCUnitSetCache;
function FindUnitSet(const CompilerFilename, TargetOS, TargetCPU, Subtarget,
Options, FPCSrcDir: string;
Options, FPCSrcDir, WorkDir: string;
CreateIfNotExists: boolean): TFPCUnitSetCache;
function FindUnitSetWithID(const UnitSetID: string; out Changed: boolean;
CreateIfNotExists: boolean): TFPCUnitSetCache;
function GetUnitSetID(CompilerFilename, TargetOS, TargetCPU, Subtarget, Options,
FPCSrcDir: string; ChangeStamp: integer): string;
FPCSrcDir, WorkDir: string; ChangeStamp: integer): string;
procedure ParseUnitSetID(const ID: string; out CompilerFilename,
TargetOS, TargetCPU, Subtarget, Options, FPCSrcDir: string;
TargetOS, TargetCPU, Subtarget, Options, FPCSrcDir, WorkDir: string;
out ChangeStamp: integer);
end;
@ -1171,7 +1178,8 @@ function RunFPCVerbose(const CompilerFilename, TestFilename: string;
out IncludePaths: TStrings;
out UnitScopes: TStrings; // unit scopes/namespaces
out Defines, Undefines: TStringToStringTree;
const Options: string = ''): boolean;
const Options: string = '';
const WorkDir: string = ''): boolean;
procedure GatherUnitsInSearchPaths(SearchUnitPaths, SearchIncludePaths: TStrings;
const OnProgress: TDefinePoolProgress;
out Units: TStringToStringTree;
@ -1218,7 +1226,7 @@ type
fpkValue,
fpkMultiValue, // e.g. -k
fpkDefine, // -d and -u options
fpkConfig, // @ parameter
fpkConfig, // @ parameter, Name='', Value=filename
fpkNonOption // e.g. source file
);
TFPCParamFlag = (
@ -1247,6 +1255,8 @@ function IndexOfFPCParamValue(ParsedParams: TObjectList { list of TFPCParamValue
const Name: string): integer;
function GetFPCParamValue(ParsedParams: TObjectList { list of TFPCParamValue };
const Name: string): TFPCParamValue;
function IndexOfFPCParamWithRelativeFile(ParsedParams: TObjectList): integer;
function HasFPCParamsRelativeFilename(const CmdLineParams: string): boolean;
function dbgs(k: TFPCParamKind): string; overload;
function dbgs(f: TFPCParamFlag): string; overload;
function dbgs(const Flags: TFPCParamFlags): string; overload;
@ -1508,6 +1518,8 @@ begin
DbgOut(['Hint: (lazarus) [RunTool] "',Filename,'"']);
for i:=0 to Params.Count-1 do
dbgout(' "',Params[i],'"');
if WorkingDirectory<>'' then
DbgOut([', WorkDir="',WorkingDirectory,'"']);
Debugln;
end;
TheProcess := TProcessUTF8.Create(nil);
@ -1888,11 +1900,11 @@ end;
function RunFPCVerbose(const CompilerFilename, TestFilename: string; out
ConfigFiles: TStrings; out RealCompilerFilename: string; out
UnitPaths: TStrings; out IncludePaths: TStrings; out UnitScopes: TStrings;
out Defines, Undefines: TStringToStringTree; const Options: string): boolean;
out Defines, Undefines: TStringToStringTree; const Options: string;
const WorkDir: string): boolean;
var
Params: TStringList;
Filename: String;
WorkDir: String;
List: TStringList;
fs: TFileStream;
begin
@ -1905,25 +1917,26 @@ begin
Defines:=nil;
Undefines:=nil;
Params:=TStringList.Create;
Filename:='';
List:=nil;
Params:=TStringList.Create;
try
Params.Add('-va');
if TestFilename<>'' then begin
Filename:=TestFilename;
if (not FilenameIsAbsolute(Filename)) and FilenameIsAbsolute(WorkDir) then
Filename:=ResolveDots(AppendPathDelim(WorkDir)+Filename);
// create empty file
try
fs:=TFileStream.Create(TestFilename,fmCreate);
fs:=TFileStream.Create(Filename,fmCreate);
fs.Free;
except
debugln(['Warning: [RunFPCVerbose] unable to create test file "'+TestFilename+'"']);
debugln(['Warning: [RunFPCVerbose] unable to create test file "'+Filename+'"']);
exit;
end;
Filename:=ExtractFileName(TestFilename);
WorkDir:=ExtractFilePath(TestFilename);
Params.Add(Filename);
end else
WorkDir:='';
end;
SplitCmdLineParams(Options,Params);
@ -1938,8 +1951,8 @@ begin
finally
Params.Free;
List.Free;
if TestFilename<>'' then
DeleteFileUTF8(TestFilename);
if Filename<>'' then
DeleteFileUTF8(Filename);
end;
end;
@ -3374,6 +3387,44 @@ begin
Result:=TFPCParamValue(ParsedParams[i]);
end;
function IndexOfFPCParamWithRelativeFile(ParsedParams: TObjectList): integer;
function IsRelativeFile(const Param: string): boolean;
begin
Result:=(Param<>'') and not FilenameIsAbsolute(Param);
end;
var
Param: TFPCParamValue;
i: Integer;
begin
Result:=-1;
if ParsedParams=nil then exit;
for i:=0 to ParsedParams.Count-1 do begin
Param:=TFPCParamValue(ParsedParams[i]);
case Param.Kind of
fpkConfig:
exit(i); // a custom config has potentially a relative filename
fpkNonOption:
if IsRelativeFile(Param.Value) then
exit(i);
end;
end;
end;
function HasFPCParamsRelativeFilename(const CmdLineParams: string): boolean;
var
ParsedParams: TObjectList;
begin
ParsedParams:=TObjectList.Create(true);
try
ParseFPCParameter(CmdLineParams,ParsedParams);
Result:=IndexOfFPCParamWithRelativeFile(ParsedParams)>=0;
finally
ParsedParams.Free;
end;
end;
function dbgs(k: TFPCParamKind): string;
begin
str(k,Result);
@ -3599,6 +3650,8 @@ begin
Result:=CompareFilenames(Item1.Compiler,Item2.Compiler);
if Result<>0 then exit;
Result:=CompareFilenames(Item1.CompilerOptions,Item2.CompilerOptions);
if Result<>0 then exit;
Result:=CompareFilenames(Item1.WorkingDir,Item2.WorkingDir);
end;
function CompareFPCSourceCacheItems(CacheItem1, CacheItem2: Pointer): integer;
@ -6420,7 +6473,7 @@ begin
Params.Add('-va');
if (PosI('pas2js',ExtractFileName(CompilerPath))<1)
and FileExistsCached(EnglishErrorMsgFilename) then
Params.Add('-Fr'+EnglishErrorMsgFilename);
Params.Add('-Fr'+EnglishErrorMsgFilename);
if CompilerOptions<>'' then
SplitCmdLineParams(CompilerOptions,Params,true);
Params.Add(TestPascalFile);
@ -9772,6 +9825,7 @@ begin
or (not SameText(Subtarget,Item.Subtarget))
or (Compiler<>Item.Compiler)
or (CompilerOptions<>Item.CompilerOptions)
or (WorkingDir<>Item.WorkingDir)
then
exit;
end;
@ -9868,6 +9922,7 @@ begin
Subtarget:=Item.Subtarget;
Compiler:=Item.Compiler;
CompilerOptions:=Item.CompilerOptions;
WorkingDir:=Item.WorkingDir;
// values
Kind:=Item.Kind;
CompilerDate:=Item.CompilerDate;
@ -10021,6 +10076,7 @@ begin
Compiler:=XMLConfig.GetValue(Path+'Compiler/File','');
CompilerOptions:=XMLConfig.GetValue(Path+'Compiler/Options','');
CompilerDate:=XMLConfig.GetValue(Path+'Compiler/Date',0);
WorkingDir:=XMLConfig.GetValue(Path+'WorkingDir','');
RealCompiler:=XMLConfig.GetValue(Path+'RealCompiler/File','');
RealCompilerDate:=XMLConfig.GetValue(Path+'RealCompiler/Date',0);
RealTargetOS:=XMLConfig.GetValue(Path+'RealCompiler/OS','');
@ -10207,6 +10263,7 @@ begin
XMLConfig.SetDeleteValue(Path+'Compiler/File',Compiler,'');
XMLConfig.SetDeleteValue(Path+'Compiler/Options',CompilerOptions,'');
XMLConfig.SetDeleteValue(Path+'Compiler/Date',CompilerDate,0);
XMLConfig.SetDeleteValue(Path+'WorkingDir',WorkingDir,'');
XMLConfig.SetDeleteValue(Path+'RealCompiler/File',RealCompiler,'');
XMLConfig.SetDeleteValue(Path+'RealCompiler/Date',RealCompilerDate,0);
XMLConfig.SetDeleteValue(Path+'RealCompiler/OS',RealTargetOS,'');
@ -10322,7 +10379,7 @@ function TPCTargetConfigCache.NeedsUpdate: boolean;
procedure DebugMissing(const Msg: string);
begin
if CTConsoleVerbosity>0 then
debugln(['Hint: [TPCTargetConfigCache.NeedsUpdate] TargetOS="',TargetOS,'" TargetCPU="',TargetCPU,'" Subtarget="',Subtarget,'" Options="',CompilerOptions,'" ',Msg]);
debugln(['Hint: [TPCTargetConfigCache.NeedsUpdate] TargetOS="',TargetOS,'" TargetCPU="',TargetCPU,'" Subtarget="',Subtarget,'" WorkDir="',WorkingDir,'" Options="',CompilerOptions,'" ',Msg]);
end;
var
@ -10415,7 +10472,7 @@ var
Infos: TFPCInfoStrings;
InfoTypes: TFPCInfoTypes;
BaseDir: String;
FullFilename, KindErrorMsg: String;
FullFilename, KindErrorMsg, CurWorkDir: String;
begin
OldOptions:=TPCTargetConfigCache.Create(nil);
CfgFiles:=nil;
@ -10425,11 +10482,11 @@ begin
Clear;
if CTConsoleVerbosity>0 then
debugln(['Hint: [TPCTargetConfigCache.Update] ',Compiler,' TargetOS=',TargetOS,' TargetCPU=',TargetCPU,' Subtarget=',Subtarget,' CompilerOptions=',CompilerOptions,' ExtraOptions=',ExtraOptions,' PATH=',GetEnvironmentVariableUTF8('PATH')]);
debugln(['Hint: [TPCTargetConfigCache.Update] ',Compiler,' TargetOS=',TargetOS,' TargetCPU=',TargetCPU,' Subtarget=',Subtarget,' WorkDir="',WorkingDir,'" CompilerOptions="',CompilerOptions,'" ExtraOptions="',ExtraOptions,'" PATH=',GetEnvironmentVariableUTF8('PATH')]);
CompilerDate:=-1;
if FileExistsCached(Compiler) then begin
CompilerDate:=FileAgeCached(Compiler);
ExtraOptions:=GetFPCInfoCmdLineOptions(ExtraOptions);// add -PTargetCPU -TTargetOS -tSubtarget
ExtraOptions:=GetFPCInfoCmdLineOptions(ExtraOptions);// add -PTargetCPU -TTargetOS -tSubtarget and CompilerOptions
BaseDir:='';
// check if this is a FPC compatible compiler and get version, OS and CPU
@ -10457,8 +10514,14 @@ begin
if (Pos('-Fr',ExtraOptions)<1) and (Pos('-Fr',Caches.ExtraOptions)>0) then
ExtraOptions:=Trim(ExtraOptions+' '+Caches.ExtraOptions);
if FilenameIsAbsolute(WorkingDir) then
CurWorkDir:=WorkingDir
else
CurWorkDir:=ExtractFilePath(TestFilename);
//debugln('TPCTargetConfigCache.Update ExtraOptions="',ExtraOptions,'" CurWorkDir="',CurWorkDir,'" WorkingDir="',WorkingDir,'" TestFilename="',TestFilename,'"');
RunFPCVerbose(Compiler,TestFilename,CfgFiles,RealCompiler,UnitPaths,
IncludePaths,UnitScopes,Defines,Undefines,ExtraOptions);
IncludePaths,UnitScopes,Defines,Undefines,ExtraOptions,CurWorkDir);
//debugln(['TPCTargetConfigCache.Update UnitPaths="',UnitPaths.Text,'"']);
//debugln(['TPCTargetConfigCache.Update UnitScopes="',UnitScopes.Text,'"']);
//debugln(['TPCTargetConfigCache.Update IncludePaths="',IncludePaths.Text,'"']);
@ -10800,18 +10863,18 @@ end;
function TPCTargetConfigCaches.Find(CompilerFilename: string;
CreateIfNotExists: boolean): TPCTargetConfigCache;
begin
Result:=Find(CompilerFilename,'','','','',CreateIfNotExists);
Result:=Find(CompilerFilename,'','','','','',CreateIfNotExists);
end;
function TPCTargetConfigCaches.Find(CompilerFilename, CompilerOptions,
TargetOS, TargetCPU: string; CreateIfNotExists: boolean
): TPCTargetConfigCache;
begin
Result:=Find(CompilerFilename,CompilerOptions,TargetOS,TargetCPU,'',CreateIfNotExists);
Result:=Find(CompilerFilename,CompilerOptions,TargetOS,TargetCPU,'','',CreateIfNotExists);
end;
function TPCTargetConfigCaches.Find(CompilerFilename, CompilerOptions,
TargetOS, TargetCPU, Subtarget: string; CreateIfNotExists: boolean
TargetOS, TargetCPU, Subtarget, WorkDir: string; CreateIfNotExists: boolean
): TPCTargetConfigCache;
var
Node: TAVLTreeNode;
@ -10824,6 +10887,7 @@ begin
Cmp.TargetOS:=TargetOS;
Cmp.TargetCPU:=TargetCPU;
Cmp.Subtarget:=Subtarget;
Cmp.WorkingDir:=WorkDir;
Node:=fItems.Find(cmp);
if Node<>nil then begin
Result:=TPCTargetConfigCache(Node.Data);
@ -11481,12 +11545,12 @@ function TCompilerDefinesCache.FindUnitSet(const CompilerFilename, TargetOS,
TargetCPU, Options, FPCSrcDir: string; CreateIfNotExists: boolean
): TFPCUnitSetCache;
begin
Result:=FindUnitSet(CompilerFilename,TargetOS,TargetCPU,'',Options,FPCSrcDir,CreateIfNotExists);
Result:=FindUnitSet(CompilerFilename,TargetOS,TargetCPU,'',Options,FPCSrcDir,'',CreateIfNotExists);
end;
function TCompilerDefinesCache.FindUnitSet(const CompilerFilename, TargetOS,
TargetCPU, Subtarget, Options, FPCSrcDir: string; CreateIfNotExists: boolean
): TFPCUnitSetCache;
TargetCPU, Subtarget, Options, FPCSrcDir, WorkDir: string;
CreateIfNotExists: boolean): TFPCUnitSetCache;
var
i: Integer;
begin
@ -11497,6 +11561,7 @@ begin
and (SysUtils.CompareText(Result.TargetCPU,TargetCPU)=0)
and (SysUtils.CompareText(Result.Subtarget,Subtarget)=0)
and (CompareFilenames(Result.FPCSourceDirectory,FPCSrcDir)=0)
and (CompareFilenames(Result.WorkingDir,WorkDir)=0)
and (Result.CompilerOptions=Options)
then
exit;
@ -11509,6 +11574,7 @@ begin
Result.TargetCPU:=TargetCPU;
Result.Subtarget:=Subtarget;
Result.FPCSourceDirectory:=FPCSrcDir;
Result.WorkingDir:=WorkDir;
fUnitToSrcCaches.Add(Result);
end else
Result:=nil;
@ -11517,27 +11583,28 @@ end;
function TCompilerDefinesCache.FindUnitSetWithID(const UnitSetID: string; out
Changed: boolean; CreateIfNotExists: boolean): TFPCUnitSetCache;
var
CompilerFilename, TargetOS, TargetCPU, Subtarget, Options, FPCSrcDir: string;
CompilerFilename, TargetOS, TargetCPU, Subtarget, Options, FPCSrcDir,
WorkDir: string;
ChangeStamp: integer;
begin
ParseUnitSetID(UnitSetID,CompilerFilename, TargetOS, TargetCPU, Subtarget,
Options, FPCSrcDir, ChangeStamp);
Options, FPCSrcDir, WorkDir, ChangeStamp);
//debugln(['TCompilerDefinesCache.FindUnitToSrcCache UnitSetID="',dbgstr(UnitSetID),'" CompilerFilename="',CompilerFilename,'" TargetOS="',TargetOS,'" TargetCPU="',TargetCPU,'" Options="',Options,'" FPCSrcDir="',FPCSrcDir,'" ChangeStamp=',ChangeStamp,' exists=',FindUnitToSrcCache(CompilerFilename, TargetOS, TargetCPU,Options, FPCSrcDir,false)<>nil]);
Result:=FindUnitSet(CompilerFilename, TargetOS, TargetCPU, Subtarget,
Options, FPCSrcDir, false);
Options, FPCSrcDir, WorkDir, false);
if Result<>nil then begin
Changed:=ChangeStamp<>Result.ChangeStamp;
end else if CreateIfNotExists then begin
Changed:=true;
Result:=FindUnitSet(CompilerFilename, TargetOS, TargetCPU, Subtarget,
Options, FPCSrcDir, true);
Options, FPCSrcDir, WorkDir, true);
end else
Changed:=false;
end;
function TCompilerDefinesCache.GetUnitSetID(CompilerFilename, TargetOS,
TargetCPU, Subtarget, Options, FPCSrcDir: string; ChangeStamp: integer
): string;
TargetCPU, Subtarget, Options, FPCSrcDir, WorkDir: string;
ChangeStamp: integer): string;
procedure Add(const aName, aValue: string);
begin
@ -11553,12 +11620,13 @@ begin
Add('Subtarget',Subtarget);
Add('Options',Options);
Add('FPCSrcDir',FPCSrcDir);
Add('WorkDir',WorkDir);
Add('Stamp',IntToStr(ChangeStamp));
end;
procedure TCompilerDefinesCache.ParseUnitSetID(const ID: string; out
CompilerFilename, TargetOS, TargetCPU, Subtarget, Options, FPCSrcDir: string;
out ChangeStamp: integer);
CompilerFilename, TargetOS, TargetCPU, Subtarget, Options, FPCSrcDir,
WorkDir: string; out ChangeStamp: integer);
var
NameStartPos: PChar;
@ -11585,6 +11653,7 @@ begin
Subtarget:='';
Options:='';
FPCSrcDir:='';
WorkDir:='';
ChangeStamp:=0;
if ID='' then exit;
// read the lines with name=value
@ -11619,6 +11688,9 @@ begin
TargetOS:=Value
else if NameFits('TargetCPU') then
TargetCPU:=Value;
'w','W':
if NameFits('WorkDir') then
WorkDir:=Value;
end;
NameStartPos:=ValueEndPos;
end;
@ -11626,13 +11698,11 @@ end;
{ TFPCUnitSetCache }
procedure TFPCUnitSetCache.SetCompilerFilename(const AValue: string);
var
NewFilename: String;
procedure TFPCUnitSetCache.SetCompilerFilename(AValue: string);
begin
NewFilename:=ResolveDots(AValue);
if FCompilerFilename=NewFilename then exit;
FCompilerFilename:=NewFilename;
AValue:=ResolveDots(AValue);
if FCompilerFilename=AValue then exit;
FCompilerFilename:=AValue;
ClearConfigCache;
end;
@ -11643,13 +11713,11 @@ begin
ClearConfigCache;
end;
procedure TFPCUnitSetCache.SetFPCSourceDirectory(const AValue: string);
var
NewValue: String;
procedure TFPCUnitSetCache.SetFPCSourceDirectory(AValue: string);
begin
NewValue:=TrimAndExpandDirectory(AValue);
if FFPCSourceDirectory=NewValue then exit;
FFPCSourceDirectory:=NewValue;
AValue:=TrimAndExpandDirectory(AValue);
if FFPCSourceDirectory=AValue then exit;
FFPCSourceDirectory:=AValue;
ClearSourceCache;
end;
@ -11686,6 +11754,14 @@ begin
Include(fFlags,fuscfUnitTreeNeedsUpdate);
end;
procedure TFPCUnitSetCache.SetWorkingDir(AValue: string);
begin
AValue:=AppendPathDelim(ResolveDots(AValue)); // do not expand! A '' must remain ''
if FWorkingDir=AValue then Exit;
FWorkingDir:=AValue;
ClearConfigCache;
end;
procedure TFPCUnitSetCache.Notification(AComponent: TComponent;
Operation: TOperation);
begin
@ -11739,12 +11815,12 @@ begin
raise Exception.Create('TFPCUnitToSrcCache.GetConfigCache missing TestFilename');
if FConfigCache=nil then begin
FConfigCache:=Caches.ConfigCaches.Find(CompilerFilename,CompilerOptions,
TargetOS,TargetCPU,true);
TargetOS,TargetCPU,Subtarget,WorkingDir,true);
FConfigCache.FreeNotification(Self);
end;
//debugln(['TFPCUnitSetCache.GetConfigCache CompilerOptions="',CompilerOptions,'" FConfigCache.CompilerOptions="',FConfigCache.CompilerOptions,'"']);
if AutoUpdate and FConfigCache.NeedsUpdate then
FConfigCache.Update(Caches.TestFilename,Caches.ExtraOptions);
FConfigCache.Update(Caches.TestFilename,'');
Result:=FConfigCache;
end;
@ -11939,7 +12015,7 @@ end;
function TFPCUnitSetCache.GetUnitSetID: string;
begin
Result:=Caches.GetUnitSetID(CompilerFilename,TargetOS,TargetCPU,Subtarget,
CompilerOptions,FPCSourceDirectory,ChangeStamp);
CompilerOptions,FPCSourceDirectory,WorkingDir,ChangeStamp);
end;
function TFPCUnitSetCache.GetFirstFPCCfg: string;

View File

@ -1022,7 +1022,7 @@ var
HasTemplate: Boolean;
CompilerErrorMsg: string;
Msg, DefCompilerFilename, ProjCompilerFilename, ProjCompilerErrorMsg,
DefCompilerErrorMsg: String;
DefCompilerErrorMsg, WorkDir: String;
CompilerKind, ProjCompilerKind, DefCompilerKind: TPascalCompiler;
begin
if ClearCaches then begin
@ -1075,7 +1075,7 @@ begin
debugln(['TBuildManager.RescanCompilerDefines reading default compiler settings']);
{$ENDIF}
UnitSetCache:=CodeToolBoss.CompilerDefinesCache.FindUnitSet(
DefCompilerFilename,'','','','',FPCSrcDir,true);
DefCompilerFilename,'','','','',FPCSrcDir,'',true);
UnitSetCache.GetConfigCache(true);
end;
@ -1118,9 +1118,14 @@ begin
{$IFDEF VerboseFPCSrcScan}
debugln(['TBuildManager.RescanCompilerDefines reading active compiler settings']);
{$ENDIF}
//debugln(['TBuildManager.RescanCompilerDefines ',CompilerFilename,' OS=',TargetOS,' CPU=',TargetCPU,' Subtarget=',Subtarget,' Options="',FPCOptions,'"']);
WorkDir:='';
if (FBuildTarget<>nil) and (not FBuildTarget.IsVirtual)
and HasFPCParamsRelativeFilename(FPCOptions) then
WorkDir:=FBuildTarget.Directory;
//debugln(['TBuildManager.RescanCompilerDefines ',CompilerFilename,' OS=',TargetOS,' CPU=',TargetCPU,' Subtarget=',Subtarget,' Options="',FPCOptions,'" WorkDir="',WorkDir,'"']);
UnitSetCache:=CodeToolBoss.CompilerDefinesCache.FindUnitSet(
CompilerFilename,TargetOS,TargetCPU,Subtarget,FPCOptions,FPCSrcDir,true);
CompilerFilename,TargetOS,TargetCPU,Subtarget,FPCOptions,FPCSrcDir,WorkDir,true);
NeedUpdateFPCSrcCache:=false;
//debugln(['TBuildManager.RescanCompilerDefines ',DirectoryExistsUTF8(FPCSrcDir),' ',(not WaitTillDone),' ',(not HasGUI)]);
@ -1152,14 +1157,15 @@ begin
{$IFDEF VerboseFPCSrcScan}
debugln(['TBuildManager.RescanCompilerDefines UnitSet changed=',UnitSetChanged,
' ClearCaches=',ClearCaches,
' CompilerFilename=',CompilerFilename,
' TargetOS=',TargetOS,
' TargetCPU=',TargetCPU,
' Subtarget=',Subtarget,
' FPCOptions="',FPCOptions,'"',
' CompilerFilename=',UnitSetCache.CompilerFilename,
' TargetOS=',UnitSetCache.TargetOS,
' TargetCPU=',UnitSetCache.TargetCPU,
' Subtarget=',UnitSetCache.Subtarget,
' WorkDir=',UnitSetCache.WorkingDir,
' FPCOptions="',UnitSetCache.CompilerOptions,'"',
' RealCompiler=',UnitSetCache.GetConfigCache(false).RealCompiler,
' EnvFPCSrcDir=',EnvironmentOptions.FPCSourceDirectory,
' FPCSrcDir=',FPCSrcDir,
' FPCSrcDir=',UnitSetCache.FPCSourceDirectory,
'']);
{$ENDIF}
@ -2321,8 +2327,7 @@ function TBuildManager.MacroFuncFPCVer(const Param: string; const Data: PtrInt;
if ConfigCache=nil then exit;
if ConfigCache.NeedsUpdate then begin
// ask compiler
if not ConfigCache.Update(CodeToolBoss.CompilerDefinesCache.TestFilename,
CodeToolBoss.CompilerDefinesCache.ExtraOptions,nil)
if not ConfigCache.Update(CodeToolBoss.CompilerDefinesCache.TestFilename,'',nil)
then
exit;
end;

View File

@ -618,7 +618,7 @@ begin
TargetProcessor:='';
UnitSetCache:=Boss.CompilerDefinesCache.FindUnitSet(CompilerPath,
TargetOS,TargetProcessor,'','',FPCSrcDir,true);
TargetOS,TargetProcessor,'','',FPCSrcDir,'',true);
// create directory defines
DirTemplate:=TDefineTemplate.Create('FPC Project ('+FileNames[0]+')',
@ -727,7 +727,7 @@ begin
DebugLn(' FPCSrcDir="',FPCSrcDir,'"');
UnitSetCache:=Boss.CompilerDefinesCache.FindUnitSet(CompilerPath,
TargetOS,TargetProcessor,'','',FPCSrcDir,true);
TargetOS,TargetProcessor,'','',FPCSrcDir,'',true);
// create FPC Source defines
FPCSrcTemplate:=CreateFPCSourceTemplate(UnitSetCache,CodeToolsOpts);
if FPCSrcTemplate=nil then begin

View File

@ -127,7 +127,7 @@ begin
CompilerFilename:=LazarusIDE.GetCompilerFilename;
FPCSrcDir:=EnvironmentOptions.GetParsedFPCSourceDirectory; // needs FPCVer macro
UnitSetCache:=CodeToolBoss.CompilerDefinesCache.FindUnitSet(
CompilerFilename,TargetOS,TargetCPU,Subtarget,'',FPCSrcDir,true);
CompilerFilename,TargetOS,TargetCPU,Subtarget,'',FPCSrcDir,'',true);
GatherFPCExecutable(UnitSetCache,sl);
ValuesMemo.Lines.Assign(sl);
@ -185,18 +185,25 @@ begin
List.Free;
sl.Add('');
// fpc -va
TargetOS:=BuildBoss.GetTargetOS;
TargetCPU:=BuildBoss.GetTargetCPU;
Subtarget:=BuildBoss.GetSubtarget;
WorkDir:='';
if (Project1<>nil) and (not Project1.IsVirtual)
and HasFPCParamsRelativeFilename(CompilerOptions) then
WorkDir:=Project1.Directory;
Cfg:=CodeToolBoss.CompilerDefinesCache.ConfigCaches.Find(
CompilerFilename,CompilerOptions,TargetOS,TargetCPU,Subtarget,true);
CompilerFilename,CompilerOptions,TargetOS,TargetCPU,Subtarget,WorkDir,true);
TestFilename:=CodeToolBoss.CompilerDefinesCache.TestFilename;
Filename:=ExtractFileName(TestFilename);
WorkDir:=ExtractFilePath(TestFilename);
sl.Add('The IDE asks the compiler with the following command for paths and macros:');
ExtraOptions:=Cfg.GetFPCInfoCmdLineOptions(CodeToolBoss.CompilerDefinesCache.ExtraOptions);
Params:=Trim('-va '+ExtraOptions)+' '+Filename;
if WorkDir='' then
WorkDir:=ExtractFilePath(TestFilename);
sl.Add(CompilerFilename+' '+Params);
sl.Add('Working directory: '+WorkDir);
// create empty file