pastojs: option -FE

git-svn-id: trunk@38983 -
This commit is contained in:
Mattias Gaertner 2018-05-12 18:26:39 +00:00
parent 59e79bb8f6
commit 8a5c519f2d
4 changed files with 36 additions and 12 deletions

View File

@ -172,6 +172,7 @@ const
nCantAssignValuesToConstVariable = 3110; nCantAssignValuesToConstVariable = 3110;
nIllegalAssignmentToForLoopVar = 3111; nIllegalAssignmentToForLoopVar = 3111;
nFunctionHidesIdentifier_NonProc = 3112; nFunctionHidesIdentifier_NonProc = 3112;
// Note: use one of the free IDs above
// using same IDs as FPC // using same IDs as FPC
nVirtualMethodXHasLowerVisibility = 3250; nVirtualMethodXHasLowerVisibility = 3250;
@ -286,7 +287,6 @@ resourcestring
sMissingFieldsX = 'Missing fields: "%s"'; sMissingFieldsX = 'Missing fields: "%s"';
sCantAssignValuesToConstVariable = 'Can''t assign values to const variable'; sCantAssignValuesToConstVariable = 'Can''t assign values to const variable';
sIllegalAssignmentToForLoopVar = 'Illegal assignment to for-loop variable "%s"'; sIllegalAssignmentToForLoopVar = 'Illegal assignment to for-loop variable "%s"';
// sFunctionHidesIdentifier_NonProc = sFunctionHidesIdentifier
type type
{ TResolveData - base class for data stored in TPasElement.CustomData } { TResolveData - base class for data stored in TPasElement.CustomData }

View File

@ -3129,6 +3129,7 @@ begin
inc(p); inc(p);
case c of case c of
'e': Log.OutputFilename:=String(p); 'e': Log.OutputFilename:=String(p);
'E': FileCache.MainOutputPath:=String(p);
'i': if not FileCache.AddIncludePaths(String(p),FromCmdLine,ErrorMsg) then 'i': if not FileCache.AddIncludePaths(String(p),FromCmdLine,ErrorMsg) then
ParamFatal('invalid include path (-Fi) "'+ErrorMsg+'"'); ParamFatal('invalid include path (-Fi) "'+ErrorMsg+'"');
'N': if not FileCache.AddNamespaces(String(p),FromCmdLine,ErrorMsg) then 'N': if not FileCache.AddNamespaces(String(p),FromCmdLine,ErrorMsg) then
@ -3972,6 +3973,7 @@ begin
l(' R : Object checks. Verify method calls and object type casts.'); l(' R : Object checks. Verify method calls and object type casts.');
l(' -F... Set file names and paths:'); l(' -F... Set file names and paths:');
l(' -Fe<x> : Redirect output to file <x>. UTF-8 encoded.'); l(' -Fe<x> : Redirect output to file <x>. UTF-8 encoded.');
l(' -FE<x> : Set main output path to <x>');
l(' -Fi<x> : Add <x> to include paths'); l(' -Fi<x> : Add <x> to include paths');
l(' -FN<x> : add <x> to namespaces. Namespaces with trailing - are removed.'); l(' -FN<x> : add <x> to namespaces. Namespaces with trailing - are removed.');
l(' Delphi calls this flag "unit scope names".'); l(' Delphi calls this flag "unit scope names".');
@ -4144,6 +4146,7 @@ begin
for i:=0 to FileCache.IncludePaths.Count-1 do for i:=0 to FileCache.IncludePaths.Count-1 do
WriteFolder('include path',FileCache.IncludePaths[i]); WriteFolder('include path',FileCache.IncludePaths[i]);
WriteFolder('unit output path',FileCache.UnitOutputPath); WriteFolder('unit output path',FileCache.UnitOutputPath);
WriteFolder('main output path',FileCache.MainOutputPath);
Log.LogMsgIgnoreFilter(nNameValue,['output file',QuoteStr(FileCache.MainJSFile)]); Log.LogMsgIgnoreFilter(nNameValue,['output file',QuoteStr(FileCache.MainJSFile)]);
end; end;

View File

@ -261,6 +261,7 @@ type
TPas2jsFilesCache = class TPas2jsFilesCache = class
private private
FBaseDirectory: string; FBaseDirectory: string;
FDefaultOutputPath: string;
FDirectoryCache: TPas2jsCachedDirectories; FDirectoryCache: TPas2jsCachedDirectories;
FFiles: TAVLTree; // tree of TPas2jsCachedFile sorted for Filename FFiles: TAVLTree; // tree of TPas2jsCachedFile sorted for Filename
FForeignUnitPaths: TStringList; FForeignUnitPaths: TStringList;
@ -295,6 +296,7 @@ type
procedure SetBaseDirectory(AValue: string); procedure SetBaseDirectory(AValue: string);
function AddSearchPaths(const Paths: string; Kind: TPas2jsSearchPathKind; function AddSearchPaths(const Paths: string; Kind: TPas2jsSearchPathKind;
FromCmdLine: boolean; var List: TStringList; var CmdLineCount: integer): string; FromCmdLine: boolean; var List: TStringList; var CmdLineCount: integer): string;
procedure SetDefaultOutputPath(AValue: string);
procedure SetMainJSFile(AValue: string); procedure SetMainJSFile(AValue: string);
procedure SetOptions(AValue: TP2jsFileCacheOptions); procedure SetOptions(AValue: TP2jsFileCacheOptions);
procedure SetSearchLikeFPC(const AValue: boolean); procedure SetSearchLikeFPC(const AValue: boolean);
@ -332,6 +334,7 @@ type
public public
property AllJSIntoMainJS: Boolean read GetAllJSIntoMainJS write SetAllJSIntoMainJS; property AllJSIntoMainJS: Boolean read GetAllJSIntoMainJS write SetAllJSIntoMainJS;
property BaseDirectory: string read FBaseDirectory write SetBaseDirectory; // includes trailing pathdelim property BaseDirectory: string read FBaseDirectory write SetBaseDirectory; // includes trailing pathdelim
property MainOutputPath: string read FDefaultOutputPath write SetDefaultOutputPath; // includes trailing pathdelim
property DirectoryCache: TPas2jsCachedDirectories read FDirectoryCache; property DirectoryCache: TPas2jsCachedDirectories read FDirectoryCache;
property ForeignUnitPaths: TStringList read FForeignUnitPaths; property ForeignUnitPaths: TStringList read FForeignUnitPaths;
property ForeignUnitPathsFromCmdLine: integer read FForeignUnitPathsFromCmdLine; property ForeignUnitPathsFromCmdLine: integer read FForeignUnitPathsFromCmdLine;
@ -1651,6 +1654,13 @@ begin
end; end;
end; end;
procedure TPas2jsFilesCache.SetDefaultOutputPath(AValue: string);
begin
AValue:=ExpandDirectory(AValue,BaseDirectory);
if FDefaultOutputPath=AValue then Exit;
FDefaultOutputPath:=AValue;
end;
procedure TPas2jsFilesCache.SetMainJSFile(AValue: string); procedure TPas2jsFilesCache.SetMainJSFile(AValue: string);
begin begin
if FMainJSFile=AValue then Exit; if FMainJSFile=AValue then Exit;
@ -1904,21 +1914,31 @@ begin
FMainJSFileResolved:='' FMainJSFileResolved:=''
else begin else begin
FMainJSFileResolved:=MainJSFile; FMainJSFileResolved:=MainJSFile;
if FMainJSFileResolved='' then if FMainJSFileResolved<>'' then
begin begin
// no option -o // has option -o
if UnitOutputPath<>'' then if ExtractFilePath(FMainJSFileResolved)='' then
begin begin
// option -FU and no -o => put into UnitOutputPath // -o<FileWithoutPath>
FMainJSFileResolved:=UnitOutputPath+ChangeFileExt(ExtractFilename(MainSrcFile),'.js') if MainOutputPath<>'' then
end else begin FMainJSFileResolved:=MainOutputPath+FMainJSFileResolved
// no -FU and no -o => put into source directory else if UnitOutputPath<>'' then
FMainJSFileResolved:=ChangeFileExt(MainSrcFile,'.js'); FMainJSFileResolved:=UnitOutputPath+FMainJSFileResolved;
end; end;
end else begin end else begin
// has option -o // no option -o
if (ExtractFilePath(FMainJSFileResolved)='') and (UnitOutputPath<>'') then FMainJSFileResolved:=ChangeFileExt(MainSrcFile,'.js');
FMainJSFileResolved:=UnitOutputPath+FMainJSFileResolved; if MainOutputPath<>'' then
begin
// option -FE and no -o => put into MainOutputPath
FMainJSFileResolved:=MainOutputPath+ExtractFilename(FMainJSFileResolved)
end else if UnitOutputPath<>'' then
begin
// option -FU and no -o => put into UnitOutputPath
FMainJSFileResolved:=UnitOutputPath+ExtractFilename(FMainJSFileResolved)
end else begin
// no -FU and no -o => put into source directory
end;
end; end;
end; end;
Include(FStates,cfsMainJSFileResolved); Include(FStates,cfsMainJSFileResolved);

View File

@ -139,6 +139,7 @@ Put + after a boolean switch option to enable it, - to disable it
R : Object checks. Verify method calls and object type casts. R : Object checks. Verify method calls and object type casts.
-F... Set file names and paths: -F... Set file names and paths:
-Fe&lt;x&gt; : Redirect output to file &lt;x&gt;. UTF-8 encoded. -Fe&lt;x&gt; : Redirect output to file &lt;x&gt;. UTF-8 encoded.
-FE&lt;x&gt; : Set main output path to &lt;x&gt;
-Fi&lt;x&gt; : Add &lt;x&gt; to include paths -Fi&lt;x&gt; : Add &lt;x&gt; to include paths
-FN&lt;x&gt; : add &lt;x&gt; to namespaces. Namespaces with trailing - are removed. -FN&lt;x&gt; : add &lt;x&gt; to namespaces. Namespaces with trailing - are removed.
Delphi calls this flag "unit scope names". Delphi calls this flag "unit scope names".