Author Topic: Batch build - optionally not show BatchLogWin dialog  (Read 2254 times)

Offline AndrewCot

  • Almost regular
  • **
  • Posts: 248
Batch build - optionally not show BatchLogWin dialog
« on: October 26, 2021, 11:44:02 am »
I have started to work on modifying the code to not show the BatchLogWindow dialog (only) when running in batch mode if you add "--batch-headless-build" option to the command line.

I could not find if anyone has worked on doing this in the past, but I may have used the wrong keywords or missed a post in the forum. Has anyone worked on this before? If you did can you point me at your changes and if possible let me know why it did not make it into the C::B svn repo?

I have C::B not running headless, but when running headless both the app and debug logs are sent to the console. This will change as I need to add support for the following when running in the headless mode:
   "no-log"
   "log-to-file"
   "debug-log"
   "debug-log-to-file"

I am not proposing at this point in time stopping the global variable GUI dialog from pop up due to missing variables.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3027
Re: Batch build - optionally not show BatchLogWin dialog
« Reply #1 on: October 26, 2021, 06:12:23 pm »
> I am not proposing at this point in time stopping the global variable GUI dialog from pop up due to missing variables.
i work on this

> I have started to work on modifying the code to not show the BatchLogWindow dialog (only) when running in batch mode if you add "--batch-headless-build" option to the command line.
isn't this possible already?

Offline AndrewCot

  • Almost regular
  • **
  • Posts: 248
Re: Batch build - optionally not show BatchLogWin dialog
« Reply #2 on: October 27, 2021, 12:43:43 am »
>> I am not proposing at this point in time stopping the global variable GUI dialog from pop up due to missing variables.
>i work on this
This is why I am not going to work on it.

>> I have started to work on modifying the code to not show the BatchLogWindow dialog (only) when running in batch mode if you add "--batch-headless-build" option to the command line.
>isn't this possible already?
Not that I could find or see in the code. Some things to check out are (there are more, but these show the main issues/problem areas):
   * main.cpp search for "MainFrame::SetupGUILogging" and have a look at it as it has GUI code
   * app.cpp - search for "TextCtrlLogger"  - cannot use TextCtrlLogger if there is no GUI...
   * compilergcc.cpp check out the "CompilerGCC::OnAttach()" function and the first call to Manager::Get()->ProcessEvent(...) should not be called when running headless.



I got a bit ahead of myself in that I have it working for the minimal C::B build, but it is failing when I build everything as I think some of the plugins have code that uses/creates something related to the GUI and therefore I get a silent failure and I need to do some more changes in one or more of the plugins to stop it/them using a GUI when running headless once I find the plugs I need to modify.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3027
Re: Batch build - optionally not show BatchLogWin dialog
« Reply #3 on: October 27, 2021, 05:39:46 pm »
I would like to think about a strategy to remove the  UI dependent code.

Obfuscated used a
Code
BaseClass -
          |- UI Class
          |- Non UI Class
way, and i quite like it, but later he said it is to complicated...
How do you think you want to remove ui code? Simply with
Code
if(!BatchBuild)
   show message box
else
   log to console
or some other way?

Offline AndrewCot

  • Almost regular
  • **
  • Posts: 248
Re: Batch build - optionally not show BatchLogWin dialog
« Reply #4 on: October 28, 2021, 12:45:49 am »
It gets a bit more complex as the more I understand it the more things have to be taken care of.

My current thinking is below at a high level, which has changed a few times as I find things and get more familiar with the code in the area that needs mods or I have looked at.

Code
if(!IsBatchBuild)
   show C::B normal IDE
else
{
    if(IsHeadlessBuild)
   {
     log to console or log to file
   }
   else
      show batch build dialog
}

NOTE: for a Headless build then both IsBatchBuild & IsHeadlessBuild are true.



The change to remove the GUI is painless and relatively easy, but other parts of the code need to be modded to not try and use the GUI. The following is my WIP SetupGUILogging() in main.cpp to that removed the GUI. The main change was to add another if check in the else code ("if (!Manager::IsHeadlessBuild())"). The call to m_pInfoPane->SetDropTarget(...) now has protection around is m_pInfoPane does not exist in a headless build.

Code
void MainFrame::SetupGUILogging(int uiSize16)
{
    // allow new docked windows to use be 3/4 of the available space, the default (0.3) is sometimes too small, especially for "Logs & others"
    m_LayoutManager.SetDockSizeConstraint(0.75,0.75);

    int bottomH = Manager::Get()->GetConfigManager(_T("app"))->ReadInt(_T("/main_frame/layout/bottom_block_height"), 150);
    wxSize clientsize = GetClientSize();

    LogManager* mgr = Manager::Get()->GetLogManager();
    Manager::Get()->SetImageSize(uiSize16, Manager::UIComponent::InfoPaneNotebooks);
    Manager::Get()->SetUIScaleFactor(cbGetContentScaleFactor(*this),
                                     Manager::UIComponent::InfoPaneNotebooks);

    if (!Manager::IsBatchBuild())
    {
        m_pInfoPane = new InfoPane(this);
        m_LayoutManager.AddPane(m_pInfoPane, wxAuiPaneInfo().
                                  Name(wxT("MessagesPane")).Caption(_("Logs & others")).
                                  BestSize(wxSize(clientsize.GetWidth(), bottomH)).//MinSize(wxSize(50,50)).
                                  Bottom());

        wxWindow* log;

        for (size_t i = LogManager::app_log; i < LogManager::max_logs; ++i)
        {
            if ((log = mgr->Slot(i).GetLogger()->CreateControl(m_pInfoPane)))
                m_pInfoPane->AddLogger(mgr->Slot(i).GetLogger(), log, mgr->Slot(i).title, mgr->Slot(i).icon);
        }

        m_findReplace.CreateSearchLog();
    }
    else
    {
        if (!Manager::IsHeadlessBuild())
        {
            m_pBatchBuildDialog = new BatchLogWindow(this, _("Code::Blocks - Batch build"));
            wxSizer* s = new wxBoxSizer(wxVERTICAL);
            m_pInfoPane = new InfoPane(m_pBatchBuildDialog);
            s->Add(m_pInfoPane, 1, wxEXPAND);
            m_pBatchBuildDialog->SetSizer(s);

            // setting &g_null_log causes the app to crash on exit for some reason...
            mgr->SetLog(new NullLogger, LogManager::app_log);
            mgr->SetLog(new NullLogger, LogManager::debug_log);
        }
    }

    mgr->NotifyUpdate();
    if (m_pInfoPane)
        m_pInfoPane->SetDropTarget(new cbFileDropTarget(this));
}


Offline blauzahn

  • Multiple posting newcomer
  • *
  • Posts: 116
Re: Batch build - optionally not show BatchLogWin dialog
« Reply #5 on: October 28, 2021, 07:13:40 am »
Hello,

I also would like to be able to use a headless build. But I am not in favour of sprinkling the code with "yet some more simple if", possibly spread across multiple files though.

My feeling is, that a solution closer to the one proposed by @obfuscated could be more appropriate -- that is runtime polymorphic use. I admit, I have not studied cb's codebase in this regard lately. One problem with the classic oo-way, here deriving the UI and Non UI classes from a common base class, is that very often it creates a lot of high coupling and accidential complexity.

In the codebases I mainly work on, we prefer alternatives to classic oo instead, like a type erasing wrapper or std::variant.

I guess, in order to preserve the current functionality in cb yet provide the means to headless mode, a handfull of functions have to be provided.

In case someone is not familiar with type erasure, std::function is an example thereof, albeit providing one single member-function (op()) only. Maybe you have already watched on youtube a quite famous talk within the C++ community, held by Adobe's Sean Parent from the GoingNative 2014 conference "C++ Seasoning" (see: https://www.youtube.com/watch?v=W2tWOdzgXHA) and maybe also a talk by Louis Dionne (https://www.youtube.com/watch?v=OtU51Ytfe04).

In headless mode, does MainFrame::SetupGUILogging have to be called in the first place?

btw: I haven't seen obfuscated here for a while. I hope, he is fine and just too busy doing his daily work to post here.

Have a nice day.