codetools: TFPCUnitSetCache.GetUnitSrcFile: always return source file in search path first

git-svn-id: trunk@41410 -
This commit is contained in:
mattias 2013-05-26 10:08:41 +00:00
parent 5df0a63a69
commit 3c5ec2b499

View File

@ -8422,37 +8422,48 @@ end;
function TFPCUnitSetCache.GetUnitSrcFile(const AnUnitName: string; function TFPCUnitSetCache.GetUnitSrcFile(const AnUnitName: string;
MustHavePPU: boolean; SkipPPUCheckIfTargetIsSourceOnly: boolean): string; MustHavePPU: boolean; SkipPPUCheckIfTargetIsSourceOnly: boolean): string;
{ Searches the unit in the FPC search path and sources.
MustHavePPU: only search the sources if there is a ppu in the search path
}
var var
Tree: TStringToStringTree; Tree: TStringToStringTree;
ConfigCache: TFPCTargetConfigCache; ConfigCache: TFPCTargetConfigCache;
UnitInFPCPath: String;
begin begin
Result:=''; Result:='';
{$IFDEF ShowTriedUnits} {$IFDEF ShowTriedUnits}
debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" MustHavePPU=',MustHavePPU,' SkipPPUCheckIfNoneExists=',SkipPPUCheckIfNoneExists]); debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" MustHavePPU=',MustHavePPU,' SkipPPUCheckIfNoneExists=',SkipPPUCheckIfNoneExists]);
{$ENDIF} {$ENDIF}
Tree:=GetUnitToSourceTree(false); Tree:=GetUnitToSourceTree(false);
if MustHavePPU then begin ConfigCache:=GetConfigCache(false);
ConfigCache:=GetConfigCache(false); if (ConfigCache.Units<>nil) then begin
if (ConfigCache.Units<>nil) UnitInFPCPath:=ConfigCache.Units[AnUnitName];
and (CompareFileExt(ConfigCache.Units[AnUnitName],'ppu',false)<>0) if (CompareFileExt(UnitInFPCPath,'ppu',false)=0) then begin
then begin // there is a ppu
end else if UnitInFPCPath<>'' then begin
// there is a pp or pas in the FPC search path
Result:=UnitInFPCPath;
exit;
end else begin
// unit has no ppu in the FPC ppu search path // unit has no ppu in the FPC ppu search path
if ConfigCache.HasPPUs then begin if MustHavePPU then begin
// but there are other ppu files if ConfigCache.HasPPUs then begin
{$IFDEF ShowTriedUnits} // but there are other ppu files
debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" unit has no ppu file in FPC path, but there are other ppu']); {$IFDEF ShowTriedUnits}
{$ENDIF} debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" unit has no ppu file in FPC path, but there are other ppu']);
exit; {$ENDIF}
end else begin
// no ppu exists at all
// => the fpc is not installed properly for this target
{$IFDEF ShowTriedUnits}
debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" there are no ppu files for this target']);
{$ENDIF}
if not SkipPPUCheckIfTargetIsSourceOnly then
exit; exit;
// => search directly in the sources end else begin
// this allows cross editing even if FPC is not installed for this target // no ppu exists at all
// => the fpc is not installed properly for this target
{$IFDEF ShowTriedUnits}
debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" there are no ppu files for this target']);
{$ENDIF}
if (not SkipPPUCheckIfTargetIsSourceOnly) then
exit;
// => search directly in the sources
// this allows cross editing even if FPC is not installed for this target
end;
end; end;
end; end;
end; end;
@ -8460,17 +8471,6 @@ begin
Result:=Tree[AnUnitName]; Result:=Tree[AnUnitName];
if (Result<>'') and (not FilenameIsAbsolute(Result)) then if (Result<>'') and (not FilenameIsAbsolute(Result)) then
Result:=FPCSourceDirectory+Result; Result:=FPCSourceDirectory+Result;
if (Result='') then begin
// maybe the source is in the fpc search path
ConfigCache:=GetConfigCache(false);
if ConfigCache<>nil then begin
Result:=ConfigCache.Units[AnUnitName];
if (CompareFileExt(Result,'ppu',false)=0) then begin
Result:='';
exit;
end;
end;
end;
{$IFDEF ShowTriedUnits} {$IFDEF ShowTriedUnits}
debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" Result=',Result]); debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" Result=',Result]);
{$ENDIF} {$ENDIF}