mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-14 14:29:31 +01:00
implemented searching for unit source in all CompiledSrcPaths of all unit paths
git-svn-id: trunk@7352 -
This commit is contained in:
parent
1bfc334185
commit
cc6e69cc7a
@ -1337,6 +1337,47 @@ var
|
|||||||
Result:=nil;
|
Result:=nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function SearchUnitFileInCompiledSrcPaths(const APath, TheUnitName: string
|
||||||
|
): TCodeBuffer;
|
||||||
|
var PathStart, PathEnd: integer;
|
||||||
|
ADir: string;
|
||||||
|
CurCompiledSrcPath: string;
|
||||||
|
begin
|
||||||
|
{$IFDEF ShowTriedFiles}
|
||||||
|
DebugLn('TFindDeclarationTool..SearchUnitFileInCompiledSrcPaths START APath="',APath,'" TheUnitName="',TheUnitName,'"');
|
||||||
|
{$ENDIF}
|
||||||
|
if not Assigned(OnGetSrcPathForCompiledUnit) then begin
|
||||||
|
Result:=nil;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
PathStart:=1;
|
||||||
|
while PathStart<=length(APath) do begin
|
||||||
|
PathEnd:=PathStart;
|
||||||
|
while (PathEnd<=length(APath)) and (APath[PathEnd]<>';') do inc(PathEnd);
|
||||||
|
if PathEnd>PathStart then begin
|
||||||
|
// extract and expand current search directory
|
||||||
|
ADir:=copy(APath,PathStart,PathEnd-PathStart);
|
||||||
|
if (ADir<>'') and (ADir[length(ADir)]<>PathDelim) then
|
||||||
|
ADir:=ADir+PathDelim;
|
||||||
|
if not FilenameIsAbsolute(ADir) then ADir:=CurDir+ADir;
|
||||||
|
// get CompiledSrcPath for current search directory
|
||||||
|
CurCompiledSrcPath:=OnGetSrcPathForCompiledUnit(Self,ADir);
|
||||||
|
if CurCompiledSrcPath<>'' then begin
|
||||||
|
// this directory is an unit output directory
|
||||||
|
// -> search the source in the current CompiledSrcPath
|
||||||
|
{$IFDEF ShowTriedFiles}
|
||||||
|
DebugLn('TFindDeclarationTool..SearchUnitFileInCompiledSrcPaths CurCompiledSrcPath="',CurCompiledSrcPath,'"');
|
||||||
|
{$ENDIF}
|
||||||
|
Result:=SearchUnitFileInPath(CurCompiledSrcPath,TheUnitName,true);
|
||||||
|
if Result<>nil then exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
PathStart:=PathEnd+1;
|
||||||
|
end;
|
||||||
|
Result:=nil;
|
||||||
|
end;
|
||||||
|
|
||||||
function SearchFileInPath(const APath, RelativeFilename: string): TCodeBuffer;
|
function SearchFileInPath(const APath, RelativeFilename: string): TCodeBuffer;
|
||||||
var PathStart, PathEnd: integer;
|
var PathStart, PathEnd: integer;
|
||||||
ADir: string;
|
ADir: string;
|
||||||
@ -1420,6 +1461,7 @@ var UnitSrcSearchPath: string;
|
|||||||
CompiledResult: TCodeBuffer;
|
CompiledResult: TCodeBuffer;
|
||||||
UnitSearchPath: string;
|
UnitSearchPath: string;
|
||||||
SrcPathInitialized: boolean;
|
SrcPathInitialized: boolean;
|
||||||
|
WorkingUnitInFilename: String;
|
||||||
|
|
||||||
procedure InitSrcPath;
|
procedure InitSrcPath;
|
||||||
begin
|
begin
|
||||||
@ -1466,17 +1508,18 @@ begin
|
|||||||
|
|
||||||
// search as the compiler would search
|
// search as the compiler would search
|
||||||
if AnUnitInFilename<>'' then begin
|
if AnUnitInFilename<>'' then begin
|
||||||
|
WorkingUnitInFilename:=SetDirSeparators(AnUnitInFilename);
|
||||||
// uses IN parameter
|
// uses IN parameter
|
||||||
if FilenameIsAbsolute(AnUnitInFilename) then begin
|
if FilenameIsAbsolute(WorkingUnitInFilename) then begin
|
||||||
Result:=TCodeBuffer(Scanner.OnLoadSource(Self,AnUnitInFilename,true));
|
Result:=TCodeBuffer(Scanner.OnLoadSource(Self,WorkingUnitInFilename,true));
|
||||||
end else begin
|
end else begin
|
||||||
// file is relative to current unit directory
|
// file is relative to current unit directory
|
||||||
// -> search file in current directory
|
// -> search file in current directory
|
||||||
CurDir:=AppendPathDelim(CurDir);
|
CurDir:=AppendPathDelim(CurDir);
|
||||||
if not LoadFile(CurDir+AnUnitInFilename,Result) then begin
|
if not LoadFile(CurDir+WorkingUnitInFilename,Result) then begin
|
||||||
// search AnUnitInFilename in searchpath
|
// search AnUnitInFilename in searchpath
|
||||||
InitSrcPath;
|
InitSrcPath;
|
||||||
Result:=SearchFileInPath(UnitSrcSearchPath,AnUnitInFilename);
|
Result:=SearchFileInPath(UnitSrcSearchPath,WorkingUnitInFilename);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
@ -1495,25 +1538,17 @@ begin
|
|||||||
Result:=SearchUnitFileInPath(UnitSrcSearchPath,AnUnitName,true);
|
Result:=SearchUnitFileInPath(UnitSrcSearchPath,AnUnitName,true);
|
||||||
end;
|
end;
|
||||||
if Result=nil then begin
|
if Result=nil then begin
|
||||||
|
// search for compiled unit
|
||||||
|
|
||||||
|
// search compiled unit in current directory
|
||||||
{$IFDEF ShowTriedFiles}
|
{$IFDEF ShowTriedFiles}
|
||||||
DebugLn('TFindDeclarationTool.FindUnitSource Search Compiled unit in current dir=',CurDir);
|
DebugLn('TFindDeclarationTool.FindUnitSource Search Compiled unit in current dir=',CurDir);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
// search compiled unit in current directory
|
|
||||||
if Scanner.InitialValues.IsDefined('WIN32')
|
if Scanner.InitialValues.IsDefined('WIN32')
|
||||||
and Scanner.InitialValues.IsDefined('VER1_0') then
|
and Scanner.InitialValues.IsDefined('VER1_0') then
|
||||||
CompiledSrcExt:='.ppw';
|
CompiledSrcExt:='.ppw';
|
||||||
CompiledResult:=SearchUnitFileInDir(CurDir,AnUnitName,false);
|
CompiledResult:=SearchUnitFileInDir(CurDir,AnUnitName,false);
|
||||||
|
|
||||||
// search compiled unit in src path
|
|
||||||
if CompiledResult=nil then begin
|
|
||||||
{$IFDEF ShowTriedFiles}
|
|
||||||
DebugLn('TFindDeclarationTool.FindUnitSource Search Compiled unit in src path=',UnitSrcSearchPath);
|
|
||||||
{$ENDIF}
|
|
||||||
InitSrcPath;
|
|
||||||
CompiledResult:=SearchUnitFileInPath(UnitSrcSearchPath,AnUnitName,false);
|
|
||||||
end;
|
|
||||||
|
|
||||||
// search compiled unit in unit path
|
// search compiled unit in unit path
|
||||||
if CompiledResult=nil then begin
|
if CompiledResult=nil then begin
|
||||||
UnitSearchPath:=Scanner.Values[ExternalMacroStart+'UnitPath'];
|
UnitSearchPath:=Scanner.Values[ExternalMacroStart+'UnitPath'];
|
||||||
@ -1538,6 +1573,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
if Result=nil then begin
|
||||||
|
// search in every unit path for a CompiledSrcPath and search there
|
||||||
|
|
||||||
|
{$IFDEF ShowTriedFiles}
|
||||||
|
DebugLn('TFindDeclarationTool.FindUnitSource Search Compiled unit in current dir=',CurDir);
|
||||||
|
{$ENDIF}
|
||||||
|
UnitSearchPath:=Scanner.Values[ExternalMacroStart+'UnitPath'];
|
||||||
|
Result:=SearchUnitFileInCompiledSrcPaths(UnitSearchPath,AnUnitName);
|
||||||
|
end;
|
||||||
|
|
||||||
if Result=nil then begin
|
if Result=nil then begin
|
||||||
// search in FPC source directory
|
// search in FPC source directory
|
||||||
Result:=SearchUnitInUnitLinks(AnUnitName);
|
Result:=SearchUnitInUnitLinks(AnUnitName);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user