pastojs: fixed include file search in module directory

This commit is contained in:
mattias 2019-03-06 18:12:13 +00:00
parent 1e56a381ec
commit 0e7de6af01
4 changed files with 35 additions and 9 deletions

View File

@ -257,7 +257,7 @@ type
function FindCustomJSFileName(const aFilename: string): String; override;
function FindUnitJSFileName(const aUnitFilename: string): String; override;
function FindUnitFileName(const aUnitname, InFilename, ModuleDir: string; out IsForeign: boolean): String; override;
function FindIncludeFileName(const aFilename: string): String; override;
function FindIncludeFileName(const aFilename, ModuleDir: string): String; override;
function AddIncludePaths(const Paths: string; FromCmdLine: boolean; out ErrorMsg: string): boolean;
function AddUnitPaths(const Paths: string; FromCmdLine: boolean; out ErrorMsg: string): boolean;
function AddSrcUnitPaths(const Paths: string; FromCmdLine: boolean; out ErrorMsg: string): boolean;
@ -1812,7 +1812,8 @@ begin
UsePointDirectory, true, RelPath);
end;
function TPas2jsFilesCache.FindIncludeFileName(const aFilename: string): String;
function TPas2jsFilesCache.FindIncludeFileName(const aFilename,
ModuleDir: string): String;
function SearchCasedInIncPath(const Filename: string): string;
var
@ -1820,9 +1821,9 @@ function TPas2jsFilesCache.FindIncludeFileName(const aFilename: string): String;
begin
// file name is relative
// first search in the same directory as the unit
if BaseDirectory<>'' then
if ModuleDir<>'' then
begin
Result:=BaseDirectory+Filename;
Result:=IncludeTrailingPathDelimiter(ModuleDir)+Filename;
if SearchLowUpCase(Result) then exit;
end;
// then search in include path

View File

@ -96,7 +96,7 @@ Type
function FindSourceFileName(const aFilename: string): String; virtual; abstract;
Public
// Public Abstract. Must be overridden
function FindIncludeFileName(const aFilename: string): String; virtual; abstract;
function FindIncludeFileName(const aFilename, ModuleDir: string): String; virtual; abstract;
function LoadFile(Filename: string; Binary: boolean = false): TPas2jsFile; virtual; abstract;
Function FileExists(Const aFileName: String): Boolean; virtual; abstract;
function FindUnitJSFileName(const aUnitFilename: string): String; virtual; abstract;
@ -416,7 +416,7 @@ var
Filename: String;
begin
Result:=nil;
Filename:=FS.FindIncludeFileName(aFilename);
Filename:=FS.FindIncludeFileName(aFilename,BaseDirectory);
if Filename='' then exit;
try
Result:=FindSourceFile(Filename);
@ -433,7 +433,7 @@ end;
function TPas2jsFSResolver.FindIncludeFileName(const aFilename: string): String;
begin
Result:=FS.FindIncludeFileName(aFilename);
Result:=FS.FindIncludeFileName(aFilename,BaseDirectory);
end;

View File

@ -3727,8 +3727,11 @@ begin
' s = ''end'';',
' s = "end";',
' return Result;',
'};'
]),
'};',
'this.Fly = function () {',
' return;',
'};',
'']),
LinesToStr([
''
]));

View File

@ -143,6 +143,7 @@ type
procedure TestUS_Program_FU;
procedure TestUS_Program_FU_o;
procedure TestUS_Program_FE_o;
procedure TestUS_IncludeSameDir;
procedure TestUS_UsesInFile;
procedure TestUS_UsesInFile_Duplicate;
@ -695,6 +696,27 @@ begin
AssertNotNull('foo.js not found',FindFile('foo.js'));
end;
procedure TTestCLI_UnitSearch.TestUS_IncludeSameDir;
begin
AddUnit('system.pp',[''],['']);
AddFile('sub/defines.inc',[
'{$Define foo}',
'']);
AddUnit('sub/unit1.pas',
['{$I defines.inc}',
'{$ifdef foo}',
'var a: longint;',
'{$endif}'],
['']);
AddFile('test1.pas',[
'uses unit1;',
'begin',
' a:=3;',
'end.']);
AddDir('lib');
Compile(['test1.pas','-Fusub','-FElib','-ofoo.js']);
end;
procedure TTestCLI_UnitSearch.TestUS_UsesInFile;
begin
AddUnit('system.pp',[''],['']);