Author Topic: cbEVT_COMPILER_FINISHED  (Read 11725 times)

Offline Picardo

  • Single posting newcomer
  • *
  • Posts: 6
cbEVT_COMPILER_FINISHED
« on: October 27, 2017, 04:08:24 pm »
Good day,

Is there a better way to determine when a user requested a build than using a cbEVT_COMPILER_FINISHED event? I use this event to trigger execution of other code and it works well but when a user selects Build and Run, the cbEVT_COMPILER_FINISHED fires twice. This causes the other code to run twice, which is not what I want. 

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: cbEVT_COMPILER_FINISHED
« Reply #1 on: October 27, 2017, 06:54:27 pm »
Can you describe what you want to achieve in more details?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Picardo

  • Single posting newcomer
  • *
  • Posts: 6
Re: cbEVT_COMPILER_FINISHED
« Reply #2 on: October 30, 2017, 08:21:32 am »
Hi oBFusCATed, thanks for your reply. 

I want to save a copy of the source code and build log of student programmers as it is at compile time. The (secretly) saved copies will then be analysed to determine what the students are struggling with.

The plugin as it is works well except that it saves two copies of the same info if the Build and Run command is used. I have thought of checking the time between compiles to determine if the save function should run or not but it feels a bit like a workaround. Any suggestions?


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: cbEVT_COMPILER_FINISHED
« Reply #3 on: October 30, 2017, 08:43:38 am »
I've done some debugging and it seems the second event is sent when the run application is closed. So an event is sent even when only running an application. This is definitely a bug, but I'm not sure how hard it would be to fix it.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: cbEVT_COMPILER_FINISHED
« Reply #4 on: October 30, 2017, 08:52:13 am »
Can you try this patch and let me know if there are some strange behaviours:

Code
diff --git a/src/plugins/compilergcc/compilergcc.cpp b/src/plugins/compilergcc/compilergcc.cpp
index 73705184d..0d13c96fa 100644
--- a/src/plugins/compilergcc/compilergcc.cpp
+++ b/src/plugins/compilergcc/compilergcc.cpp
@@ -3931,10 +3931,12 @@ void CompilerGCC::NotifyJobDone(bool showNothingToBeDone)
         ProjectManager *manager = Manager::Get()->GetProjectManager();
         if (manager->GetIsRunning() == this)
             manager->SetIsRunning(NULL);
-
-        CodeBlocksEvent evt(cbEVT_COMPILER_FINISHED, 0, m_pProject, 0, this);
-        evt.SetInt(m_LastExitCode);
-        Manager::Get()->ProcessEvent(evt);
+        else
+        {
+            CodeBlocksEvent evt(cbEVT_COMPILER_FINISHED, 0, m_pProject, 0, this);
+            evt.SetInt(m_LastExitCode);
+            Manager::Get()->ProcessEvent(evt);
+        }
         m_LastExitCode = 0;
     }
 }
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Picardo

  • Single posting newcomer
  • *
  • Posts: 6
Re: cbEVT_COMPILER_FINISHED
« Reply #5 on: October 30, 2017, 01:42:07 pm »
Hi oBFusCATed, thanks for your help.

I modified the code as you suggested and rebuilt Code Blocks but it does not seem to have made a difference.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: cbEVT_COMPILER_FINISHED
« Reply #6 on: October 30, 2017, 08:35:36 pm »
What os are you using? How have you build the source? If it is from inside cb have you run the appropriate update script?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Picardo

  • Single posting newcomer
  • *
  • Posts: 6
Re: cbEVT_COMPILER_FINISHED
« Reply #7 on: October 31, 2017, 08:13:05 am »
I'm pretty green with building C::B from source and writing plug-ins so chances are that I missed something. Please bear with me!

- OS is Windows 10
- I manually changed the compilergcc.cpp file as per your git instructions.
- I compiled the C::B sources project from an installed C::B 16.01. I believe the changes were part of the compile as I got a compile error because of finger trouble the first time.
- I ran update.bat
- I opened the compiled C::B which complained about a few missing .dll files. Copied those over from the installed C::B.
- Opened C::B again, no missing .dll files.
- Installed the plug-in and tested.


What os are you using? How have you build the source? If it is from inside cb have you run the appropriate update script?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: cbEVT_COMPILER_FINISHED
« Reply #8 on: October 31, 2017, 08:31:20 am »
I have no idea if this is the only problem in the 16.01 build. I'm testing with latest trunk/master. For me the event is fired only once now. Testing on linux, but this shouldn't make any difference.

Can you use a debugger and give me a call stack when the event is fired?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Re: cbEVT_COMPILER_FINISHED
« Reply #9 on: October 31, 2017, 10:09:46 am »
I'm pretty green with building C::B from source and writing plug-ins so chances are that I missed something. Please bear with me!

- OS is Windows 10
- I manually changed the compilergcc.cpp file as per your git instructions.
- I compiled the C::B sources project from an installed C::B 16.01. I believe the changes were part of the compile as I got a compile error because of finger trouble the first time.
- I ran update.bat
- I opened the compiled C::B which complained about a few missing .dll files. Copied those over from the installed C::B.
- Opened C::B again, no missing .dll files.
- Installed the plug-in and tested.


What os are you using? How have you build the source? If it is from inside cb have you run the appropriate update script?
Mixing dll's from installed and compiled C::B might be the culprit.

If the self-compiled C::B does not work after running update.bat, something went wrong.
Did you run the version from the "devel" or the "output" folder ?

Offline Picardo

  • Single posting newcomer
  • *
  • Posts: 6
Re: cbEVT_COMPILER_FINISHED
« Reply #10 on: October 31, 2017, 10:21:35 am »
Hi Jens, I ran the .exe from the devel folder. Yes, I am a dumba**!  :D
I just tried again from the output folder (here the date modified of the .dlls are the same as the codeblocks.exe) but I still have the same problem.


oBFusCATed, can you point me in the right direction on how to capture the call stack when the event is fired please?

Offline Picardo

  • Single posting newcomer
  • *
  • Posts: 6
Re: cbEVT_COMPILER_FINISHED
« Reply #11 on: October 31, 2017, 11:20:13 am »
oBFusCATed, my bad. The last version of my plugin used the COMPILER_STARTED event in an effort to solve the double running of the plugin code. The COMPILER_STARTED event still fires twice though... I changed it back to the COMPILER_FINISHED event and now it works perfectly.

Sorry for wasting your time! Thanks for your help.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: cbEVT_COMPILER_FINISHED
« Reply #12 on: January 20, 2018, 02:10:54 am »
Back to this problem. It seems the COMPILER_STARTED is sent at the start of every distinct operation.

For example if you do a "build project" then you get one event. If you do "clean project" get one event. Same for clean and build file and workspace. But if you do rebuild then you get one event for the clean part and one event for the build part of the rebuild process.

I'm not sure if this is done on purpose or if this is accidental.
I'll commit the fix for the compiler finished event though. If this double send of the compiler started is bothering you we could try to think something about it.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]