Browse Source

Show preprocessor output also if compiling failed but preprocessing succeeded.
Also ISCompileScript cleanup.

Martijn Laan 5 years ago
parent
commit
15583c291c
4 changed files with 93 additions and 71 deletions
  1. 9 8
      Projects/CompForm.pas
  2. 4 4
      Projects/CompInt.pas
  3. 79 58
      Projects/Compile.pas
  4. 1 1
      Projects/ISCmplr.dpr

+ 9 - 8
Projects/CompForm.pas

@@ -1378,8 +1378,9 @@ begin
           if Form.FCompileWantAbort then
             Result := iscrRequestAbort;
         end;
-      iscbNotifyIncludedFiles:
+      iscbNotifyPreproc:
         begin
+          PreprocessedScript := Data.PreprocessedScript;
           DecodeIncludedFilenames(Data.IncludedFilenames, Form.FIncludedFiles); { Also stores last write time }
           Form.SaveKnownIncludedFiles(Filename);
         end;
@@ -1578,13 +1579,6 @@ begin
     StatusMessage(smkStartEnd, Format(SCompilerStatusFinished, [TimeToStr(Time),
       Format('%.2u%s%.2u%s%.3u', [ElapsedSeconds div 60, {$IFDEF IS_DXE}FormatSettings.{$ENDIF}TimeSeparator,
         ElapsedSeconds mod 60, {$IFDEF IS_DXE}FormatSettings.{$ENDIF}DecimalSeparator, ElapsedTime mod 1000])]));
-    FPreprocessorMemo.ReadOnly := False;
-    try
-      FPreprocessorMemo.Lines.Text := AppData.PreprocessedScript;
-      FPreprocessorMemo.ClearUndo;
-    finally
-      FPreprocessorMemo.ReadOnly := True;
-    end;
   finally
     AppData.Lines.Free;
     FCompiling := False;
@@ -1598,6 +1592,13 @@ begin
     UpdateEditModePanel;
     UpdateRunMenu;
     UpdateCaption;
+    FPreprocessorMemo.ReadOnly := False;
+    try
+      FPreprocessorMemo.Lines.Text := AppData.PreprocessedScript;
+      FPreprocessorMemo.ClearUndo;
+    finally
+      FPreprocessorMemo.ReadOnly := True;
+    end;
     UpdateIncludedFilesMemos;
     if AppData.DebugInfo <> nil then begin
       ParseDebugInfo(AppData.DebugInfo); { Must be called after UpdateIncludedFilesMemos }

+ 4 - 4
Projects/CompInt.pas

@@ -22,7 +22,7 @@ const
   iscbNotifySuccess = 4;   { Sent when compilation succeeds }
   iscbNotifyError = 5;     { Sent when compilation fails or is aborted by the
                              application }
-  iscbNotifyIncludedFiles = 6; { Sent to notify the application of included files }
+  iscbNotifyPreproc = 6;   { Sent to notify the application of preprocessor results }
 
   { Return values for callback function }
   iscrSuccess = 0;         { Return this for compiler to continue }
@@ -74,7 +74,8 @@ type
         BytesCompressedPerSecond: Cardinal); { [in] Average bytes compressed
                                                per second (new in 5.1.13) }
 
-      iscbNotifyIncludedFiles: (
+      iscbNotifyPreproc: (
+        PreprocessedScript: PChar; { [in] Preprocessed script (new in 6.1.0) }
         IncludedFilenames: PChar); { [in] Names of #included files. Each name is
                                           a null-terminated string, and the final
                                           name is followed by an additional null
@@ -85,8 +86,7 @@ type
                                           or empty if output was disabled
                                           (latter new in 5.5.5) }
         DebugInfo: Pointer;        { [in] Debug info (new in 3.0.0.1) }
-        DebugInfoSize: Cardinal;   { [in] Size of debug info (new in 3.0.0.1) }
-        PreprocessedScript: PChar);{ [in] Preprocessed script (new in 6.1.0) }
+        DebugInfoSize: Cardinal);  { [in] Size of debug info (new in 3.0.0.1) }
 
       iscbNotifyError: (
         ErrorMsg: PChar;      { [in] The error message, or NULL if compilation

+ 79 - 58
Projects/Compile.pas

@@ -9167,47 +9167,86 @@ begin
   end;
 end;
 
-{ Interface helper functions }
+{ Interface functions }
 
-function CheckParams(const Params: TCompileScriptParamsEx): Boolean;
-begin
-  Result := ((Params.Size = SizeOf(Params)) or
-             (Params.Size = SizeOf(TCompileScriptParams))) and
-            Assigned(Params.CallbackProc);
-end;
+function ISCompileScript(const Params: TCompileScriptParamsEx;
+  const PropagateExceptions: Boolean): Integer;
 
-procedure InitializeSetupCompiler(const SetupCompiler: TSetupCompiler;
-  const Params: TCompileScriptParamsEx);
-begin
-  SetupCompiler.AppData := Params.AppData;
-  SetupCompiler.CallbackProc := Params.CallbackProc;
-  if Assigned(Params.CompilerPath) then
-    SetupCompiler.CompilerDir := Params.CompilerPath
-  else
-    SetupCompiler.CompilerDir := PathExtractPath(GetSelfFilename);
-  SetupCompiler.SourceDir := Params.SourcePath;
-end;
+  function CheckParams(const Params: TCompileScriptParamsEx): Boolean;
+  begin
+    Result := ((Params.Size = SizeOf(Params)) or
+               (Params.Size = SizeOf(TCompileScriptParams))) and
+              Assigned(Params.CallbackProc);
+  end;
 
-function EncodeIncludedFilenames(const IncludedFilenames: TStringList): String;
-var
-  S: String;
-  I: Integer;
-begin
-  S := '';
-  for I := 0 to IncludedFilenames.Count-1 do
-   S := S + IncludedFilenames[I] + #0;
-  Result := S;
-end;
+  procedure InitializeSetupCompiler(const SetupCompiler: TSetupCompiler;
+    const Params: TCompileScriptParamsEx);
+  begin
+    SetupCompiler.AppData := Params.AppData;
+    SetupCompiler.CallbackProc := Params.CallbackProc;
+    if Assigned(Params.CompilerPath) then
+      SetupCompiler.CompilerDir := Params.CompilerPath
+    else
+      SetupCompiler.CompilerDir := PathExtractPath(GetSelfFilename);
+    SetupCompiler.SourceDir := Params.SourcePath;
+  end;
 
-{ Interface functions }
+  function EncodeIncludedFilenames(const IncludedFilenames: TStringList): String;
+  var
+    S: String;
+    I: Integer;
+  begin
+    S := '';
+    for I := 0 to IncludedFilenames.Count-1 do
+     S := S + IncludedFilenames[I] + #0;
+    Result := S;
+  end;
+
+  procedure NotifyPreproc(const SetupCompiler: TSetupCompiler);
+  var
+    Data: TCompilerCallbackData;
+    S: String;
+  begin
+    Data.PreprocessedScript := PChar(SetupCompiler.PreprocOutput);
+    S := EncodeIncludedFilenames(SetupCompiler.PreprocIncludedFilenames);
+    Data.IncludedFilenames := PChar(S);
+    Params.CallbackProc(iscbNotifyPreproc, Data, Params.AppData);
+  end;
+
+  procedure NotifySuccess(const SetupCompiler: TSetupCompiler);
+  var
+    Data: TCompilerCallbackData;
+  begin
+    Data.OutputExeFilename := PChar(SetupCompiler.ExeFilename);
+    Data.DebugInfo := SetupCompiler.DebugInfo.Memory;
+    Data.DebugInfoSize := SetupCompiler.DebugInfo.Size;
+    Data.PreprocessedScript := PChar(SetupCompiler.PreprocOutput);
+    Params.CallbackProc(iscbNotifySuccess, Data, Params.AppData);
+  end;
+
+  procedure NotifyError(const SetupCompiler: TSetupCompiler);
+  var
+    Data: TCompilerCallbackData;
+    S: String;
+  begin
+    Data.ErrorMsg := nil;
+    Data.ErrorFilename := nil;
+    Data.ErrorLine := 0;
+    if not(ExceptObject is EAbort) then begin
+      S := GetExceptMessage;
+      Data.ErrorMsg := PChar(S);
+      { use a Pointer cast instead of PChar so that we'll get a null
+        pointer if the string is empty }
+      Data.ErrorFilename := Pointer(SetupCompiler.LineFilename);
+      Data.ErrorLine := SetupCompiler.LineNumber;
+    end;
+    Params.CallbackProc(iscbNotifyError, Data, Params.AppData);
+  end;
 
-function ISCompileScript(const Params: TCompileScriptParamsEx;
-  const PropagateExceptions: Boolean): Integer;
 var
   SetupCompiler: TSetupCompiler;
   P: PChar;
   Data: TCompilerCallbackData;
-  S: String;
   P2: Integer;
 begin
   if not CheckParams(Params) then begin
@@ -9266,38 +9305,20 @@ begin
       end;
     end;
 
-    Result := isceNoError;
     try
-      SetupCompiler.Compile;
+      try
+        SetupCompiler.Compile;
+      finally
+        NotifyPreproc(SetupCompiler);
+      end;
+      Result := isceNoError;
+      NotifySuccess(SetupCompiler);
     except
       Result := isceCompileFailure;
-      S := EncodeIncludedFilenames(SetupCompiler.PreprocIncludedFilenames);
-      Data.IncludedFilenames := PChar(S);
-      Params.CallbackProc(iscbNotifyIncludedFiles, Data, Params.AppData);
-      Data.ErrorMsg := nil;
-      Data.ErrorFilename := nil;
-      Data.ErrorLine := 0;
-      if not(ExceptObject is EAbort) then begin
-        S := GetExceptMessage;
-        Data.ErrorMsg := PChar(S);
-        { use a Pointer cast instead of PChar so that we'll get a null
-          pointer if the string is empty }
-        Data.ErrorFilename := Pointer(SetupCompiler.LineFilename);
-        Data.ErrorLine := SetupCompiler.LineNumber;
-      end;
-      Params.CallbackProc(iscbNotifyError, Data, Params.AppData);
+      NotifyError(SetupCompiler);
       if PropagateExceptions then
         raise;
-      Exit;
     end;
-    S := EncodeIncludedFilenames(SetupCompiler.PreprocIncludedFilenames);
-    Data.IncludedFilenames := PChar(S);
-    Params.CallbackProc(iscbNotifyIncludedFiles, Data, Params.AppData);
-    Data.OutputExeFilename := PChar(SetupCompiler.ExeFilename);
-    Data.DebugInfo := SetupCompiler.DebugInfo.Memory;
-    Data.DebugInfoSize := SetupCompiler.DebugInfo.Size;
-    Data.PreprocessedScript := PChar(SetupCompiler.PreprocOutput);
-    Params.CallbackProc(iscbNotifySuccess, Data, Params.AppData);
   finally
     SetupCompiler.Free;
   end;

+ 1 - 1
Projects/ISCmplr.dpr

@@ -51,7 +51,7 @@ type
     LastLineRead: String;
   end;
 
-{ Does not support iscbNotifyIncludedFiles }
+{ Does not support iscbNotifyPreproc }
 function WrapperCallbackProc(Code: Integer; var Data: TCompilerCallbackData;
   AppData: Longint): Integer;
 stdcall;