Menu

#658 Switching project does not change target

Undefined
open
nobody
Compiler (40)
Undefined
2018-04-11
2018-04-07
bluehazzard
No

If i open two projects and both have the same target names, if i switch project the target is not switched to the last used in this project.

For example:
Project1 with targets:
Debug
Release

Project2 with targets:
Debug
Release

1) Load both projects in codeblocks.
2) Activate Project1
3) Select target "Release"
4) Activate Project2
5) Select target "Debug"
6) Activate Project1 --> Target stays at "Debug" but should switch to "Release" because this was the last active target for this project.

I have not investigated what happens if two projects do not have the same target names.

At the moment i have no time to investigate if this is a bug, or codeblocks does not save the last active target at project level. I made a quick search in the tickets and could not find a ticket matching. Anyway this is really annoying...

Discussion

  • bluehazzard

    bluehazzard - 2018-04-08

    I am still not quite sure what is happening here...

    What i have found:
    1) The compiler plugin manages the target toolbar
    2) The compiler plugin does NOT react to the cbEVT_BUILDTARGET_SELECTED event
    3) The current target is selected with the cbProject::SetActiveBuildTarget function. This function generates the cbEVT_BUILDTARGET_SELECTED event.
    4) The current target is stored in the Project class in cbProject::m_ActiveTarget
    5) On prject activation the target is not read and set
    6) On project load the target is read from the layout file and activated
    7) The Target is not applied correctly from the layout file

    Point 7) is essential for me. I think there are two problems:
    1) BUG: The compiler plugin does not handle the cbEVT_BUILDTARGET_SELECTED event, and for this can not update the UI accordingly. ?? If i hit build, always the UI value is used?? This is probably a other bug, because the Active target should be used instead...
    2) BUG: CompilerGCC::DoRecreateTargetMenu() does not handle the cbProject::m_ActiveTarget from the current project correctly, because it is a fall back for cbWorkspace::GetPreferredTarget() if the build target is not valid. But if two projects have the same target the name from GetPreferredTarget from the old project is valid and for this used. This is the wrong behaviour. By default the active target of the project should be used....

    code: plugins\compilergcc\compilergcc.cpp:1422

    if (cbWorkspace* wsp = Manager::Get()->GetProjectManager()->GetWorkspace())
            {
              const wxString preferredTarget = wsp->GetPreferredTarget();
              tgtStr = preferredTarget;
              if ( !IsValidTarget(tgtStr) )
                  tgtStr = m_pProject->GetActiveBuildTarget();
              if ( !IsValidTarget(tgtStr) )
                  tgtStr = m_pProject->GetFirstValidBuildTargetName(); // last-chance default
              if ( preferredTarget.IsEmpty() )
                  wsp->SetPreferredTarget(tgtStr);
            }
    

    Why is cbWorkspace::GetPreferredTarget() even used? We know the target to use: m_pProject->GetActiveBuildTarget(). Why guess it from a workspace level?

     

    Last edit: bluehazzard 2018-04-08
  • bluehazzard

    bluehazzard - 2018-04-08

    Ok, i changed two lines and everything works as expected (loading from layout file and activating project)

    diff --git a/src/plugins/compilergcc/compilergcc.cpp b/src/plugins/compilergcc/compilergcc.cpp
    index 86a8a6279..36ff899a8 100644
    --- a/src/plugins/compilergcc/compilergcc.cpp
    +++ b/src/plugins/compilergcc/compilergcc.cpp
    @@ -1421,10 +1421,10 @@ void CompilerGCC::DoRecreateTargetMenu()
             // find out the should-be-selected target
             if (cbWorkspace* wsp = Manager::Get()->GetProjectManager()->GetWorkspace())
             {
    -          const wxString preferredTarget = wsp->GetPreferredTarget();
    +          const wxString preferredTarget = m_pProject->GetActiveBuildTarget();
               tgtStr = preferredTarget;
               if ( !IsValidTarget(tgtStr) )
    -              tgtStr = m_pProject->GetActiveBuildTarget();
    +              tgtStr = wsp->GetPreferredTarget();
               if ( !IsValidTarget(tgtStr) )
                   tgtStr = m_pProject->GetFirstValidBuildTargetName(); // last-chance default
               if ( preferredTarget.IsEmpty() )
    
     
  • Teodor Petrov

    Teodor Petrov - 2018-04-10

    For me the expected behaviour would be to keep the same target in both projects.
    If I am at Project1:Debug, when I switch to Project2 I would want to still be in target Debug if there is such target. So if I'm debugging after the switch I still want to debug the newly selected project.
    Everything else would be confusing for me.

    If the workspace contains projects with non-matching targets then I guess the preferred target could be used.

    Why do you want to switch targets automatically? Do you store projects that aren't related to each other?

     
  • Teodor Petrov

    Teodor Petrov - 2018-04-10
    • labels: --> Compiler
     
  • bluehazzard

    bluehazzard - 2018-04-11

    somehow related...
    Project1 is a embedded device
    Project2 is the software on the pc that communicates with the device...

    both projects have obviously debug and release targets. But i won't use the debug target for embedded device by default because this needs more flash and the flashing time is longer (factor 2)...
    So if i debug the pc application, find a bug in the embedded code, correct it and switch projects to flash the device i always use the wrong target by default. This is really annoying...

    Would a setting be acceptable?

     
  • Teodor Petrov

    Teodor Petrov - 2018-04-11

    Not sure. Too many settings...
    And we don't have workspace settings, but this is the places where it should go, so it is quite a lot of work for something that is of limitted use.

    Probably you could rename your targets to make them different (as a workaround).

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.