ide: using cache and support star dirs

This commit is contained in:
mattias 2023-08-03 11:12:53 +02:00
parent b3e68a30e1
commit f9870ed298
6 changed files with 74 additions and 33 deletions

View File

@ -811,10 +811,10 @@ begin
PPUFilename:=PPUFiles[i];
AUnitName:=ExtractFileNameOnly(PPUFilename);
// search .pas/.pp/.p file
if SearchPascalUnitInPath(AUnitName,'',SrcPath,';',ctsfcAllCase)<>'' then
if SearchUnitInSearchPath(AUnitName,'',SrcPath,true)<>'' then
PPUFiles.Delete(i)
// check for main source
else if (Options.Owner is TLazProject) then begin
// check for main source
CurProject:=TLazProject(Options.Owner);
if (CurProject.MainFileID>=0) then begin
ProjFile:=CurProject.MainFile;

View File

@ -3209,7 +3209,7 @@ begin
if (aPhase in [etpspAfterReadLine,etpspAfterSync])
and (fIncludePathValidForWorkerDir=MsgWorkerDir) then begin
// include path is valid and in worker thread
// -> search file
// -> search file (todo: needs a thread safe function for star directories)
aFilename:=FileUtil.SearchFileInPath(aFilename,MsgWorkerDir,fIncludePath,';',
[FileUtil.sffSearchLoUpCase,sffFile]);
if aFilename<>'' then

View File

@ -115,13 +115,13 @@ begin
Browser:='';
// prefer open source ;)
if Find('xdg-open',Browser) then exit;
if Find('firefox',Browser) then exit;
if Find('mozilla',Browser) then exit;
if Find('galeon',Browser) then exit;
if Find('konqueror',Browser) then exit;
if Find('safari',Browser) then exit;
if Find('netscape',Browser) then exit;
if Find('opera',Browser) then exit;
if Find('iexplore.exe',Browser) then exit;
end;
{---------------------------------------------------------------------------

View File

@ -99,6 +99,8 @@ type
function SearchFileInSearchPath(const Filename, BasePath: string;
SearchPath: string; Flags: TSPSearchFileFlags = []): string; overload;
function SearchUnitInSearchPath(const AnUnitname, BasePath: string;
SearchPath: string; AnyCase: boolean): string; overload;
procedure CollectFilesInSearchPath(const SearchPath: string;
Files: TFilenameToStringTree; const Value: string = ''); overload;
@ -647,8 +649,6 @@ var
p: Integer;
CurPath, Base: String;
Cache: TCTDirectoryBaseCache;
StarCache: TCTStarDirectoryCache;
DirCache: TCTDirectoryCache;
FileCase: TCTSearchFileCase;
begin
if Filename='' then
@ -689,20 +689,40 @@ begin
Cache:=CodeToolBoss.DirectoryCachePool.GetBaseCache(CurPath);
if Cache=nil then continue;
if Cache is TCTStarDirectoryCache then
begin
StarCache:=TCTStarDirectoryCache(Cache);
Result:=StarCache.FindFile(Filename,FileCase);
if Result<>'' then
if Fits(StarCache.Directory+Result) then
exit;
end else if Cache is TCTDirectoryCache then begin
DirCache:=TCTDirectoryCache(Cache);
Result:=DirCache.FindFile(Filename,FileCase);
if Result<>'' then
if Fits(DirCache.Directory+Result) then
exit;
end;
Result:=Cache.FindFile(Filename,FileCase);
if Result<>'' then
if Fits(Cache.Directory+Result) then
exit;
until false;
Result:='';
end;
function SearchUnitInSearchPath(const AnUnitname, BasePath: string;
SearchPath: string; AnyCase: boolean): string;
var
Base, CurPath: String;
p: Integer;
Cache: TCTDirectoryBaseCache;
begin
Base:=AppendPathDelim(ExpandFileNameUTF8(BasePath));
if BasePath<>'' then
begin
// search in current directory
Result:=CodeToolBoss.DirectoryCachePool.FindUnitInDirectory(Base,AnUnitname,AnyCase);
if Result<>'' then exit;
end;
// search in search path
p:=1;
repeat
CurPath:=GetNextDirectoryInSearchPath(SearchPath,p);
if CurPath='' then break;
CurPath:=TrimAndExpandDirectory(CurPath,Base);
Cache:=CodeToolBoss.DirectoryCachePool.GetBaseCache(CurPath);
if Cache=nil then continue;
Result:=Cache.FindUnitSource(AnUnitname,AnyCase);
if Result<>'' then
exit(Cache.Directory+Result);
until false;
Result:='';
end;

View File

@ -5496,15 +5496,14 @@ var
function CheckFile(const ShortFilename: string): TModalResult;
var
AmbiguousFilename: String;
SearchFlags: TSearchFileInPathFlags;
SearchFlags: TSPSearchFileFlags;
begin
Result:=mrOk;
SearchFlags:=[];
if CompareFilenames(PkgDir,PkgOutputDir)=0 then
Include(SearchFlags,sffDontSearchInBasePath);
Include(SearchFlags,TSPSearchFileFlag.DontSearchInBasePath);
repeat
AmbiguousFilename:=SearchFileInPath(ShortFilename,PkgDir,SrcDirs,';',
SearchFlags);
AmbiguousFilename:=SearchFileInSearchPath(ShortFilename,PkgDir,SrcDirs,SearchFlags);
if (AmbiguousFilename='') then exit;
if not YesToAll then
Result:=IDEMessageDialog(lisAmbiguousUnitFound,

View File

@ -3819,11 +3819,39 @@ function TPkgManager.CheckUserSearchPaths(aCompilerOptions: TBaseCompilerOptions
var
aPackage: TLazPackage;
CurUnitPath: String;
CurIncPath: String;
CurSrcPath: String;
CurOutPath: String;
SrcDirToPkg: TFilenameToPointerTree;
function GetPkgOfSrcDirToPkg(Dir: string): TLazPackage;
var
MaskType: TSPMaskType;
Item: PStringToPointerTreeItem;
CurDir: String;
begin
MaskType:=GetSPMaskType(Dir);
if MaskType=TSPMaskType.None then
begin
Result:=TLazPackage(SrcDirToPkg[Dir]);
exit;
end;
Dir:=ChompPathDelim(ExtractFilePath(Dir));
for Item in SrcDirToPkg do
begin
CurDir:=Item^.Name;
case MaskType of
TSPMaskType.Star:
if CompareFilenames(ChompPathDelim(ExtractFilePath(CurDir)),Dir)=0 then
exit(TLazPackage(Item^.Value));
TSPMaskType.StarStar:
if (CompareFilenames(CurDir,Dir)=0)
or FileIsInPath(CurDir,Dir) then
exit(TLazPackage(Item^.Value));
end;
end;
Result:=nil;
end;
function CheckPathContainsDirOfOtherPkg(Option: TParsedCompilerOptString
): TModalResult;
var
@ -3836,11 +3864,6 @@ var
begin
Result:=mrOk;
case Option of
pcosIncludePath:
begin
aType:='include files search path';
aSearchPath:=CurIncPath;
end;
pcosUnitPath:
begin
aType:='other unit files search path (aka unit path)';
@ -3860,7 +3883,7 @@ var
if Dir='' then break;
Dir:=ChompPathDelim(Dir);
if not FilenameIsAbsolute(Dir) then continue;
OtherPackage:=TLazPackage(SrcDirToPkg[Dir]);
OtherPackage:=GetPkgOfSrcDirToPkg(Dir);
if (OtherPackage<>nil) and (OtherPackage<>aPackage) then begin
// search path contains source directory of another package
if Option=pcosIncludePath then;
@ -3951,7 +3974,6 @@ begin
if (aPackage<>nil) and (aPackage.AutoUpdate=pupManually) then exit;
CurUnitPath:=aCompilerOptions.ParsedOpts.GetParsedValue(pcosUnitPath);
CurIncPath:=aCompilerOptions.ParsedOpts.GetParsedValue(pcosIncludePath);
CurSrcPath:=aCompilerOptions.ParsedOpts.GetParsedValue(pcosSrcPath);
CurOutPath:=aCompilerOptions.ParsedOpts.GetParsedValue(pcosOutputDir);
//debugln(['TPkgManager.CheckUserSearchPaths CompOpts=',aCompilerOptions.GetOwnerName,' UnitPath="',CurUnitPath,'" IncPath="',CurIncPath,'" SrcPath="',CurSrcPath,'" OutPath="',CurOutPath,'"']);
@ -4264,7 +4286,7 @@ begin
for i:=0 to PkgList.Count-1 do begin
APackage:=TLazPackage(PkgList[i]);
IncPath:=APackage.CompilerOptions.GetIncludePath(false);
Result:=SearchFileInPath(Filename,APackage.Directory,IncPath,';',ctsfcDefault);
Result:=SearchFileInSearchPath(Filename,APackage.Directory,IncPath);
if Result<>'' then exit;
end;
finally