mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 13:09:20 +02:00
IDE: inspect checksum changed dlg: show hints
git-svn-id: trunk@28975 -
This commit is contained in:
parent
3643ab6d81
commit
d092bfc036
@ -45,9 +45,13 @@ uses
|
|||||||
// codetools
|
// codetools
|
||||||
CodeCache, CodeToolManager, FileProcs, DirectoryCacher, DefineTemplates,
|
CodeCache, CodeToolManager, FileProcs, DirectoryCacher, DefineTemplates,
|
||||||
// IDEIntf
|
// IDEIntf
|
||||||
LazIDEIntf, TextTools, IDEMsgIntf, PackageIntf,
|
LazIDEIntf, TextTools, IDEMsgIntf, PackageIntf, ProjectIntf,
|
||||||
|
// IDE
|
||||||
LazarusIDEStrConsts;
|
LazarusIDEStrConsts;
|
||||||
|
|
||||||
|
const
|
||||||
|
ICC_FPC = '#FPC unit search path';
|
||||||
|
ICC_Project = '#Project';
|
||||||
type
|
type
|
||||||
TInspectChksumChgDialog = class;
|
TInspectChksumChgDialog = class;
|
||||||
|
|
||||||
@ -66,7 +70,9 @@ type
|
|||||||
public
|
public
|
||||||
Filename: string;
|
Filename: string;
|
||||||
Age: integer;
|
Age: integer;
|
||||||
OwnerName: string;
|
OwnerNames: TStringList;
|
||||||
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
destructor Destroy; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TICCFiles }
|
{ TICCFiles }
|
||||||
@ -98,6 +104,11 @@ type
|
|||||||
FUnit1Files: TICCFiles;
|
FUnit1Files: TICCFiles;
|
||||||
FUnit2: string;
|
FUnit2: string;
|
||||||
FUnit2Files: TICCFiles;
|
FUnit2Files: TICCFiles;
|
||||||
|
procedure FindUnitOwnerNames(aFile: TICCFile);
|
||||||
|
procedure SearchDirectory(anUnitName: string; Dir: string;
|
||||||
|
IsFPCPath: boolean; Files: TICCFiles);
|
||||||
|
procedure SearchInFPCFiles(anUnitName, SearchPath: string; Files: TICCFiles);
|
||||||
|
procedure SearchInSearchPath(anUnitName, SearchPath: string; Files: TICCFiles);
|
||||||
function SearchUnit(anUnitName, SearchPath: string): TICCFiles;
|
function SearchUnit(anUnitName, SearchPath: string): TICCFiles;
|
||||||
procedure AddNodesForUnit(anUnitName: string; Files: TICCFiles);
|
procedure AddNodesForUnit(anUnitName: string; Files: TICCFiles);
|
||||||
public
|
public
|
||||||
@ -127,6 +138,20 @@ begin
|
|||||||
RegisterIDEMsgQuickFix(TQuickFixRecompilingChecksumChanged.Create);
|
RegisterIDEMsgQuickFix(TQuickFixRecompilingChecksumChanged.Create);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TICCFile }
|
||||||
|
|
||||||
|
constructor TICCFile.Create(AOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited Create(AOwner);
|
||||||
|
OwnerNames:=TStringList.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TICCFile.Destroy;
|
||||||
|
begin
|
||||||
|
FreeAndNil(OwnerNames);
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TICCFiles }
|
{ TICCFiles }
|
||||||
|
|
||||||
function TICCFiles.GetFiles(Index: integer): TICCFile;
|
function TICCFiles.GetFiles(Index: integer): TICCFile;
|
||||||
@ -178,84 +203,114 @@ begin
|
|||||||
FreeAndNil(FUnit2Files);
|
FreeAndNil(FUnit2Files);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TInspectChksumChgDialog.SearchUnit(anUnitName, SearchPath: string
|
procedure TInspectChksumChgDialog.FindUnitOwnerNames(aFile: TICCFile);
|
||||||
): TICCFiles;
|
var
|
||||||
|
Owners: TFPList;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Owners:=PackageEditingInterface.GetPossibleOwnersOfUnit(aFile.Filename,
|
||||||
|
[piosfIncludeSourceDirectories]);
|
||||||
|
//debugln(['TInspectChksumChgDialog.FindUnitOwnerNames ',aFile.Filename,' ',DbgSName(Owners)]);
|
||||||
|
if Owners<>nil then begin
|
||||||
|
for i:=0 to Owners.Count-1 do begin
|
||||||
|
if TObject(Owners[i]) is TIDEPackage then
|
||||||
|
aFile.OwnerNames.Add(TIDEPackage(Owners[i]).Name)
|
||||||
|
else if TObject(Owners[i]) is TLazProject then
|
||||||
|
aFile.OwnerNames.Add(ICC_Project);
|
||||||
|
end;
|
||||||
|
Owners.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure SeachDirectory(Dir: string);
|
procedure TInspectChksumChgDialog.SearchDirectory(anUnitName: string;
|
||||||
var
|
Dir: string; IsFPCPath: boolean; Files: TICCFiles);
|
||||||
DirCache: TCTDirectoryCache;
|
var
|
||||||
i: Integer;
|
DirCache: TCTDirectoryCache;
|
||||||
Filename: PChar;
|
i: Integer;
|
||||||
Ext: String;
|
Filename: PChar;
|
||||||
aFile: TICCFile;
|
Ext: String;
|
||||||
begin
|
aFile: TICCFile;
|
||||||
if (Dir='') or (not FilenameIsAbsolute(Dir)) then exit;
|
j: Integer;
|
||||||
// search in directory for all files that could be sources or ppu files of this unit
|
begin
|
||||||
DirCache:=CodeToolBoss.DirectoryCachePool.GetCache(Dir,true,false);
|
if (Dir='') or (not FilenameIsAbsolute(Dir)) then exit;
|
||||||
if (DirCache=nil) or (DirCache.Listing=nil) then exit;
|
// search in directory for all files that could be sources or ppu files of this unit
|
||||||
for i:=0 to DirCache.Listing.NameCount-1 do begin
|
DirCache:=CodeToolBoss.DirectoryCachePool.GetCache(Dir,true,false);
|
||||||
Filename:=PChar(@DirCache.Listing.Names[DirCache.Listing.NameStarts[i]]);
|
if (DirCache=nil) or (DirCache.Listing=nil) then exit;
|
||||||
Ext:=lowercase(ExtractFileExt(Filename));
|
for i:=0 to DirCache.Listing.NameCount-1 do begin
|
||||||
if ((Ext='.pas') or (Ext='.pp') or (Ext='.p') or (Ext='.ppu'))
|
Filename:=PChar(@DirCache.Listing.Names[DirCache.Listing.NameStarts[i]]);
|
||||||
and (SysUtils.CompareText(anUnitName,ExtractFileNameOnly(Filename))=0)
|
Ext:=lowercase(ExtractFileExt(Filename));
|
||||||
then begin
|
if ((Ext='.pas') or (Ext='.pp') or (Ext='.p') or (Ext='.ppu'))
|
||||||
|
and (SysUtils.CompareText(anUnitName,ExtractFileNameOnly(Filename))=0)
|
||||||
|
then begin
|
||||||
|
j:=Files.Count-1;
|
||||||
|
while (j>=0) and (CompareFilenames(Files[j].Filename,Filename)<>0) do
|
||||||
|
dec(j);
|
||||||
|
if j<0 then begin
|
||||||
//debugln(['TInspectChksumChgDialog.SearchUnit Unit="',anUnitName,'" Filename="',Filename,'"']);
|
//debugln(['TInspectChksumChgDialog.SearchUnit Unit="',anUnitName,'" Filename="',Filename,'"']);
|
||||||
aFile:=TICCFile.Create(nil);
|
aFile:=TICCFile.Create(nil);
|
||||||
aFile.Filename:=AppendPathDelim(Dir)+Filename;
|
aFile.Filename:=AppendPathDelim(Dir)+Filename;
|
||||||
aFile.Age:=FileAgeCached(aFile.Filename);
|
aFile.Age:=FileAgeCached(aFile.Filename);
|
||||||
Result.Add(aFile);
|
FindUnitOwnerNames(aFile);
|
||||||
|
if IsFPCPath then
|
||||||
|
aFile.OwnerNames.Add(ICC_FPC);
|
||||||
|
Files.Add(aFile);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure SearchInSearchPath;
|
procedure TInspectChksumChgDialog.SearchInSearchPath(anUnitName,
|
||||||
var
|
SearchPath: string; Files: TICCFiles);
|
||||||
CurDir: String;
|
var
|
||||||
p: LongInt;
|
CurDir: String;
|
||||||
l: Integer;
|
p: LongInt;
|
||||||
StartPos: Integer;
|
l: Integer;
|
||||||
begin
|
StartPos: Integer;
|
||||||
// search in search path
|
begin
|
||||||
StartPos:=1;
|
// search in search path
|
||||||
l:=length(SearchPath);
|
StartPos:=1;
|
||||||
while StartPos<=l do begin
|
l:=length(SearchPath);
|
||||||
p:=StartPos;
|
while StartPos<=l do begin
|
||||||
while (p<=l) and (SearchPath[p]<>';') do inc(p);
|
p:=StartPos;
|
||||||
CurDir:=TrimFilename(copy(SearchPath,StartPos,p-StartPos));
|
while (p<=l) and (SearchPath[p]<>';') do inc(p);
|
||||||
SeachDirectory(CurDir);
|
CurDir:=TrimFilename(copy(SearchPath,StartPos,p-StartPos));
|
||||||
StartPos:=p+1;
|
SearchDirectory(anUnitName,CurDir,false,Files);
|
||||||
end;
|
StartPos:=p+1;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure SearchInFPCFiles;
|
procedure TInspectChksumChgDialog.SearchInFPCFiles(
|
||||||
var
|
anUnitName, SearchPath: string; Files: TICCFiles);
|
||||||
UnitSetID: String;
|
var
|
||||||
UnitSet: TFPCUnitSetCache;
|
UnitSetID: String;
|
||||||
CfgCache: TFPCTargetConfigCache;
|
UnitSet: TFPCUnitSetCache;
|
||||||
i: Integer;
|
CfgCache: TFPCTargetConfigCache;
|
||||||
HasChanged: boolean;
|
i: Integer;
|
||||||
CurDir: String;
|
HasChanged: boolean;
|
||||||
begin
|
CurDir: String;
|
||||||
// search in fpc unit paths
|
begin
|
||||||
UnitSetID:=CodeToolBoss.GetUnitSetIDForDirectory('');
|
// search in fpc unit paths
|
||||||
if UnitSetID='' then exit;
|
UnitSetID:=CodeToolBoss.GetUnitSetIDForDirectory('');
|
||||||
UnitSet:=CodeToolBoss.FPCDefinesCache.FindUnitSetWithID(UnitSetID,HasChanged,false);
|
if UnitSetID='' then exit;
|
||||||
if UnitSet=nil then exit;
|
UnitSet:=CodeToolBoss.FPCDefinesCache.FindUnitSetWithID(UnitSetID,HasChanged,false);
|
||||||
CfgCache:=UnitSet.GetConfigCache(false);
|
if UnitSet=nil then exit;
|
||||||
if CfgCache=nil then exit;
|
CfgCache:=UnitSet.GetConfigCache(false);
|
||||||
if CfgCache.UnitPaths=nil then exit;
|
if CfgCache=nil then exit;
|
||||||
for i:=0 to CfgCache.UnitPaths.Count-1 do begin
|
if CfgCache.UnitPaths=nil then exit;
|
||||||
CurDir:=TrimFilename(CfgCache.UnitPaths[i]);
|
for i:=0 to CfgCache.UnitPaths.Count-1 do begin
|
||||||
SeachDirectory(CurDir);
|
CurDir:=TrimFilename(CfgCache.UnitPaths[i]);
|
||||||
end;
|
SearchDirectory(anUnitName,CurDir,false,Files);
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TInspectChksumChgDialog.SearchUnit(anUnitName, SearchPath: string
|
||||||
|
): TICCFiles;
|
||||||
begin
|
begin
|
||||||
Result:=TICCFiles.create(true);
|
Result:=TICCFiles.create(true);
|
||||||
if (anUnitName='') then exit;
|
if (anUnitName='') then exit;
|
||||||
|
|
||||||
SearchInSearchPath;
|
SearchInSearchPath(anUnitName,SearchPath,Result);
|
||||||
SearchInFPCFiles;
|
SearchInFPCFiles(anUnitName,SearchPath,Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TInspectChksumChgDialog.AddNodesForUnit(anUnitName: string;
|
procedure TInspectChksumChgDialog.AddNodesForUnit(anUnitName: string;
|
||||||
@ -264,15 +319,57 @@ var
|
|||||||
UnitNode: TTreeNode;
|
UnitNode: TTreeNode;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
aFile: TICCFile;
|
aFile: TICCFile;
|
||||||
|
FileNode: TTreeNode;
|
||||||
|
OwnerName: string;
|
||||||
|
j: Integer;
|
||||||
|
s: String;
|
||||||
|
APackage: TIDEPackage;
|
||||||
|
PPUCount: Integer;
|
||||||
|
SrcCount: Integer;
|
||||||
begin
|
begin
|
||||||
UnitNode:=InfoTreeView.Items.Add(nil,'Unit '+anUnitName);
|
UnitNode:=InfoTreeView.Items.Add(nil,'Unit '+anUnitName);
|
||||||
if Files<>nil then begin
|
if Files<>nil then begin
|
||||||
|
PPUCount:=0;
|
||||||
|
SrcCount:=0;
|
||||||
for i:=0 to Files.Count-1 do begin
|
for i:=0 to Files.Count-1 do begin
|
||||||
aFile:=Files[i];
|
aFile:=Files[i];
|
||||||
InfoTreeView.Items.AddChildObject(UnitNode,aFile.Filename,aFile);
|
if CompareFileExt(aFile.Filename,'.ppu',false)=0 then
|
||||||
|
inc(PPUCount)
|
||||||
|
else
|
||||||
|
inc(SrcCount);
|
||||||
|
FileNode:=InfoTreeView.Items.AddChildObject(UnitNode,aFile.Filename,aFile);
|
||||||
|
for j:=0 to aFile.OwnerNames.Count-1 do begin
|
||||||
|
OwnerName:=aFile.OwnerNames[j];
|
||||||
|
if OwnerName=ICC_FPC then begin
|
||||||
|
s:=lisInFPCUnitSearchPathProbablyInstalledByTheFPCPackag;
|
||||||
|
end else if OwnerName=ICC_Project then begin
|
||||||
|
s:=lisInASourceDirectoryOfTheProjectCheckForDuplicates;
|
||||||
|
end else begin
|
||||||
|
s:=Format(lisInASourceDirectoryOfThePackage, [OwnerName]);
|
||||||
|
APackage:=PackageEditingInterface.FindPackageWithName(OwnerName);
|
||||||
|
if APackage<>nil then begin
|
||||||
|
if APackage.IsVirtual then begin
|
||||||
|
s:=Format(lisCheckTheTargetOSCPULCLWidgetTypeMaybeYouHaveToReco, [
|
||||||
|
s]);
|
||||||
|
end else begin
|
||||||
|
s:=Format(lisMaybeYouHaveToRecompileThePackage, [s]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if s<>'' then
|
||||||
|
InfoTreeView.Items.AddChild(FileNode,s);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if PPUCount>1 then begin
|
||||||
|
InfoTreeView.Items.AddChild(FileNode,
|
||||||
|
lisDuplicatePpuFilesDeleteOneOrMakeSureAllSearchPaths);
|
||||||
|
end;
|
||||||
|
if SrcCount>1 then begin
|
||||||
|
InfoTreeView.Items.AddChild(FileNode,
|
||||||
|
lisDuplicateSourcesDeleteOneOrMakeSureAllSearchPathsH);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
UnitNode.Expanded:=true;
|
UnitNode.Expand(true);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TInspectChksumChgDialog.InitWithMsg(aMsg: TIDEMessageLine);
|
procedure TInspectChksumChgDialog.InitWithMsg(aMsg: TIDEMessageLine);
|
||||||
@ -287,7 +384,7 @@ begin
|
|||||||
FreeAndNil(FUnit2Files);
|
FreeAndNil(FUnit2Files);
|
||||||
|
|
||||||
SearchPath:=CodeToolBoss.GetCompleteSrcPathForDirectory('');
|
SearchPath:=CodeToolBoss.GetCompleteSrcPathForDirectory('');
|
||||||
debugln(['TInspectChksumChgDialog.InitWithMsg SearchPath=',SearchPath]);
|
//debugln(['TInspectChksumChgDialog.InitWithMsg SearchPath=',SearchPath]);
|
||||||
FUnit1Files:=SearchUnit(Unit1,SearchPath);
|
FUnit1Files:=SearchUnit(Unit1,SearchPath);
|
||||||
FUnit2Files:=SearchUnit(Unit2,SearchPath);
|
FUnit2Files:=SearchUnit(Unit2,SearchPath);
|
||||||
|
|
||||||
|
@ -5101,6 +5101,24 @@ resourcestring
|
|||||||
lisTheCurrentFPCHasNoConfigFileItWillProbablyMissSome = 'The current FPC '
|
lisTheCurrentFPCHasNoConfigFileItWillProbablyMissSome = 'The current FPC '
|
||||||
+'has no config file. It will probably miss some units. Check your '
|
+'has no config file. It will probably miss some units. Check your '
|
||||||
+'installation of fpc.';
|
+'installation of fpc.';
|
||||||
|
lisInFPCUnitSearchPathProbablyInstalledByTheFPCPackag = 'In FPC unit search '
|
||||||
|
+'path. Probably installed by the FPC package. Check if the compiler and '
|
||||||
|
+'the ppu file are from the same installation.';
|
||||||
|
lisInASourceDirectoryOfTheProjectCheckForDuplicates = 'In a source '
|
||||||
|
+'directory of the project. Check for duplicates.';
|
||||||
|
lisInASourceDirectoryOfThePackage = 'In a source directory of the package "%'
|
||||||
|
+'s".';
|
||||||
|
lisCheckTheTargetOSCPULCLWidgetTypeMaybeYouHaveToReco = '%s Check the '
|
||||||
|
+'target (OS, CPU, LCL widget type). Maybe you have to recompile the '
|
||||||
|
+'package for this target or set another target for the project.';
|
||||||
|
lisMaybeYouHaveToRecompileThePackage = '%s Maybe you have to recompile the '
|
||||||
|
+'package.';
|
||||||
|
lisDuplicatePpuFilesDeleteOneOrMakeSureAllSearchPaths = 'Duplicate ppu '
|
||||||
|
+'files. Delete one or make sure all search paths have correct order ('
|
||||||
|
+'Hint: FPC uses last path first).';
|
||||||
|
lisDuplicateSourcesDeleteOneOrMakeSureAllSearchPathsH = 'Duplicate sources. '
|
||||||
|
+'Delete one or make sure all search paths have correct order (Hint: FPC '
|
||||||
|
+'uses last path first).';
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
@ -1151,11 +1151,13 @@ begin
|
|||||||
SrcDir:=ExtractFilePath(TheFilename);
|
SrcDir:=ExtractFilePath(TheFilename);
|
||||||
for i:=0 to Cnt-1 do begin
|
for i:=0 to Cnt-1 do begin
|
||||||
APackage:=Packages[i];
|
APackage:=Packages[i];
|
||||||
if APackage.IsVirtual then continue;
|
if APackage.IsVirtual and (not APackage.AutoCreated) then continue;
|
||||||
// source directories + unit path + base directory
|
// source directories + unit path without inherited paths + base directory + output directory
|
||||||
PkgDirs:=APackage.CompilerOptions.GetParsedPath(pcosUnitPath,icoNone,false);
|
PkgDirs:=APackage.CompilerOptions.GetParsedPath(pcosUnitPath,icoNone,false);
|
||||||
PkgDirs:=MergeSearchPaths(PkgDirs,APackage.SourceDirectories.CreateSearchPathFromAllFiles);
|
PkgDirs:=MergeSearchPaths(PkgDirs,APackage.SourceDirectories.CreateSearchPathFromAllFiles);
|
||||||
|
PkgDirs:=MergeSearchPaths(PkgDirs,APackage.GetOutputDirectory);
|
||||||
PkgDirs:=MergeSearchPaths(PkgDirs,APackage.Directory);
|
PkgDirs:=MergeSearchPaths(PkgDirs,APackage.Directory);
|
||||||
|
//debugln(['TLazPackageGraph.FindPossibleOwnersOfUnit ',APackage.Name,' ',PkgDirs]);
|
||||||
if FindPathInSearchPath(PChar(SrcDir),length(SrcDir),
|
if FindPathInSearchPath(PChar(SrcDir),length(SrcDir),
|
||||||
PChar(PkgDirs),length(PkgDirs))<>nil
|
PChar(PkgDirs),length(PkgDirs))<>nil
|
||||||
then
|
then
|
||||||
|
@ -2503,7 +2503,7 @@ begin
|
|||||||
ID:=TLazPackageID.Create;
|
ID:=TLazPackageID.Create;
|
||||||
try
|
try
|
||||||
ID.Name:=PkgName;
|
ID.Name:=PkgName;
|
||||||
Result:=PackageGraph.FindPackageWithID(ID);
|
Result:=PackageGraph.FindPackageWithIDMask(ID);
|
||||||
finally
|
finally
|
||||||
ID.Free;
|
ID.Free;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user