mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 21:59:14 +02:00
ide: TBuildManager.CheckUnitPathForAmbiguousPascalFiles: using cache
This commit is contained in:
parent
aeb8dbd099
commit
7efae97858
@ -44,6 +44,7 @@ uses
|
|||||||
// LazUtils
|
// LazUtils
|
||||||
FPCAdds, LConvEncoding, FileUtil, LazFileUtils, LazFileCache, LazUTF8,
|
FPCAdds, LConvEncoding, FileUtil, LazFileUtils, LazFileCache, LazUTF8,
|
||||||
Laz2_XMLCfg, LazUtilities, LazStringUtils, LazMethodList, LazVersion,
|
Laz2_XMLCfg, LazUtilities, LazStringUtils, LazMethodList, LazVersion,
|
||||||
|
AvgLvlTree,
|
||||||
// BuildIntf
|
// BuildIntf
|
||||||
BaseIDEIntf, IDEOptionsIntf, ProjectIntf, MacroIntf, PublishModuleIntf,
|
BaseIDEIntf, IDEOptionsIntf, ProjectIntf, MacroIntf, PublishModuleIntf,
|
||||||
IDEExternToolIntf, CompOptsIntf, MacroDefIntf,
|
IDEExternToolIntf, CompOptsIntf, MacroDefIntf,
|
||||||
@ -1782,93 +1783,73 @@ function TBuildManager.CheckUnitPathForAmbiguousPascalFiles(const BaseDir,
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
EndPos: Integer;
|
|
||||||
StartPos: Integer;
|
|
||||||
CurDir: String;
|
|
||||||
FileInfo: TSearchRec;
|
|
||||||
SourceUnitTree, CompiledUnitTree: TAVLTree;
|
SourceUnitTree, CompiledUnitTree: TAVLTree;
|
||||||
ANode: TAVLTreeNode;
|
ANode: TAVLTreeNode;
|
||||||
CurUnitName: String;
|
CurUnitName: String;
|
||||||
CurFilename: String;
|
CurFilename: String;
|
||||||
AnUnitFile: PUnitFile;
|
AnUnitFile: PUnitFile;
|
||||||
CurUnitTree: TAVLTree;
|
CurUnitTree: TAVLTree;
|
||||||
FileInfoNeedClose: Boolean;
|
|
||||||
UnitPath: String;
|
UnitPath: String;
|
||||||
IgnoreAll: Boolean;
|
IgnoreAll: Boolean;
|
||||||
|
Files: TFilenameToStringTree;
|
||||||
|
Item: PStringToStringItem;
|
||||||
begin
|
begin
|
||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
UnitPath:=TrimSearchPath(TheUnitPath,BaseDir,true);
|
UnitPath:=TrimSearchPath(TheUnitPath,BaseDir,true);
|
||||||
|
|
||||||
SourceUnitTree:=TAVLTree.Create(TListSortCompare(@CompareUnitFiles));
|
SourceUnitTree:=TAVLTree.Create(TListSortCompare(@CompareUnitFiles));
|
||||||
CompiledUnitTree:=TAVLTree.Create(TListSortCompare(@CompareUnitFiles));
|
CompiledUnitTree:=TAVLTree.Create(TListSortCompare(@CompareUnitFiles));
|
||||||
FileInfoNeedClose:=false;
|
Files:=TFilenameToStringTree.Create(true);
|
||||||
try
|
try
|
||||||
// collect all units (.pas, .pp, compiled units)
|
// collect all units (.pas, .pp, compiled units)
|
||||||
EndPos:=1;
|
CollectFilesInSearchPath(UnitPath,Files,'Unit');
|
||||||
while EndPos<=length(UnitPath) do begin
|
IgnoreAll:=false;
|
||||||
StartPos:=EndPos;
|
for Item in Files do
|
||||||
while (StartPos<=length(UnitPath)) and (UnitPath[StartPos]=';') do
|
begin
|
||||||
inc(StartPos);
|
CurFilename:=Item^.Name;
|
||||||
EndPos:=StartPos;
|
if FilenameHasPascalExt(CurFilename) then
|
||||||
while (EndPos<=length(UnitPath)) and (UnitPath[EndPos]<>';') do
|
CurUnitTree:=SourceUnitTree
|
||||||
inc(EndPos);
|
else if FilenameExtIs(CurFilename,CompiledExt,true) then
|
||||||
if EndPos>StartPos then begin
|
CurUnitTree:=CompiledUnitTree
|
||||||
CurDir:=AppendPathDelim(TrimFilename(copy(UnitPath,StartPos,EndPos-StartPos)));
|
else
|
||||||
FileInfoNeedClose:=true;
|
continue;
|
||||||
if FindFirstUTF8(CurDir+GetAllFilesMask,faAnyFile,FileInfo)=0 then begin
|
CurUnitName:=ExtractFilenameOnly(CurFilename);
|
||||||
IgnoreAll:=false;
|
if not LazIsValidIdent(CurUnitName) then
|
||||||
repeat
|
continue;
|
||||||
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
|
//DebugLn(['TBuildManager.CheckUnitPathForAmbiguousPascalFiles ',CurUnitName,' ',CurFilename]);
|
||||||
or ((FileInfo.Attr and faDirectory)<>0) then continue;
|
// check if unit already found
|
||||||
if FilenameHasPascalExt(FileInfo.Name) then
|
ANode:=CurUnitTree.FindKey(PChar(CurUnitName),
|
||||||
CurUnitTree:=SourceUnitTree
|
TListSortCompare(@CompareUnitNameAndUnitFile));
|
||||||
else if FilenameExtIs(FileInfo.Name,CompiledExt,true) then
|
if (ANode<>nil) and (not IgnoreAll) then begin
|
||||||
CurUnitTree:=CompiledUnitTree
|
if ConsoleVerbosity>=0 then
|
||||||
else
|
DebugLn(['Note: (lazarus) [TBuildManager.CheckUnitPathForAmbiguousPascalFiles] CurUnitName="',CurUnitName,'" CurFilename="',CurFilename,'" OtherUnitName="',PUnitFile(ANode.Data)^.FileUnitName,'" OtherFilename="',PUnitFile(ANode.Data)^.Filename,'"']);
|
||||||
continue;
|
// pascal unit exists twice
|
||||||
CurUnitName:=ExtractFilenameOnly(FileInfo.Name);
|
Result:=IDEQuestionDialog(lisAmbiguousUnitFound,
|
||||||
if not LazIsValidIdent(CurUnitName) then
|
Format(lisTheUnitExistsTwiceInTheUnitPathOfThe,[CurUnitName,ContextDescription])
|
||||||
continue;
|
+LineEnding
|
||||||
CurFilename:=CurDir+FileInfo.Name;
|
+LineEnding
|
||||||
//DebugLn(['TBuildManager.CheckUnitPathForAmbiguousPascalFiles ',CurUnitName,' ',CurFilename]);
|
+'1. "'+PUnitFile(ANode.Data)^.Filename+'"'+LineEnding
|
||||||
// check if unit already found
|
+'2. "'+CurFilename+'"'+LineEnding
|
||||||
ANode:=CurUnitTree.FindKey(PChar(CurUnitName),
|
+LineEnding
|
||||||
TListSortCompare(@CompareUnitNameAndUnitFile));
|
+lisHintCheckIfTwoPackagesContainAUnitWithTheSameName,
|
||||||
if (ANode<>nil) and (not IgnoreAll) then begin
|
mtWarning, [mrIgnore,
|
||||||
if ConsoleVerbosity>=0 then
|
mrYesToAll, lisIgnoreAll,
|
||||||
DebugLn(['Note: (lazarus) [TBuildManager.CheckUnitPathForAmbiguousPascalFiles] CurUnitName="',CurUnitName,'" CurFilename="',CurFilename,'" OtherUnitName="',PUnitFile(ANode.Data)^.FileUnitName,'" OtherFilename="',PUnitFile(ANode.Data)^.Filename,'"']);
|
mrAbort]);
|
||||||
// pascal unit exists twice
|
case Result of
|
||||||
Result:=IDEQuestionDialog(lisAmbiguousUnitFound,
|
mrIgnore: ;
|
||||||
Format(lisTheUnitExistsTwiceInTheUnitPathOfThe,[CurUnitName,ContextDescription])
|
mrYesToAll: IgnoreAll:=true;
|
||||||
+LineEnding
|
else exit;
|
||||||
+LineEnding
|
|
||||||
+'1. "'+PUnitFile(ANode.Data)^.Filename+'"'+LineEnding
|
|
||||||
+'2. "'+CurFilename+'"'+LineEnding
|
|
||||||
+LineEnding
|
|
||||||
+lisHintCheckIfTwoPackagesContainAUnitWithTheSameName,
|
|
||||||
mtWarning, [mrIgnore,
|
|
||||||
mrYesToAll, lisIgnoreAll,
|
|
||||||
mrAbort]);
|
|
||||||
case Result of
|
|
||||||
mrIgnore: ;
|
|
||||||
mrYesToAll: IgnoreAll:=true;
|
|
||||||
else exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
// add unit to tree
|
|
||||||
New(AnUnitFile);
|
|
||||||
AnUnitFile^.FileUnitName:=CurUnitName;
|
|
||||||
AnUnitFile^.Filename:=CurFilename;
|
|
||||||
CurUnitTree.Add(AnUnitFile);
|
|
||||||
until FindNextUTF8(FileInfo)<>0;
|
|
||||||
end;
|
end;
|
||||||
FindCloseUTF8(FileInfo);
|
|
||||||
FileInfoNeedClose:=false;
|
|
||||||
end;
|
end;
|
||||||
|
// add unit to tree
|
||||||
|
New(AnUnitFile);
|
||||||
|
AnUnitFile^.FileUnitName:=CurUnitName;
|
||||||
|
AnUnitFile^.Filename:=CurFilename;
|
||||||
|
CurUnitTree.Add(AnUnitFile);
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
// clean up
|
// clean up
|
||||||
if FileInfoNeedClose then FindCloseUTF8(FileInfo);
|
Files.Free;
|
||||||
FreeUnitTree(SourceUnitTree);
|
FreeUnitTree(SourceUnitTree);
|
||||||
FreeUnitTree(CompiledUnitTree);
|
FreeUnitTree(CompiledUnitTree);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user