mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-03 00:17:18 +01:00
IDE: use GetPhysicalFilename instead of readalllinks
git-svn-id: trunk@45246 -
This commit is contained in:
parent
b0e7e2b994
commit
978ec20681
@ -37,7 +37,7 @@ uses
|
||||
Classes, SysUtils, AVL_Tree,
|
||||
// LCL
|
||||
LConvEncoding, InterfaceBase, LCLProc, Dialogs, FileUtil, Laz2_XMLCfg,
|
||||
LazUTF8, Forms, Controls,
|
||||
LazUTF8, LazFileUtils, Forms, Controls,
|
||||
// codetools
|
||||
ExprEval, BasicCodeTools, CodeToolManager, DefineTemplates, CodeCache,
|
||||
FileProcs, CodeToolsCfgScript, CodeToolsStructs,
|
||||
@ -813,7 +813,7 @@ procedure TBuildManager.RescanCompilerDefines(ResetBuildTarget,
|
||||
mtError,[mbOk]);
|
||||
exit(false);
|
||||
end;
|
||||
Filename:=ReadAllLinks(Cfg.RealCompiler,false);
|
||||
Filename:=GetPhysicalFilename(Cfg.RealCompiler,pfeEmpty);
|
||||
if (Filename='') then begin
|
||||
IDEMessageDialog('Error','Compiler executable is missing: '+Cfg.RealCompiler,
|
||||
mtError,[mbOk]);
|
||||
|
||||
@ -31,8 +31,8 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LCLProc, AvgLvlTree, Laz2_XMLCfg, LazUTF8,
|
||||
lazutf8classes, StdCtrls, ExtCtrls, SourceLog, FileProcs, CodeToolManager,
|
||||
CodeToolsConfig, CodeCache, LazConf;
|
||||
lazutf8classes, LazFileUtils, StdCtrls, ExtCtrls, SourceLog, FileProcs,
|
||||
CodeToolManager, CodeToolsConfig, CodeCache, LazConf;
|
||||
|
||||
type
|
||||
// comments
|
||||
@ -433,7 +433,7 @@ begin
|
||||
if List=nil then exit;
|
||||
for i:=List.Count-1 downto 0 do begin
|
||||
OldFilename:=List[i];
|
||||
NewFilename:=ReadAllLinks(OldFilename,false);
|
||||
NewFilename:=GetPhysicalFilename(OldFilename,pfeEmpty);
|
||||
//DebugLn(['ResolveLinksInFileList OldFilename=',OldFilename,' NewFilename=',NewFilename]);
|
||||
if NewFilename='' then begin
|
||||
if RemoveDanglingLinks then
|
||||
|
||||
@ -114,49 +114,6 @@ type
|
||||
end;
|
||||
|
||||
|
||||
{ TFPCConfigCacheItem }
|
||||
|
||||
TFPCConfigCacheItem = class
|
||||
public
|
||||
Options: string;
|
||||
SearchPath: string;
|
||||
FPCSrcDir: string;
|
||||
UnitLinks: string;
|
||||
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string);
|
||||
procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string);
|
||||
end;
|
||||
|
||||
|
||||
{ TFPCConfigCache }
|
||||
|
||||
TFPCConfigCache = class
|
||||
private
|
||||
FCompilerAge: longint;
|
||||
FCompilerPath: string;
|
||||
FItems: TList; // list of TFPCConfigCacheItem
|
||||
function GetCount: integer;
|
||||
function GetItems(Index: integer): TFPCConfigCacheItem;
|
||||
procedure SetCompilerPath(const AValue: string);
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure Clear;
|
||||
function FindItem(const Options: string): integer;
|
||||
procedure SetItem(const Options, SearchPath, FPCSrcDir, UnitLinks: string);
|
||||
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string);
|
||||
procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string);
|
||||
function Valid(CheckCompiler: boolean): boolean;
|
||||
function UnitLinksNeedUpdate(const Options, SearchPath,
|
||||
FPCSrcDir: string): boolean;
|
||||
function GetUnitLinks(const Options: string): string;
|
||||
public
|
||||
property CompilerPath: string read FCompilerPath write SetCompilerPath;
|
||||
property CompilerAge: longint read FCompilerAge;
|
||||
property Count: integer read GetCount;
|
||||
property Items[Index: integer]: TFPCConfigCacheItem read GetItems;
|
||||
end;
|
||||
|
||||
|
||||
{ TInputHistories }
|
||||
|
||||
TLazFindInFileSearchOption = (
|
||||
@ -221,9 +178,6 @@ type
|
||||
FFindInFilesMaskHistory: TStringList;
|
||||
FMaxFindHistory: Integer;
|
||||
|
||||
// FPC config cache
|
||||
FFPCConfigCache: TFPCConfigCache;
|
||||
|
||||
// various history lists
|
||||
FHistoryLists: THistoryLists;
|
||||
|
||||
@ -247,13 +201,6 @@ type
|
||||
function AddToFindInFilesPathHistory(const APathStr: String): boolean;
|
||||
function AddToFindInFilesMaskHistory(const AMaskStr: String): boolean;
|
||||
|
||||
// fpc units
|
||||
function LastFPCUnitLinksValid: boolean;
|
||||
function LastFPCUnitLinksNeedsUpdate(const Options, SearchPath,
|
||||
FPCSrcDir: string): boolean;
|
||||
procedure SetLastFPCUnitLinks(const FPCPath, FPCOptions,
|
||||
SearchPath, FPCSrcDir, UnitLinks: string);
|
||||
|
||||
// filedialog
|
||||
procedure ApplyFileDialogSettings(DestDialog: TFileDialog);
|
||||
procedure StoreFileDialogSettings(SourceDialog: TFileDialog);
|
||||
@ -279,9 +226,6 @@ type
|
||||
property FindAutoComplete: boolean read FFindAutoComplete
|
||||
write FFindAutoComplete;
|
||||
|
||||
// FPC config cache
|
||||
property FPCConfigCache: TFPCConfigCache read FFPCConfigCache;
|
||||
|
||||
// filedialogs
|
||||
property FileDialogSettings: TFileDialogSettings
|
||||
read FFileDialogSettings write FFileDialogSettings;
|
||||
@ -425,8 +369,6 @@ begin
|
||||
// various history lists
|
||||
FHistoryLists:=THistoryLists.Create;
|
||||
|
||||
FFPCConfigCache:=TFPCConfigCache.Create;
|
||||
|
||||
fFileEncodings:=TStringToStringTree.Create({$IFDEF CaseInsensitiveFilenames}false{$ELSE}true{$ENDIF});
|
||||
|
||||
FIgnores:=TIHIgnoreIDEQuestionList.Create;
|
||||
@ -445,7 +387,6 @@ begin
|
||||
FreeAndNil(FReplaceHistory);
|
||||
FreeAndNil(FFindInFilesPathHistory);
|
||||
FreeAndNil(FFindInFilesMaskHistory);
|
||||
FreeAndNil(FFPCConfigCache);
|
||||
FreeAndNil(fFileEncodings);
|
||||
inherited Destroy;
|
||||
end;
|
||||
@ -468,7 +409,6 @@ begin
|
||||
FDiffText2OnlySelection:=false;
|
||||
FNewProjectType:='';
|
||||
FNewFileType:='';
|
||||
FFPCConfigCache.Clear;
|
||||
FLastConvertDelphiProject:='';
|
||||
FLastConvertDelphiUnit:='';
|
||||
FCleanOutputFileMask:=DefaultProjectCleanOutputFileMask;
|
||||
@ -512,8 +452,6 @@ begin
|
||||
Include(FFindOptions,FindOption);
|
||||
end;
|
||||
|
||||
// fpc config cache
|
||||
FFPCConfigCache.LoadFromXMLConfig(XMLConfig,'FPCConfigCache/');
|
||||
// file dialog
|
||||
with FFileDialogSettings do begin
|
||||
Width:=XMLConfig.GetValue(Path+'FileDialog/Width',0);
|
||||
@ -588,8 +526,6 @@ begin
|
||||
FindOption in LazFindSearchOptionsDefault);
|
||||
end;
|
||||
|
||||
// fpc config cache
|
||||
FFPCConfigCache.SaveToXMLConfig(XMLConfig,'FPCConfigCache/');
|
||||
// file dialog
|
||||
with FFileDialogSettings do begin
|
||||
XMLConfig.SetDeleteValue(Path+'FileDialog/Width',Width,0);
|
||||
@ -700,24 +636,6 @@ begin
|
||||
Result:= AddToRecentList(AMaskStr,FFindInFilesMaskHistory,FMaxFindHistory,rltFile);
|
||||
end;
|
||||
|
||||
function TInputHistories.LastFPCUnitLinksValid: boolean;
|
||||
begin
|
||||
Result:=FFPCConfigCache.Valid(false);
|
||||
end;
|
||||
|
||||
function TInputHistories.LastFPCUnitLinksNeedsUpdate(
|
||||
const Options, SearchPath, FPCSrcDir: string): boolean;
|
||||
begin
|
||||
Result:=FFPCConfigCache.UnitLinksNeedUpdate(Options,SearchPath,FPCSrcDir);
|
||||
end;
|
||||
|
||||
procedure TInputHistories.SetLastFPCUnitLinks(const FPCPath, FPCOptions,
|
||||
SearchPath, FPCSrcDir, UnitLinks: string);
|
||||
begin
|
||||
FFPCConfigCache.CompilerPath:=FPCPath;
|
||||
FFPCConfigCache.SetItem(FPCOptions,SearchPath,FPCSrcDir,UnitLinks);
|
||||
end;
|
||||
|
||||
procedure TInputHistories.ApplyFileDialogSettings(DestDialog: TFileDialog);
|
||||
begin
|
||||
DestDialog.InitialDir:=FFileDialogSettings.InitialDir;
|
||||
@ -932,176 +850,6 @@ begin
|
||||
GetList(ListName,true,ListType).Push(Entry);
|
||||
end;
|
||||
|
||||
{ TFPCConfigCache }
|
||||
|
||||
function TFPCConfigCache.GetCount: integer;
|
||||
begin
|
||||
Result:=FItems.Count;
|
||||
end;
|
||||
|
||||
function TFPCConfigCache.GetItems(Index: integer): TFPCConfigCacheItem;
|
||||
begin
|
||||
Result:=TFPCConfigCacheItem(FItems[Index]);
|
||||
end;
|
||||
|
||||
procedure TFPCConfigCache.SetCompilerPath(const AValue: string);
|
||||
var
|
||||
ResolvedFilename: String;
|
||||
begin
|
||||
if FCompilerPath=AValue then exit;
|
||||
Clear;
|
||||
FCompilerPath:=AValue;
|
||||
ResolvedFilename:=ReadAllLinks(FCompilerPath,false);
|
||||
if FileExistsCached(ResolvedFilename) then
|
||||
FCompilerAge:=FileAgeCached(ResolvedFilename)
|
||||
else
|
||||
FCompilerAge:=-1;
|
||||
end;
|
||||
|
||||
constructor TFPCConfigCache.Create;
|
||||
begin
|
||||
FItems:=TList.Create;
|
||||
FCompilerAge:=-1;
|
||||
end;
|
||||
|
||||
destructor TFPCConfigCache.Destroy;
|
||||
begin
|
||||
Clear;
|
||||
FItems.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TFPCConfigCache.Clear;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
FCompilerPath:='';
|
||||
FCompilerAge:=-1;
|
||||
for i:=0 to FItems.Count-1 do Items[i].Free;
|
||||
FItems.Clear;
|
||||
end;
|
||||
|
||||
function TFPCConfigCache.FindItem(const Options: string): integer;
|
||||
begin
|
||||
Result:=FItems.Count-1;
|
||||
while (Result>=0) and (Options<>Items[Result].Options) do dec(Result);
|
||||
end;
|
||||
|
||||
procedure TFPCConfigCache.SetItem(const Options, SearchPath, FPCSrcDir, UnitLinks: string);
|
||||
var
|
||||
i: Integer;
|
||||
CurItem: TFPCConfigCacheItem;
|
||||
begin
|
||||
i:=FindItem(Options);
|
||||
if i<0 then begin
|
||||
CurItem:=TFPCConfigCacheItem.Create;
|
||||
FItems.Add(CurItem);
|
||||
end else
|
||||
CurItem:=Items[i];
|
||||
CurItem.Options:=Options;
|
||||
CurItem.SearchPath:=SearchPath;
|
||||
CurItem.FPCSrcDir:=FPCSrcDir;
|
||||
CurItem.UnitLinks:=UnitLinks;
|
||||
end;
|
||||
|
||||
procedure TFPCConfigCache.LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string);
|
||||
var
|
||||
NewCount: Integer;
|
||||
i: Integer;
|
||||
NewItem: TFPCConfigCacheItem;
|
||||
OldCompilerAge: Integer;
|
||||
NewCompilerPath: String;
|
||||
begin
|
||||
NewCompilerPath:=XMLConfig.GetValue(Path+'CompilerPath','');
|
||||
OldCompilerAge:=FCompilerAge;
|
||||
FCompilerAge:=XMLConfig.GetValue(Path+'CompilerDate',-1);
|
||||
if FCompilerAge<>OldCompilerAge then Clear;
|
||||
CompilerPath:=NewCompilerPath;
|
||||
NewCount:=XMLConfig.GetValue(Path+'Items/Count',0);
|
||||
for i:=1 to NewCount do begin
|
||||
NewItem:=TFPCConfigCacheItem.Create;
|
||||
NewItem.LoadFromXMLConfig(XMLConfig,Path+'Item'+IntToStr(i)+'/');
|
||||
FItems.Add(NewItem);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFPCConfigCache.SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
XMLConfig.SetDeleteValue(Path+'CompilerPath',FCompilerPath,'');
|
||||
XMLConfig.SetDeleteValue(Path+'CompilerDate',FCompilerAge,-1);
|
||||
XMLConfig.SetDeleteValue(Path+'Items/Count',Count,0);
|
||||
for i:=1 to Count do begin
|
||||
Items[i-1].SaveToXMLConfig(XMLConfig,Path+'Item'+IntToStr(i)+'/');
|
||||
end;
|
||||
end;
|
||||
|
||||
function TFPCConfigCache.Valid(CheckCompiler: boolean): boolean;
|
||||
var
|
||||
ResolvedFilename: String;
|
||||
begin
|
||||
Result:=(FCompilerPath<>'') and (FCompilerAge>=0);
|
||||
if Result and CheckCompiler then begin
|
||||
ResolvedFilename:=ReadAllLinks(FCompilerPath,false);
|
||||
if FileExistsUTF8(ResolvedFilename)
|
||||
and (FileAgeCached(ResolvedFilename)=FCompilerAge) then
|
||||
exit;
|
||||
FCompilerAge:=-1;
|
||||
Result:=false;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TFPCConfigCache.UnitLinksNeedUpdate(const Options, SearchPath,
|
||||
FPCSrcDir: string): boolean;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Result:=true;
|
||||
if not Valid(false) then exit;
|
||||
// check if option was already cached
|
||||
i:=FindItem(Options);
|
||||
if i<0 then exit;
|
||||
// check if search path changed
|
||||
if Items[i].SearchPath<>SearchPath then exit;
|
||||
// check if FPCSrcDir changed
|
||||
if Items[i].FPCSrcDir<>FPCSrcDir then exit;
|
||||
// check if compiler changed
|
||||
if not Valid(true) then exit;
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
function TFPCConfigCache.GetUnitLinks(const Options: string): string;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
i:=FindItem(Options);
|
||||
if i<0 then
|
||||
Result:=''
|
||||
else
|
||||
Result:=Items[i].UnitLinks;
|
||||
end;
|
||||
|
||||
{ TFPCConfigCacheItem }
|
||||
|
||||
procedure TFPCConfigCacheItem.LoadFromXMLConfig(XMLConfig: TXMLConfig;
|
||||
const Path: string);
|
||||
begin
|
||||
Options:=XMLConfig.GetValue(Path+'Options/Value','');
|
||||
SearchPath:=LineBreaksToDelimiter(XMLConfig.GetValue(Path+'SearchPath/Value',''),';');
|
||||
FPCSrcDir:=XMLConfig.GetValue(Path+'FPCSrcDir/Value','');
|
||||
UnitLinks:=XMLConfig.GetValue(Path+'UnitLinks/Value','');
|
||||
end;
|
||||
|
||||
procedure TFPCConfigCacheItem.SaveToXMLConfig(XMLConfig: TXMLConfig;
|
||||
const Path: string);
|
||||
begin
|
||||
XMLConfig.SetDeleteValue(Path+'Options/Value',Options,'');
|
||||
XMLConfig.SetDeleteValue(Path+'SearchPath/Value',SearchPath,'');
|
||||
XMLConfig.SetDeleteValue(Path+'FPCSrcDir/Value',FPCSrcDir,'');
|
||||
XMLConfig.SetDeleteValue(Path+'UnitLinks/Value',UnitLinks,'');
|
||||
end;
|
||||
|
||||
{ TIHIgnoreIDEQuestionList }
|
||||
|
||||
function TIHIgnoreIDEQuestionList.FindNode(const Identifier: string): TAvgLvlTreeNode;
|
||||
|
||||
@ -92,7 +92,7 @@ uses
|
||||
BaseUnix,
|
||||
{$ENDIF}
|
||||
Classes, SysUtils, Process, UTF8Process,
|
||||
LCLProc, FileProcs, FileUtil, Forms, Controls, Dialogs,
|
||||
LCLProc, FileProcs, FileUtil, LazFileUtils, Forms, Controls, Dialogs,
|
||||
IDECmdLine, LazConf, Splash, BaseIDEIntf;
|
||||
|
||||
type
|
||||
@ -276,10 +276,10 @@ begin
|
||||
try
|
||||
StartPath:=ExpandFileNameUTF8(ParamStrUTF8(0));
|
||||
if FileIsSymlink(StartPath) then
|
||||
StartPath:=ReadAllLinks(StartPath,true);
|
||||
StartPath:=GetPhysicalFilename(StartPath,pfeException);
|
||||
DefaultDir:=ExtractFilePath(StartPath);
|
||||
if DirectoryExistsUTF8(DefaultDir) then
|
||||
DefaultDir:=ReadAllLinks(DefaultDir,true);
|
||||
DefaultDir:=GetPhysicalFilename(DefaultDir,pfeException);
|
||||
except
|
||||
on E: Exception do begin
|
||||
MessageDlg ('Error',E.Message,mtError,[mbCancel],0);
|
||||
|
||||
@ -5675,7 +5675,7 @@ function TProject.UnitInfoWithFilename(const AFilename: string;
|
||||
Result:=TheFilename;
|
||||
if (pfsfResolveFileLinks in SearchFlags)
|
||||
and FilenameIsAbsolute(Result) then
|
||||
Result:=ReadAllLinks(Result,false);
|
||||
Result:=GetPhysicalFilename(Result,pfeOriginal);
|
||||
end;
|
||||
|
||||
function FindFileInList(ListType: TUnitInfoList): TUnitInfo;
|
||||
@ -5851,7 +5851,7 @@ function TProject.IndexOfFilename(const AFilename: string;
|
||||
Result:=TheFilename;
|
||||
if (pfsfResolveFileLinks in SearchFlags)
|
||||
and (FilenameIsAbsolute(Result)) then
|
||||
Result:=ReadAllLinks(Result,false);
|
||||
Result:=GetPhysicalFilename(Result,pfeOriginal);
|
||||
end;
|
||||
|
||||
var
|
||||
|
||||
@ -176,7 +176,7 @@ type
|
||||
procedure UpdateSourceDirectoryReference;
|
||||
function GetFullFilename: string; override;
|
||||
function GetShortFilename(UseUp: boolean): string; override;
|
||||
function GetResolvedFilename: string; // GetFullFilename + ReadAllLinks
|
||||
function GetResolvedFilename: string; // GetFullFilename + resolve symlinks
|
||||
public
|
||||
property AddToUsesPkgSection: boolean
|
||||
read GetAddToUsesPkgSection write SetAddToUsesPkgSection;
|
||||
@ -658,7 +658,7 @@ type
|
||||
function HasDirectory: boolean;
|
||||
function HasStaticDirectory: boolean;
|
||||
function GetFullFilename(ResolveMacros: boolean): string;
|
||||
function GetResolvedFilename(ResolveMacros: boolean): string; // GetFullFilename + ReadAllLinks
|
||||
function GetResolvedFilename(ResolveMacros: boolean): string; // GetFullFilename + resolve symlinks
|
||||
function GetSourceDirs(WithPkgDir, WithoutOutputDir: boolean): string;
|
||||
procedure GetInheritedCompilerOptions(var OptionsList: TFPList);
|
||||
function GetOutputDirectory(UseOverride: boolean = true): string; // this can change before building, when default dir is readonly
|
||||
@ -1759,8 +1759,7 @@ end;
|
||||
|
||||
function TPkgFile.GetResolvedFilename: string;
|
||||
begin
|
||||
Result:=ReadAllLinks(GetFullFilename,false);
|
||||
if Result='' then Result:=GetFullFilename;
|
||||
Result:=GetPhysicalFilename(GetFullFilename,pfeOriginal);
|
||||
end;
|
||||
|
||||
{ TPkgDependency }
|
||||
@ -3000,12 +2999,8 @@ begin
|
||||
end;
|
||||
|
||||
function TLazPackage.GetResolvedFilename(ResolveMacros: boolean): string;
|
||||
var
|
||||
s: String;
|
||||
begin
|
||||
Result:=GetFullFilename(ResolveMacros);
|
||||
s:=ReadAllLinks(Result,false);
|
||||
if s<>'' then Result:=s;
|
||||
Result:=GetPhysicalFilename(GetFullFilename(ResolveMacros),pfeOriginal);
|
||||
end;
|
||||
|
||||
function TLazPackage.GetSourceDirs(WithPkgDir, WithoutOutputDir: boolean): string;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user