View Issue Details

IDProjectCategoryView StatusLast Update
0035240LazarusPatchpublic2019-09-16 11:13
ReporterPascal RiekenbergAssigned ToJuha Manninen 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSWindows 10 x64OS Version1803
Product Version2.1 (SVN)Product Build60707 
Target VersionFixed in Version 
Summary0035240: IDE: DoCallBuildingFinishedHandler is called with ToolState itBuilder
DescriptionDoCallBuildingFinishedHandler is called with ToolState itBuilder.
Therefore i can not save restored project/package LazCompilerOptions inside handler.

I need this for LazProfiler to restore original options right after building instrumented executable.
Additional InformationMaybe ToolStatus can be reset before BuildingFinishedHandlers are called.
Ohterwise it can be restored temporary as shown in the attached patch.
TagsNo tags attached.
Fixed in Revisionr60719
LazTarget-
WidgetsetWin32/Win64
Attached Files
  • main.pp.patch (944 bytes)
    Index: ide/main.pp
    ===================================================================
    --- ide/main.pp	(revision 60674)
    +++ ide/main.pp	(working copy)
    @@ -6929,7 +6929,15 @@
                                     aCompileHint);
             if ConsoleVerbosity>=0 then
               debugln(['Hint: (lazarus) [TMainIDE.DoBuildProject] compiler time in s: ',(Now-StartTime)*86400]);
    -        DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk);
    +        try
    +          if OldToolStatus = itDebugger then
    +            ToolStatus := OldToolStatus
    +          else
    +            ToolStatus := itNone;
    +          DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk);
    +        finally
    +          ToolStatus := itBuilder;
    +        end;
             if Result<>mrOk then begin
               // save state, so that next time the project is not compiled clean
               Project1.LastCompilerFilename:=CompilerFilename;
    
    main.pp.patch (944 bytes)
  • main2.pp.patch (839 bytes)
    Index: ide/main.pp
    ===================================================================
    --- ide/main.pp	(revision 60674)
    +++ ide/main.pp	(working copy)
    @@ -6929,7 +6929,6 @@
                                     aCompileHint);
             if ConsoleVerbosity>=0 then
               debugln(['Hint: (lazarus) [TMainIDE.DoBuildProject] compiler time in s: ',(Now-StartTime)*86400]);
    -        DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk);
             if Result<>mrOk then begin
               // save state, so that next time the project is not compiled clean
               Project1.LastCompilerFilename:=CompilerFilename;
    @@ -6977,6 +6976,7 @@
           end
           else
             ToolStatus:=itNone;
    +      DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk);
         end;
       finally
         // check sources
    
    main2.pp.patch (839 bytes)

Activities

Pascal Riekenberg

2019-03-17 08:17

reporter  

main.pp.patch (944 bytes)
Index: ide/main.pp
===================================================================
--- ide/main.pp	(revision 60674)
+++ ide/main.pp	(working copy)
@@ -6929,7 +6929,15 @@
                                 aCompileHint);
         if ConsoleVerbosity>=0 then
           debugln(['Hint: (lazarus) [TMainIDE.DoBuildProject] compiler time in s: ',(Now-StartTime)*86400]);
-        DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk);
+        try
+          if OldToolStatus = itDebugger then
+            ToolStatus := OldToolStatus
+          else
+            ToolStatus := itNone;
+          DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk);
+        finally
+          ToolStatus := itBuilder;
+        end;
         if Result<>mrOk then begin
           // save state, so that next time the project is not compiled clean
           Project1.LastCompilerFilename:=CompilerFilename;
main.pp.patch (944 bytes)

Juha Manninen

2019-03-17 11:09

developer   ~0114894

> DoCallBuildingFinishedHandler is called with ToolState itBuilder.

No, ToolState is not used for DoCallBuildingFinishedHandler.

> Therefore i can not save restored project/package LazCompilerOptions inside handler.

What prevents it?

The code in TMainIDE.DoBuildProject() regarding ToolStatus is quite a hack.
ToolStatus is already set in many places and your patch would make it worse. There must be a cleaner way.

Pascal Riekenberg

2019-03-18 06:42

reporter   ~0114905

>> DoCallBuildingFinishedHandler is called with ToolState itBuilder.
>
>No, ToolState is not used for DoCallBuildingFinishedHandler.

That's not right. During calling the BuildingFinished handlers (in TMainIDE.DoBuildProject)
it is set to itBuilder and is reset to itDebugger or itNone before leaving TMainIDE.DoBuildProject.


>> Therefore i can not save restored project/package LazCompilerOptions inside handler.
>
>What prevents it?

SaveProject (SourceFileManager) and TPkgManager.DoSavePackage (PkgManager) check ToolStatus and exit immediately when set to other than itNone or itDebugger.

So i am not able to save the restored modifications back to disk.

>The code in TMainIDE.DoBuildProject() regarding ToolStatus is quite a hack.
>ToolStatus is already set in many places and your patch would make it worse. There must be a cleaner way.

The cleaner way would be to reset the ToolStatus right before calling
DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk).

But as i don't know the code between DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk) and the resetting of ToolStatus in the finally part, i did set it to the state it was before the call to DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk).

Maybe Mattias can have a look if it would be save to resert ToolStatus right before calling DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk).

Juha Manninen

2019-03-18 07:14

developer   ~0114906

> SaveProject (SourceFileManager) and TPkgManager.DoSavePackage (PkgManager) check
> ToolStatus and exit immediately when set to other than itNone or itDebugger.

Ah, OK.
A clean way would also be to move DoCallBuildingFinishedHandler call further down. I will look at this later...

Pascal Riekenberg

2019-03-18 08:30

reporter   ~0114907

>A clean way would also be to move DoCallBuildingFinishedHandler call further down. I will look at this later...

Yes, of course!

Pascal Riekenberg

2019-03-18 09:42

reporter  

main2.pp.patch (839 bytes)
Index: ide/main.pp
===================================================================
--- ide/main.pp	(revision 60674)
+++ ide/main.pp	(working copy)
@@ -6929,7 +6929,6 @@
                                 aCompileHint);
         if ConsoleVerbosity>=0 then
           debugln(['Hint: (lazarus) [TMainIDE.DoBuildProject] compiler time in s: ',(Now-StartTime)*86400]);
-        DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk);
         if Result<>mrOk then begin
           // save state, so that next time the project is not compiled clean
           Project1.LastCompilerFilename:=CompilerFilename;
@@ -6977,6 +6976,7 @@
       end
       else
         ToolStatus:=itNone;
+      DoCallBuildingFinishedHandler(lihtProjectBuildingFinished, Self, Result=mrOk);
     end;
   finally
     // check sources
main2.pp.patch (839 bytes)

Pascal Riekenberg

2019-03-18 09:43

reporter   ~0114908

See 2nd patch.
Moved DoCallBuildingFinishedHandler down to finally section after restoring ToolStatus.

Juha Manninen

2019-03-19 00:09

developer   ~0114915

Applied, thanks.
I made the same change for building Lazarus itself.

Pascal Riekenberg

2019-09-13 14:57

reporter   ~0118061

@juha: Could you merge this to the fixes_2_0 branch, please?

Juha Manninen

2019-09-13 22:54

developer   ~0118068

I added r60719 to the list for merging:
https://wiki.freepascal.org/Lazarus_2.0_fixes_branch#Submitted_by_developer_.2F_committer.2C_tested.2C_waiting_to_be_merged
It will be in version 2.0.6.

Pascal Riekenberg

2019-09-16 11:13

reporter   ~0118091

Thanks.

Issue History

Date Modified Username Field Change
2019-03-17 08:17 Pascal Riekenberg New Issue
2019-03-17 08:17 Pascal Riekenberg File Added: main.pp.patch
2019-03-17 11:09 Juha Manninen LazTarget => -
2019-03-17 11:09 Juha Manninen Note Added: 0114894
2019-03-17 11:09 Juha Manninen Assigned To => Juha Manninen
2019-03-17 11:09 Juha Manninen Status new => feedback
2019-03-18 06:42 Pascal Riekenberg Note Added: 0114905
2019-03-18 06:42 Pascal Riekenberg Status feedback => assigned
2019-03-18 07:14 Juha Manninen Note Added: 0114906
2019-03-18 08:30 Pascal Riekenberg Note Added: 0114907
2019-03-18 09:42 Pascal Riekenberg File Added: main2.pp.patch
2019-03-18 09:43 Pascal Riekenberg Note Added: 0114908
2019-03-19 00:09 Juha Manninen Fixed in Revision => r60719
2019-03-19 00:09 Juha Manninen Note Added: 0114915
2019-03-19 00:09 Juha Manninen Status assigned => resolved
2019-03-19 00:09 Juha Manninen Resolution open => fixed
2019-03-19 06:42 Pascal Riekenberg Status resolved => closed
2019-09-13 14:57 Pascal Riekenberg Status closed => assigned
2019-09-13 14:57 Pascal Riekenberg Resolution fixed => reopened
2019-09-13 14:57 Pascal Riekenberg Note Added: 0118061
2019-09-13 22:54 Juha Manninen Status assigned => resolved
2019-09-13 22:54 Juha Manninen Widgetset Win32/Win64 => Win32/Win64
2019-09-13 22:54 Juha Manninen Note Added: 0118068
2019-09-13 22:55 Juha Manninen Resolution reopened => fixed
2019-09-13 22:55 Juha Manninen Widgetset Win32/Win64 => Win32/Win64
2019-09-16 11:13 Pascal Riekenberg Status resolved => closed
2019-09-16 11:13 Pascal Riekenberg Note Added: 0118091