Browse Source

pastojs: write encoding, compiler date and src platform

git-svn-id: trunk@38985 -
Mattias Gaertner 7 years ago
parent
commit
6d10ef21c6
2 changed files with 54 additions and 8 deletions
  1. 30 5
      packages/pastojs/src/pas2jscompiler.pp
  2. 24 3
      packages/pastojs/src/pas2jslogger.pp

+ 30 - 5
packages/pastojs/src/pas2jscompiler.pp

@@ -64,7 +64,7 @@ const
   nParsingFile = 126; sParsingFile = 'Parsing %s ...';
   nParsingFile = 126; sParsingFile = 'Parsing %s ...';
   nCompilingFile = 127; sCompilingFile = 'Compiling %s ...';
   nCompilingFile = 127; sCompilingFile = 'Compiling %s ...';
   nExpectedButFound = 128; sExpectedButFound = 'Illegal unit name: Expected "%s", but found "%s"';
   nExpectedButFound = 128; sExpectedButFound = 'Illegal unit name: Expected "%s", but found "%s"';
-  nLinesInFilesCompiled = 129; sLinesInFilesCompiled = '%s lines in %s files compiled, %s sec';
+  nLinesInFilesCompiled = 129; sLinesInFilesCompiled = '%s lines in %s files compiled, %s sec%s';
   nTargetPlatformIs = 130; sTargetPlatformIs = 'Target platform is %s';
   nTargetPlatformIs = 130; sTargetPlatformIs = 'Target platform is %s';
   nTargetProcessorIs = 131; sTargetProcessorIs = 'Target processor is %s';
   nTargetProcessorIs = 131; sTargetProcessorIs = 'Target processor is %s';
   nMessageEncodingIs = 132; sMessageEncodingIs = 'Message encoding is %s';
   nMessageEncodingIs = 132; sMessageEncodingIs = 'Message encoding is %s';
@@ -363,6 +363,7 @@ type
     FFileCacheAutoFree: boolean;
     FFileCacheAutoFree: boolean;
     FFiles: TAVLTree; // tree of TPas2jsCompilerFile sorted for PasFilename
     FFiles: TAVLTree; // tree of TPas2jsCompilerFile sorted for PasFilename
     FReadingModules: TFPList; // list of TPas2jsCompilerFile ordered by uses sections
     FReadingModules: TFPList; // list of TPas2jsCompilerFile ordered by uses sections
+    FHasShownEncoding: boolean;
     FHasShownLogo: boolean;
     FHasShownLogo: boolean;
     FLog: TPas2jsLogger;
     FLog: TPas2jsLogger;
     FMainFile: TPas2jsCompilerFile;
     FMainFile: TPas2jsCompilerFile;
@@ -466,6 +467,7 @@ type
     class function GetVersion(ShortVersion: boolean): string;
     class function GetVersion(ShortVersion: boolean): string;
     procedure WriteHelp;
     procedure WriteHelp;
     procedure WriteLogo;
     procedure WriteLogo;
+    procedure WriteEncoding;
     procedure WriteVersionLine;
     procedure WriteVersionLine;
     procedure WriteOptions;
     procedure WriteOptions;
     procedure WriteDefines;
     procedure WriteDefines;
@@ -1989,7 +1991,7 @@ begin
       Seconds:=(Now-StartTime)*86400;
       Seconds:=(Now-StartTime)*86400;
       Log.LogMsgIgnoreFilter(nLinesInFilesCompiled,
       Log.LogMsgIgnoreFilter(nLinesInFilesCompiled,
              [IntToStr(FileCache.ReadLineCounter),IntToStr(SrcFileCount),
              [IntToStr(FileCache.ReadLineCounter),IntToStr(SrcFileCount),
-              FormatFloat('0.0',Seconds)]);
+              FormatFloat('0.0',Seconds),'s']);
       ok:=true;
       ok:=true;
     end;
     end;
   finally
   finally
@@ -3170,7 +3172,14 @@ begin
             begin
             begin
             Identifier:=NormalizeEncoding(String(p));
             Identifier:=NormalizeEncoding(String(p));
             case Identifier of
             case Identifier of
-            'console','system','utf8', 'json': Log.Encoding:=Identifier;
+            'console','system','utf8', 'json':
+              if Log.Encoding<>Identifier then begin
+                Log.Encoding:=Identifier;
+                if FHasShownEncoding then begin
+                  FHasShownEncoding:=false;
+                  WriteEncoding;
+                end;
+              end;
             else ParamFatal('invalid encoding (-Je) "'+String(p)+'"');
             else ParamFatal('invalid encoding (-Je) "'+String(p)+'"');
             end;
             end;
             end;
             end;
@@ -3814,6 +3823,7 @@ begin
   AddDefine('UNICODE');
   AddDefine('UNICODE');
 
 
   FHasShownLogo:=false;
   FHasShownLogo:=false;
+  FHasShownEncoding:=false;
   FFileCache.Reset;
   FFileCache.Reset;
 end;
 end;
 
 
@@ -4071,11 +4081,26 @@ begin
   FHasShownLogo:=true;
   FHasShownLogo:=true;
   WriteVersionLine;
   WriteVersionLine;
   Log.LogPlain('Copyright (c) 2018 Mattias Gaertner and others');
   Log.LogPlain('Copyright (c) 2018 Mattias Gaertner and others');
+  if coShowInfos in Options then
+    WriteEncoding;
+end;
+
+procedure TPas2jsCompiler.WriteEncoding;
+begin
+  if FHasShownEncoding then exit;
+  FHasShownEncoding:=true;
+  Log.LogMsgIgnoreFilter(nMessageEncodingIs,[Log.GetEncodingCaption]);
 end;
 end;
 
 
 procedure TPas2jsCompiler.WriteVersionLine;
 procedure TPas2jsCompiler.WriteVersionLine;
+var
+  s: String;
 begin
 begin
-  Log.LogPlain('Pas2JS Compiler version '+GetVersion(false));
+  s:='Pas2JS Compiler version '+GetVersion(false);
+  s:=s+' ['+{$i %Date%}+'] for '+{$i %FPCTargetOS%}+' '+{$i %FPCTargetCPU%};
+  Log.LogPlain(s);
+  if coShowInfos in Options then
+    WriteEncoding;
 end;
 end;
 
 
 procedure TPas2jsCompiler.WriteOptions;
 procedure TPas2jsCompiler.WriteOptions;
@@ -4084,7 +4109,7 @@ var
   fco: TP2jsFileCacheOption;
   fco: TP2jsFileCacheOption;
 begin
 begin
   // message encoding
   // message encoding
-  Log.LogMsgIgnoreFilter(nMessageEncodingIs,[BoolToStr(Log.Encoding<>'',Log.Encoding,'system')]);
+  WriteEncoding;
   // target platform
   // target platform
   Log.LogMsgIgnoreFilter(nTargetPlatformIs,[PasToJsPlatformNames[TargetPlatform]]);
   Log.LogMsgIgnoreFilter(nTargetPlatformIs,[PasToJsPlatformNames[TargetPlatform]]);
   Log.LogMsgIgnoreFilter(nTargetProcessorIs,[PasToJsProcessorNames[TargetProcessor]]);
   Log.LogMsgIgnoreFilter(nTargetProcessorIs,[PasToJsProcessorNames[TargetProcessor]]);

+ 24 - 3
packages/pastojs/src/pas2jslogger.pp

@@ -120,6 +120,7 @@ type
     procedure OpenDebugLog;
     procedure OpenDebugLog;
     procedure CloseDebugLog;
     procedure CloseDebugLog;
     procedure DebugLogWriteLn(Msg: string); overload;
     procedure DebugLogWriteLn(Msg: string); overload;
+    function GetEncodingCaption: string;
   public
   public
     property Encoding: string read FEncoding write SetEncoding; // normalized
     property Encoding: string read FEncoding write SetEncoding; // normalized
     property MsgCount: integer read GetMsgCount;
     property MsgCount: integer read GetMsgCount;
@@ -717,17 +718,37 @@ begin
   FDebugLog.Write(Msg[1],length(Msg));
   FDebugLog.Write(Msg[1],length(Msg));
 end;
 end;
 
 
+function TPas2jsLogger.GetEncodingCaption: string;
+begin
+  Result:=Encoding;
+  if Result='' then
+  begin
+    if FOutputFile=nil then
+      Result:='console'
+    else
+      Result:='utf-8';
+  end;
+  if Result='console' then
+  begin
+    {$IFDEF Unix}
+    if not IsNonUTF8System then
+      Result:='utf-8';
+    {$ENDIF}
+  end;
+  if Result='utf8' then
+    Result:='utf-8';
+end;
+
 procedure TPas2jsLogger.LogPlain(const Msg: string);
 procedure TPas2jsLogger.LogPlain(const Msg: string);
 var
 var
   s: String;
   s: String;
 begin
 begin
   ClearLastMsg;
   ClearLastMsg;
   if Encoding='json' then
   if Encoding='json' then
-    begin
+  begin
     s:=FormatJSONMsg(mtInfo,Msg,0,'',0,0);
     s:=FormatJSONMsg(mtInfo,Msg,0,'',0,0);
     DoLogRaw(s,True);
     DoLogRaw(s,True);
-    end
-  else
+  end else
     DoLogRaw(Msg,False);
     DoLogRaw(Msg,False);
 end;
 end;