Browse Source

pastojs: fixed -FU -o, -o is always relative to working directory

git-svn-id: trunk@39189 -
Mattias Gaertner 7 years ago
parent
commit
8c8b983c37
2 changed files with 73 additions and 7 deletions
  1. 22 6
      packages/pastojs/src/pas2jscompiler.pp
  2. 51 1
      packages/pastojs/tests/tcunitsearch.pas

+ 22 - 6
packages/pastojs/src/pas2jscompiler.pp

@@ -487,6 +487,7 @@ type
     procedure AddUsedUnit(aFile: TPas2jsCompilerFile);
 
     function DirectoryExists(const Filename: string): boolean;
+    function ExpandFileName(const Filename: string): string;
   public
     property CompilerExe: string read FCompilerExe write SetCompilerExe;
     property ConditionEvaluator: TCondDirectiveEvaluator read FConditionEval;
@@ -2598,7 +2599,7 @@ end;
 procedure TPas2jsCompiler.SetCompilerExe(AValue: string);
 begin
   if AValue<>'' then
-    AValue:=ExpandFileNameUTF8(AValue,FileCache.BaseDirectory);
+    AValue:=ExpandFileName(AValue);
   if FCompilerExe=AValue then Exit;
   FCompilerExe:=AValue;
 end;
@@ -2933,7 +2934,7 @@ procedure TPas2jsCompiler.LoadDefaultConfig;
   begin
     Result:=false;
     if aFilename='' then exit;
-    aFilename:=ExpandFileNameUTF8(aFilename,FileCache.BaseDirectory);
+    aFilename:=ExpandFileName(aFilename);
     if ShowTriedUsedFiles then
       Log.LogMsgIgnoreFilter(nConfigFileSearch,[aFilename]);
     if not DirectoryCache.FileExists(aFilename) then exit;
@@ -3251,6 +3252,7 @@ begin
               end;
           'o':
             begin
+              // -Jo<flag>
               Identifier:=String(p);
               if Identifier='' then
                 ParamFatal('missing value of -Jo option');
@@ -3314,7 +3316,16 @@ begin
       'o': // output file, main JavaScript file
         begin
           inc(p);
-          FileCache.MainJSFile:=String(p);
+          aFilename:=String(p);
+          if aFilename='' then
+            ParamFatal('invalid empty output file (-o)')
+          else if aFilename='..' then
+            ParamFatal('invalid output file (-o) "'+aFilename+'"')
+          else if aFilename='.' then
+            // ok, stdout
+          else
+            aFilename:=ExpandFileName(aFilename);
+          FileCache.MainJSFile:=aFilename;
         end;
       'O': // optimizations
         begin
@@ -3428,7 +3439,7 @@ begin
       aFilename:=copy(Param,2,length(Param));
       if aFilename='' then
         ParamFatal('invalid config file at param position '+IntToStr(i));
-      aFilename:=ExpandFileNameUTF8(aFilename,FileCache.BaseDirectory);
+      aFilename:=ExpandFileName(aFilename);
       if not DirectoryCache.FileExists(aFilename) then
         ParamFatal('config file not found: "'+copy(Param,2,length(Param))+'"');
       LoadConfig(aFilename);
@@ -3441,7 +3452,7 @@ begin
         CfgSyntaxError('invalid parameter');
       if FileCache.MainSrcFile<>'' then
         ParamFatal('Only one Pascal file is supported, but got "'+FileCache.MainSrcFile+'" and "'+Param+'".');
-      aFilename:=ExpandFileNameUTF8(Param,FileCache.BaseDirectory);
+      aFilename:=ExpandFileName(Param);
       FileCache.MainSrcFile:=aFilename;
     end;
   end;
@@ -4275,7 +4286,7 @@ begin
     Terminate(ExitCodeFileNotFound);
   end;
 
-  UnitFilename:=ExpandFileNameUTF8(UnitFilename,FileCache.BaseDirectory);
+  UnitFilename:=ExpandFileName(UnitFilename);
   if DirectoryCache.DirectoryExists(UnitFilename) then
   begin
     Log.LogMsg(nFileIsFolder,[QuoteStr(UnitFilename)]);
@@ -4356,5 +4367,10 @@ begin
   Result:=FileCache.DirectoryCache.DirectoryExists(Filename);
 end;
 
+function TPas2jsCompiler.ExpandFileName(const Filename: string): string;
+begin
+  Result:=ExpandFileNameUTF8(Filename,FileCache.BaseDirectory);
+end;
+
 end.
 

+ 51 - 1
packages/pastojs/tests/tcunitsearch.pas

@@ -132,6 +132,10 @@ type
   published
     procedure TestUS_Program;
     procedure TestUS_UsesEmptyFileFail;
+    procedure TestUS_Program_o;
+    procedure TestUS_Program_FU;
+    procedure TestUS_Program_FU_o;
+    procedure TestUS_Program_FE_o;
 
     procedure TestUS_UsesInFile;
     procedure TestUS_UsesInFile_Duplicate;
@@ -556,6 +560,7 @@ begin
     'begin',
     'end.']);
   Compile(['test1.pas','-va']);
+  AssertNotNull('test1.js not found',FindFile('test1.js'));
 end;
 
 procedure TTestCLI_UnitSearch.TestUS_UsesEmptyFileFail;
@@ -564,10 +569,55 @@ begin
   AddFile('test1.pas',[
     'begin',
     'end.']);
-  Compile(['test1.pas',''],ExitCodeSyntaxError);
+  Compile(['test1.pas'],ExitCodeSyntaxError);
   AssertEquals('ErrorMsg','Expected "unit"',ErrorMsg);
 end;
 
+procedure TTestCLI_UnitSearch.TestUS_Program_o;
+begin
+  AddUnit('system.pp',[''],['']);
+  AddFile('test1.pas',[
+    'begin',
+    'end.']);
+  Compile(['test1.pas','-obla.js']);
+  AssertNotNull('bla.js not found',FindFile('bla.js'));
+end;
+
+procedure TTestCLI_UnitSearch.TestUS_Program_FU;
+begin
+  AddUnit('system.pp',[''],['']);
+  AddFile('test1.pas',[
+    'begin',
+    'end.']);
+  AddDir('lib');
+  Compile(['test1.pas','-FUlib']);
+  AssertNotNull('lib/test1.js not found',FindFile('lib/test1.js'));
+end;
+
+procedure TTestCLI_UnitSearch.TestUS_Program_FU_o;
+begin
+  AddUnit('system.pp',[''],['']);
+  AddFile('test1.pas',[
+    'begin',
+    'end.']);
+  AddDir('lib');
+  Compile(['test1.pas','-FUlib','-ofoo.js']);
+  AssertNotNull('lib/system.js not found',FindFile('lib/system.js'));
+  AssertNotNull('foo.js not found',FindFile('foo.js'));
+end;
+
+procedure TTestCLI_UnitSearch.TestUS_Program_FE_o;
+begin
+  AddUnit('system.pp',[''],['']);
+  AddFile('test1.pas',[
+    'begin',
+    'end.']);
+  AddDir('lib');
+  Compile(['test1.pas','-FElib','-ofoo.js']);
+  AssertNotNull('lib/system.js not found',FindFile('lib/system.js'));
+  AssertNotNull('foo.js not found',FindFile('foo.js'));
+end;
+
 procedure TTestCLI_UnitSearch.TestUS_UsesInFile;
 begin
   AddUnit('system.pp',[''],['']);