Author Topic: Plugin 'compilergcc'  (Read 11404 times)

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Plugin 'compilergcc'
« on: May 20, 2023, 04:00:55 pm »
With the 'compilergcc' plugin in 'int CompilerGCC::Run(ProjectBuildTarget* target)' we find
Code
 Manager::Get()->GetLogManager()->Log(_("Checking for existence: ") + f.GetFullPath(), m_PageIndex);
    if ( (target->GetTargetType() != ttCommandsOnly) && !wxFileExists(f.GetFullPath()) )
    {
        int ret = cbMessageBox(_("It seems that this project has not been built yet.\n"
                                 "Do you want to build it now?"),
                               _("Information"),
                               wxYES_NO | wxCANCEL | wxICON_QUESTION);
        switch (ret)
        {
            case wxID_YES:
            {
                m_pProject->SetCurrentlyCompilingTarget(0);
                m_RunAfterCompile = true;
                Build(target);
                return -1;
            }
            case wxID_NO:
                break;
            default:
                m_pProject->SetCurrentlyCompilingTarget(0);
                return -1;
        }
    }
This verifies that the executable exists, because '&Run' has been activated.

Instead, '&Run' should be invalidated if the executable does not exist. This could be done automatically in
'void CompilerGCC::OnUpdateUI(wxUpdateUIEvent& event)' by :
Code
    ...
    cbProject* prj = projectManager->GetActiveProject();
    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
/// new
    if (id == idMenuRun)
    {
        event.Enable(exeExists(prj));
    }
    else
    ...
with 'exeExists(prj)' which would indicate whether the executable exists for example :
Code
bool CompilerGCC::exeExists(cbProject* prj)
{
    bool valid = false;
    if (prj)
    {
        ProjectBuildTarget* pTarget = prj->GetBuildTarget(prj->GetActiveBuildTarget());
        if (pTarget)
        {
            wxString out = UnixFilename(pTarget->GetOutputFilename());
            Manager::Get()->GetMacrosManager()->ReplaceEnvVars(out);
            wxFileName file(out);
            file.MakeAbsolute(prj->GetBasePath());
            valid = ::wxFileExists(file.GetFullPath());
            valid = valid || (pTarget->GetTargetType() == ttCommandsOnly) ;
        }
    }

    return valid;
}
This approach seems to me to be more correct than checking afterwards whether the action taken is correct.
Because in the options allowed to the user: the option 'wxID_NO' leads to run anyway with an error !!

What do you think about this?
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5514
Re: Plugin 'compilergcc'
« Reply #1 on: May 20, 2023, 04:46:57 pm »
I agree, providing the user to click on something while we (the system) knows this is not possible, is not user friendly.

Would there still be added value in checking afterwards ... ?

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Plugin 'compilergcc'
« Reply #2 on: May 20, 2023, 05:23:54 pm »
I don't think so. But this needs to be checked by other people.
It would then be necessary to delete the code presented first, which is no longer useful.

There is the same kind of code for 'int CompilerGCC::RunSingleFile(const wxString& filename)'.
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Plugin 'compilergcc'
« Reply #3 on: May 22, 2023, 09:20:15 am »
Can I submit a ticket for a patch request ?
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5514
Re: Plugin 'compilergcc'
« Reply #4 on: May 22, 2023, 10:21:04 am »
sure

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Plugin 'compilergcc'
« Reply #5 on: May 23, 2023, 05:37:48 pm »
I created a ticket with a patch  https://sourceforge.net/p/codeblocks/tickets/1395/
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Plugin 'compilergcc'
« Reply #6 on: May 30, 2023, 03:10:27 pm »
Fixed in 'r13278'.
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl