codetools: fpcdefines: started supported caching multiple targets

git-svn-id: trunk@26605 -
This commit is contained in:
mattias 2010-07-12 07:31:43 +00:00
parent 7e74198f7d
commit 7ece9907af

View File

@ -650,7 +650,9 @@ type
TFPCTargetConfigCaches = class; TFPCTargetConfigCaches = class;
{ TFPCTargetConfigCache } { TFPCTargetConfigCache
Storing all information (maros, search paths) of one compiler
with one specific TargetOS and TargetCPU. }
TFPCTargetConfigCache = class TFPCTargetConfigCache = class
private private
@ -689,7 +691,8 @@ type
property ChangeStamp: integer read FChangeStamp; property ChangeStamp: integer read FChangeStamp;
end; end;
{ TFPCTargetConfigCaches } { TFPCTargetConfigCaches
List of TFPCTargetConfigCache }
TFPCTargetConfigCaches = class TFPCTargetConfigCaches = class
private private
@ -711,7 +714,8 @@ type
TFPCSourceCaches = class; TFPCSourceCaches = class;
{ TFPCSourceCache } { TFPCSourceCache
All source files of one FPC source directory }
TFPCSourceCache = class TFPCSourceCache = class
private private
@ -750,42 +754,66 @@ type
procedure SaveToFile(Filename: string); procedure SaveToFile(Filename: string);
procedure IncreaseChangeStamp; procedure IncreaseChangeStamp;
property ChangeStamp: integer read FChangeStamp; property ChangeStamp: integer read FChangeStamp;
function Find(const Directory: string; function Find(Directory: string;
CreateIfNotExists: boolean): TFPCSourceCache; CreateIfNotExists: boolean): TFPCSourceCache;
end; end;
TFPCUnitCaches = class TFPCDefinesCache = class;
{ TFPCUnitToSrcCache
Unit name to FPC source file.
Specific to one compiler, targetos, targetcpu and FPC source directory. }
TFPCUnitToSrcCache = class
private
FCaches: TFPCDefinesCache;
FChangeStamp: integer;
FCompilerFilename: string;
FFPCSourceDirectory: string;
FTargetCPU: string;
FTargetOS: string;
FConfigCache: TFPCTargetConfigCache;
fSourceCache: TFPCSourceCache;
fFPCSourceRules: TFPCSourceRules;
fUnitToSourceTree: TStringToStringTree; // lowercase unit name to file name (maybe relative)
fSrcDuplicates: TStringToStringTree; // lower case unit to semicolon separated list of files
fOldUnitToSourceTree: TStringToStringTree;
procedure SetCompilerFilename(const AValue: string);
procedure SetFPCSourceDirectory(const AValue: string);
procedure SetTargetCPU(const AValue: string);
procedure SetTargetOS(const AValue: string);
procedure ClearConfigCache;
procedure ClearSourceCache;
public
constructor Create(Owner: TFPCDefinesCache);
destructor Destroy; override;
procedure Clear;
property Caches: TFPCDefinesCache read FCaches;
property CompilerFilename: string read FCompilerFilename write SetCompilerFilename;
property TargetOS: string read FTargetOS write SetTargetOS;
property TargetCPU: string read FTargetCPU write SetTargetCPU;
property FPCSourceDirectory: string read FFPCSourceDirectory write SetFPCSourceDirectory;
function GetConfigCache(AutoUpdate: boolean): TFPCTargetConfigCache;
function GetSourceCache(AutoUpdate: boolean): TFPCSourceCache;
function GetSourceRules(AutoUpdate: boolean): TFPCSourceRules;
function GetUnitToSourceTree(AutoUpdate: boolean): TStringToStringTree; // lowercase unit name to file name (maybe relative)
function GetSourceDuplicates(AutoUpdate: boolean): TStringToStringTree; // lower case unit to semicolon separated list of files
property ChangeStamp: integer read FChangeStamp;
end; end;
{ TFPCDefinesCache } { TFPCDefinesCache }
TFPCDefinesCache = class TFPCDefinesCache = class
private private
FCompilerFilename: string;
FConfigCaches: TFPCTargetConfigCaches; FConfigCaches: TFPCTargetConfigCaches;
FConfigCachesSaveStamp: integer; FConfigCachesSaveStamp: integer;
FFPCSourceDirectory: string;
FSourceCaches: TFPCSourceCaches; FSourceCaches: TFPCSourceCaches;
FSourceCachesSaveStamp: integer; FSourceCachesSaveStamp: integer;
FTargetCPU: string;
FTargetOS: string;
FConfigCache: TFPCTargetConfigCache;
fSourceCache: TFPCSourceCache;
fFPCSourceRules: TFPCSourceRules;
FTestFilename: string; FTestFilename: string;
fUnitToSourceTree: TStringToStringTree; // lowercase unit name to file name (maybe relative) fUnitToSrcCaches: TFPList; // list of TFPCUnitToSrcCache
fSrcDuplicates: TStringToStringTree; // lower case unit to semicolon separated list of files
FUnitToSourceTreeChangeStamp: integer;
fOldUnitToSourceTree: TStringToStringTree;
procedure SetCompilerFilename(const AValue: string);
procedure SetConfigCaches(const AValue: TFPCTargetConfigCaches); procedure SetConfigCaches(const AValue: TFPCTargetConfigCaches);
procedure SetFPCSourceDirectory(const AValue: string);
procedure SetSourceCaches(const AValue: TFPCSourceCaches); procedure SetSourceCaches(const AValue: TFPCSourceCaches);
procedure SetTargetCPU(const AValue: string); procedure ClearUnitToSrcCaches;
procedure SetTargetOS(const AValue: string);
procedure ClearConfigCache;
procedure ClearSourceCache;
public public
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
@ -797,17 +825,11 @@ type
function NeedsSave: boolean; function NeedsSave: boolean;
property SourceCaches: TFPCSourceCaches read FSourceCaches write SetSourceCaches; property SourceCaches: TFPCSourceCaches read FSourceCaches write SetSourceCaches;
property ConfigCaches: TFPCTargetConfigCaches read FConfigCaches write SetConfigCaches; property ConfigCaches: TFPCTargetConfigCaches read FConfigCaches write SetConfigCaches;
property CompilerFilename: string read FCompilerFilename write SetCompilerFilename; function FindUnitToSrcCache(const CompilerFilename, TargetOS, TargetCPU,
property TargetOS: string read FTargetOS write SetTargetOS; FPCSrcDir: string; CreateIfNotExists: boolean
property TargetCPU: string read FTargetCPU write SetTargetCPU; ): TFPCUnitToSrcCache;
property TestFilename: string read FTestFilename write FTestFilename; // an empty file to test the compiler, will be auto created property TestFilename: string read FTestFilename write FTestFilename; // an empty file to test the compiler, will be auto created
property FPCSourceDirectory: string read FFPCSourceDirectory write SetFPCSourceDirectory;
function GetConfigCache(AutoUpdate: boolean): TFPCTargetConfigCache;
function GetSourceCache(AutoUpdate: boolean): TFPCSourceCache;
function GetSourceRules(AutoUpdate: boolean): TFPCSourceRules;
function GetUnitToSourceTree(AutoUpdate: boolean): TStringToStringTree; // lowercase unit name to file name (maybe relative)
function GetSourceDuplicates(AutoUpdate: boolean): TStringToStringTree; // lower case unit to semicolon separated list of files
property UnitToSourceTreeChangeStamp: integer read FUnitToSourceTreeChangeStamp;
end; end;
function DefineActionNameToAction(const s: string): TDefineAction; function DefineActionNameToAction(const s: string): TDefineAction;
@ -7362,11 +7384,12 @@ begin
FChangeStamp:=Low(FChangeStamp); FChangeStamp:=Low(FChangeStamp);
end; end;
function TFPCSourceCaches.Find(const Directory: string; function TFPCSourceCaches.Find(Directory: string;
CreateIfNotExists: boolean): TFPCSourceCache; CreateIfNotExists: boolean): TFPCSourceCache;
var var
Node: TAVLTreeNode; Node: TAVLTreeNode;
begin begin
Directory:=ChompPathDelim(TrimFilename(Directory));
Node:=fItems.FindKey(PChar(Directory),@CompareDirectoryWithFPCSourceCacheItem); Node:=fItems.FindKey(PChar(Directory),@CompareDirectoryWithFPCSourceCacheItem);
if Node<>nil then begin if Node<>nil then begin
Result:=TFPCSourceCache(Node.Data); Result:=TFPCSourceCache(Node.Data);
@ -7388,21 +7411,6 @@ begin
if FConfigCaches=AValue then exit; if FConfigCaches=AValue then exit;
FConfigCaches:=AValue; FConfigCaches:=AValue;
FConfigCachesSaveStamp:=Low(FConfigCachesSaveStamp); FConfigCachesSaveStamp:=Low(FConfigCachesSaveStamp);
ClearConfigCache;
end;
procedure TFPCDefinesCache.SetCompilerFilename(const AValue: string);
begin
if FCompilerFilename=AValue then exit;
FCompilerFilename:=AValue;
ClearConfigCache;
end;
procedure TFPCDefinesCache.SetFPCSourceDirectory(const AValue: string);
begin
if FFPCSourceDirectory=AValue then exit;
FFPCSourceDirectory:=AValue;
ClearSourceCache;
end; end;
procedure TFPCDefinesCache.SetSourceCaches(const AValue: TFPCSourceCaches); procedure TFPCDefinesCache.SetSourceCaches(const AValue: TFPCSourceCaches);
@ -7410,60 +7418,37 @@ begin
if FSourceCaches=AValue then exit; if FSourceCaches=AValue then exit;
FSourceCaches:=AValue; FSourceCaches:=AValue;
FSourceCachesSaveStamp:=low(FSourceCachesSaveStamp); FSourceCachesSaveStamp:=low(FSourceCachesSaveStamp);
ClearSourceCache;
end; end;
procedure TFPCDefinesCache.SetTargetCPU(const AValue: string); procedure TFPCDefinesCache.ClearUnitToSrcCaches;
var
i: Integer;
begin begin
if FTargetCPU=AValue then exit; for i:=0 to fUnitToSrcCaches.Count-1 do
FTargetCPU:=AValue; TObject(fUnitToSrcCaches[i]).Free;
ClearConfigCache; fUnitToSrcCaches.Clear;
end;
procedure TFPCDefinesCache.SetTargetOS(const AValue: string);
begin
if FTargetOS=AValue then exit;
FTargetOS:=AValue;
ClearConfigCache;
end;
procedure TFPCDefinesCache.ClearConfigCache;
begin
FConfigCache:=nil;
FreeAndNil(fFPCSourceRules);
FreeAndNil(fUnitToSourceTree);
end;
procedure TFPCDefinesCache.ClearSourceCache;
begin
fSourceCache:=nil;
FreeAndNil(fUnitToSourceTree);
FreeAndNil(fSrcDuplicates);
end; end;
constructor TFPCDefinesCache.Create; constructor TFPCDefinesCache.Create;
begin begin
ConfigCaches:=TFPCTargetConfigCaches.Create; ConfigCaches:=TFPCTargetConfigCaches.Create;
SourceCaches:=TFPCSourceCaches.Create; SourceCaches:=TFPCSourceCaches.Create;
fOldUnitToSourceTree:=TStringToStringTree.Create(true); fUnitToSrcCaches:=TFPList.Create;
end; end;
destructor TFPCDefinesCache.Destroy; destructor TFPCDefinesCache.Destroy;
begin begin
ClearConfigCache; ClearUnitToSrcCaches;
ClearSourceCache;
FreeAndNil(FConfigCaches); FreeAndNil(FConfigCaches);
FreeAndNil(FSourceCaches); FreeAndNil(FSourceCaches);
FreeAndNil(fOldUnitToSourceTree);
inherited Destroy; inherited Destroy;
end; end;
procedure TFPCDefinesCache.Clear; procedure TFPCDefinesCache.Clear;
begin begin
ClearUnitToSrcCaches;
if ConfigCaches<>nil then ConfigCaches.Clear; if ConfigCaches<>nil then ConfigCaches.Clear;
ClearConfigCache;
if SourceCaches<>nil then SourceCaches.Clear; if SourceCaches<>nil then SourceCaches.Clear;
ClearSourceCache;
end; end;
procedure TFPCDefinesCache.LoadFromXMLConfig(XMLConfig: TXMLConfig; procedure TFPCDefinesCache.LoadFromXMLConfig(XMLConfig: TXMLConfig;
@ -7472,12 +7457,10 @@ begin
if ConfigCaches<>nil then begin if ConfigCaches<>nil then begin
ConfigCaches.LoadFromXMLConfig(XMLConfig,Path+'FPCConfigs/'); ConfigCaches.LoadFromXMLConfig(XMLConfig,Path+'FPCConfigs/');
FConfigCachesSaveStamp:=ConfigCaches.ChangeStamp; FConfigCachesSaveStamp:=ConfigCaches.ChangeStamp;
ClearConfigCache;
end; end;
if SourceCaches<>nil then begin if SourceCaches<>nil then begin
SourceCaches.LoadFromXMLConfig(XMLConfig,Path+'FPCSources/'); SourceCaches.LoadFromXMLConfig(XMLConfig,Path+'FPCSources/');
FSourceCachesSaveStamp:=SourceCaches.ChangeStamp; FSourceCachesSaveStamp:=SourceCaches.ChangeStamp;
ClearSourceCache;
end; end;
end; end;
@ -7528,30 +7511,102 @@ begin
Result:=false; Result:=false;
end; end;
function TFPCDefinesCache.GetConfigCache(AutoUpdate: boolean function TFPCDefinesCache.FindUnitToSrcCache(const CompilerFilename, TargetOS,
TargetCPU, FPCSrcDir: string; CreateIfNotExists: boolean
): TFPCUnitToSrcCache;
begin
Result:=nil;
end;
{ TFPCUnitToSrcCache }
procedure TFPCUnitToSrcCache.SetCompilerFilename(const AValue: string);
begin
if FCompilerFilename=AValue then exit;
FCompilerFilename:=AValue;
ClearConfigCache;
end;
procedure TFPCUnitToSrcCache.SetFPCSourceDirectory(const AValue: string);
begin
if FFPCSourceDirectory=AValue then exit;
FFPCSourceDirectory:=AValue;
ClearSourceCache;
end;
procedure TFPCUnitToSrcCache.SetTargetCPU(const AValue: string);
begin
if FTargetCPU=AValue then exit;
FTargetCPU:=AValue;
ClearConfigCache;
end;
procedure TFPCUnitToSrcCache.SetTargetOS(const AValue: string);
begin
if FTargetOS=AValue then exit;
FTargetOS:=AValue;
ClearConfigCache;
end;
procedure TFPCUnitToSrcCache.ClearConfigCache;
begin
FConfigCache:=nil;
FreeAndNil(fFPCSourceRules);
FreeAndNil(fUnitToSourceTree);
end;
procedure TFPCUnitToSrcCache.ClearSourceCache;
begin
fSourceCache:=nil;
FreeAndNil(fUnitToSourceTree);
FreeAndNil(fSrcDuplicates);
end;
constructor TFPCUnitToSrcCache.Create(Owner: TFPCDefinesCache);
begin
fOldUnitToSourceTree:=TStringToStringTree.Create(true);
FCaches:=Owner;
end;
destructor TFPCUnitToSrcCache.Destroy;
begin
inherited Destroy;
FreeAndNil(fOldUnitToSourceTree);
end;
procedure TFPCUnitToSrcCache.Clear;
begin
end;
function TFPCUnitToSrcCache.GetConfigCache(AutoUpdate: boolean
): TFPCTargetConfigCache; ): TFPCTargetConfigCache;
begin begin
if CompilerFilename='' then if CompilerFilename='' then
raise Exception.Create('TFPCDefinesCache.GetConfigCache missing CompilerFilename'); raise Exception.Create('TFPCUnitToSrcCache.GetConfigCache missing CompilerFilename');
if TestFilename='' then if Caches.TestFilename='' then
raise Exception.Create('TFPCDefinesCache.GetConfigCache missing TestFilename'); raise Exception.Create('TFPCUnitToSrcCache.GetConfigCache missing TestFilename');
if FConfigCache=nil then if FConfigCache=nil then
FConfigCache:=ConfigCaches.Find(CompilerFilename,TargetOS,TargetCPU,true); FConfigCache:=Caches.ConfigCaches.Find(CompilerFilename,TargetOS,TargetCPU,true);
if AutoUpdate and FConfigCache.NeedsUpdate then if AutoUpdate and FConfigCache.NeedsUpdate then
FConfigCache.Update(TestFilename); FConfigCache.Update(Caches.TestFilename);
Result:=FConfigCache; Result:=FConfigCache;
end; end;
function TFPCDefinesCache.GetSourceCache(AutoUpdate: boolean): TFPCSourceCache; function TFPCUnitToSrcCache.GetSourceCache(AutoUpdate: boolean
): TFPCSourceCache;
begin begin
if FPCSourceDirectory='' then
raise Exception.Create('TFPCUnitToSrcCache.GetSourceCache missing FPCSourceDirectory');
if fSourceCache=nil then if fSourceCache=nil then
fSourceCache:=SourceCaches.Find(FPCSourceDirectory,true); fSourceCache:=Caches.SourceCaches.Find(FPCSourceDirectory,true);
if AutoUpdate and (fSourceCache.Files.Count=0) then if AutoUpdate and (fSourceCache.Files.Count=0) then
fSourceCache.Update(nil); fSourceCache.Update(nil);
Result:=fSourceCache; Result:=fSourceCache;
end; end;
function TFPCDefinesCache.GetSourceRules(AutoUpdate: boolean): TFPCSourceRules; function TFPCUnitToSrcCache.GetSourceRules(AutoUpdate: boolean
): TFPCSourceRules;
var var
Cfg: TFPCTargetConfigCache; Cfg: TFPCTargetConfigCache;
begin begin
@ -7563,14 +7618,16 @@ begin
Result:=fFPCSourceRules; Result:=fFPCSourceRules;
end; end;
function TFPCDefinesCache.GetUnitToSourceTree(AutoUpdate: boolean function TFPCUnitToSrcCache.GetUnitToSourceTree(AutoUpdate: boolean
): TStringToStringTree; ): TStringToStringTree;
var var
Src: TFPCSourceCache; Src: TFPCSourceCache;
SrcRules: TFPCSourceRules; SrcRules: TFPCSourceRules;
begin begin
Src:=GetSourceCache(AutoUpdate);
// ToDo: check
if fUnitToSourceTree=nil then begin if fUnitToSourceTree=nil then begin
Src:=GetSourceCache(AutoUpdate);
fSrcDuplicates:=TStringToStringTree.Create(true); fSrcDuplicates:=TStringToStringTree.Create(true);
SrcRules:=GetSourceRules(AutoUpdate); SrcRules:=GetSourceRules(AutoUpdate);
fUnitToSourceTree:=GatherUnitsInFPCSources(Src.Files,TargetOS,TargetCPU, fUnitToSourceTree:=GatherUnitsInFPCSources(Src.Files,TargetOS,TargetCPU,
@ -7578,17 +7635,17 @@ begin
if fUnitToSourceTree=nil then if fUnitToSourceTree=nil then
fUnitToSourceTree:=TStringToStringTree.Create(true); fUnitToSourceTree:=TStringToStringTree.Create(true);
if not fOldUnitToSourceTree.Equals(fUnitToSourceTree) then begin if not fOldUnitToSourceTree.Equals(fUnitToSourceTree) then begin
if FUnitToSourceTreeChangeStamp<High(FUnitToSourceTreeChangeStamp) then if FChangeStamp<High(FChangeStamp) then
inc(FUnitToSourceTreeChangeStamp) inc(FChangeStamp)
else else
FUnitToSourceTreeChangeStamp:=Low(FUnitToSourceTreeChangeStamp); FChangeStamp:=Low(FChangeStamp);
fOldUnitToSourceTree.Assign(fUnitToSourceTree); fOldUnitToSourceTree.Assign(fUnitToSourceTree);
end; end;
end; end;
Result:=fUnitToSourceTree; Result:=fUnitToSourceTree;
end; end;
function TFPCDefinesCache.GetSourceDuplicates(AutoUpdate: boolean function TFPCUnitToSrcCache.GetSourceDuplicates(AutoUpdate: boolean
): TStringToStringTree; ): TStringToStringTree;
begin begin
GetUnitToSourceTree(AutoUpdate); GetUnitToSourceTree(AutoUpdate);