Code::Blocks  SVN r11506
compilergcc.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  */
5 
6 #ifndef COMPILERGCC_H
7 #define COMPILERGCC_H
8 
9 #include <wx/choice.h>
10 #include <wx/dynarray.h>
11 #include <wx/process.h>
12 #include <wx/timer.h>
13 
14 #include <queue>
15 
16 #include <cbplugin.h>
17 #include <cbproject.h>
18 #include <compileoptionsbase.h>
19 #include <compilerfactory.h>
20 #include <logger.h>
21 #include <sdk_events.h>
22 #include <settings.h> // SDK
23 
24 #include "compilermessages.h"
25 #include "compilererrors.h"
26 #include "compiler_defs.h"
27 
29 {
30  cotGlobal = 0,
32 };
33 
35 {
36  etNone = 0,
39 };
40 
43 {
44  bjIdle = 0,
48 };
49 
52 {
53  bsNone = 0,
62 };
63 
65 {
66  ltMessages = 0x01,
67  ltFile = 0x02,
68 
69  ltAll = 0xff
70 };
71 
73 {
74  baClean = 0,
78 };
79 
80 class wxComboBox;
81 class wxGauge;
82 class wxStaticText;
83 
84 class BuildLogger;
85 class PipedProcess;
86 
88 {
89  public:
90  CompilerGCC();
91  virtual ~CompilerGCC();
92 
93  virtual void OnAttach();
94  virtual void OnRelease(bool appShutDown);
95  virtual void BuildMenu(wxMenuBar* menuBar); // offer for menu space by host
96  virtual void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0); // offer for menu space by a module
97  virtual bool BuildToolBar(wxToolBar* toolBar);
98  virtual int GetToolBarPriority() { return 1; }
99 
100  virtual int Run(ProjectBuildTarget* target = 0L);
101  virtual int Run(const wxString& target);
102  virtual int RunSingleFile(const wxString& filename);
103  virtual int Clean(const wxString& target);
104  virtual int Clean(ProjectBuildTarget* target = 0L);
105  virtual int DistClean(ProjectBuildTarget* target = 0L);
106  virtual int DistClean(const wxString& target);
107  virtual int Build(ProjectBuildTarget* target = 0L);
108  virtual int Build(const wxString& target);
109  virtual int Rebuild(ProjectBuildTarget* target = 0L);
110  virtual int Rebuild(const wxString& target);
111  virtual int CleanWorkspace(const wxString& target = wxEmptyString);
112  virtual int BuildWorkspace(const wxString& target = wxEmptyString);
113  virtual int RebuildWorkspace(const wxString& target = wxEmptyString);
114  virtual int CompileFile(const wxString& file);
115  virtual int CompileFileWithoutProject(const wxString& file);
116  virtual int CompileFileDefault(cbProject* project, ProjectFile* pf, ProjectBuildTarget* bt);
117  virtual int KillProcess();
118  virtual bool IsRunning() const;
119  virtual int GetExitCode() const { return m_LastExitCode; }
120  virtual int Configure(cbProject* project, ProjectBuildTarget* target = 0L); // this is NOT the obsolete cbPlugin::Configure! Do not remove!!!
121 
122  int GetConfigurationPriority() const { return 0; }
123  int GetConfigurationGroup() const { return cgCompiler; }
125 
126  bool IsValidTarget(const wxString& target) const;
127 
128  void SwitchCompiler(const wxString& id);
130 
131  // used to read from the external process
132  void OnIdle(wxIdleEvent& event);
133  void OnTimer(wxTimerEvent& event);
134 
135  void OnCompile(wxCommandEvent& event);
136  void OnCompileFile(wxCommandEvent& event);
137  void OnCleanFile(wxCommandEvent& event);
138  void OnRebuild(wxCommandEvent& event);
139  void OnCompileAll(wxCommandEvent& event);
140  void OnRebuildAll(wxCommandEvent& event);
141  void OnCleanAll(wxCommandEvent& event);
142  void OnClean(wxCommandEvent& event);
143  void OnRun(wxCommandEvent& event);
146  void OnCompileAndRun(wxCommandEvent& event);
147  void OnKillProcess(wxCommandEvent& event);
148  void OnSelectTarget(wxCommandEvent& event);
149  void OnNextError(wxCommandEvent& event);
150  void OnPreviousError(wxCommandEvent& event);
151  void OnClearErrors(wxCommandEvent& event);
152  void OnUpdateUI(wxUpdateUIEvent& event);
153  void OnConfig(wxCommandEvent& event);
154  private:
155  friend class CompilerOptionsDlg;
156 
157  void Dispatcher(wxCommandEvent& event);
158  void TextURL(wxTextUrlEvent& event);
159 
160  bool StopRunningDebugger();
161 
162  bool ReAllocProcesses();
163  void AllocProcesses();
164  void FreeProcesses();
165  bool IsProcessRunning(int idx = -1) const;
166  int GetNextAvailableProcessIndex() const;
167  int GetActiveProcessCount() const;
168 
169  void SetupEnvironment();
170  void OnProjectActivated(CodeBlocksEvent& event);
171  void OnProjectLoaded(CodeBlocksEvent& event);
172  void OnProjectUnloaded(CodeBlocksEvent& event);
173  void OnWorkspaceClosed(CodeBlocksEvent& event);
175  void OnGCCOutput(CodeBlocksEvent& event);
176  void OnGCCError(CodeBlocksEvent& event);
177  void OnGCCTerminated(CodeBlocksEvent& event);
178  void OnJobEnd(size_t procIndex, int exitCode);
179 
180  void SaveOptions();
181  void LoadOptions();
182  void DoRegisterCompilers();
183  void DoPrepareQueue(bool clearLog);
184  void NotifyCleanProject(const wxString& target);
185  void NotifyCleanWorkspace();
186  int DoRunQueue();
187  void DoClearTargetMenu();
188  void DoRecreateTargetMenu();
189  void DoUpdateTargetMenu(int targetIndex);
192  int DoGUIAskForTarget();
193  void ClearLog(bool switchToLog);
194  void PrepareCompileFile(wxFileName& file);
195  void PrepareCompileFilePM(wxFileName& file);
196  bool CheckProject();
197  void AskForActiveProject();
198  void StartCompileFile(wxFileName file);
199  void DoGotoNextError();
200  void DoGotoPreviousError();
201  void DoClearErrors();
203  void AddOutputLine(const wxString& output, bool forceErrorColour = false);
204  void LogWarningOrError(CompilerLineType lt, cbProject* prj, const wxString& filename, const wxString& line, const wxString& msg);
205  void LogMessage(const wxString& message, CompilerLineType lt = cltNormal, LogTarget log = ltAll, bool forceErrorColour = false, bool isTitle = false, bool updateProgress = false);
206  void SaveBuildLog();
207  void InitBuildLog(bool workspaceBuild);
208  void PrintBanner(BuildAction action, cbProject* prj = 0, ProjectBuildTarget* target = 0);
209  bool UseMake(cbProject* project = 0);
210 
212  {
213  Compiler *compiler = nullptr;
214  bool isValid = false;
215  };
217  void PrintInvalidCompiler(ProjectBuildTarget *target, Compiler *compiler, const wxString &finalMessage);
220  int DoBuild(bool clean, bool build);
221  int DoBuild(const wxString& target, bool clean, bool build, bool clearLog=true);
222  int DoWorkspaceBuild(const wxString& target, bool clean, bool build, bool clearLog=true);
225  void InitBuildState(BuildJob job, const wxString& target);
226  void ResetBuildState();
227  void BuildStateManagement();
229  void NotifyJobDone(bool showNothingToBeDone = false);
230 
231  // wxArrayString from DirectCommands
232  void AddToCommandQueue(const wxArrayString& commands);
233 
234  int GetTargetIndexFromName(cbProject* prj, const wxString& name);
235  void UpdateProjectTargets(cbProject* project);
236  wxString GetTargetString(int index = -1);
237  void DoClean(const wxArrayString& commands);
239 
240  // active target, currently building project or active project
242 
245 
246  // when a build is about to start, a preprocessing step runs
247  // in PreprocessJob(), that fills m_BuildJobTargetsList with
248  // BuildJobTarget. It is a simple pair of project->target which
249  // are to be built in order
251  {
252  BuildJobTarget(cbProject* p = 0, const wxString& n = wxEmptyString) : project(p), targetName(n) {}
255  };
256  typedef std::queue<BuildJobTarget> BuildJobTargetsList;
257  BuildJobTargetsList m_BuildJobTargetsList;
258 
259  void ExpandTargets(cbProject* project, const wxString& targetName, wxArrayString& result);
260  void PreprocessJob(cbProject* project, const wxString& targetName);
262  const BuildJobTarget& PeekNextJob();
263 
265  {
268  long int PID;
269  };
270  typedef std::vector<CompilerProcess> CompilerProcessList;
271  CompilerProcessList m_CompilerProcessList;
272 
273  wxArrayString m_Targets; // list of targets contained in the active project
276 
299 
300  // build state management
308  // Clean and Build
309  bool m_Clean;
310  bool m_Build;
311  // if set and we are reaching NotifyJobDone, we know that we have finished the
312  // last step in a clean/build (aka rebuild)-process and send the cbEVT_COMPILER_FINISHED
314  // to decide if post-build steps should run
317 
318  bool m_IsWorkspaceOperation; // true for workspace commands
319 
324 
325  // build progress
329 
330  DECLARE_EVENT_TABLE()
331 };
332 
333 #endif // COMPILERGCC_H
void OnKillProcess(wxCommandEvent &event)
void OnJobEnd(size_t procIndex, int exitCode)
CompilerMessages * m_pListLog
Definition: compilergcc.h:289
void OnCompileFileRequest(CodeBlocksEvent &event)
int GetConfigurationPriority() const
Return the plugin&#39;s configuration priority.
Definition: compilergcc.h:122
virtual bool IsRunning() const
Is the plugin currently compiling?
wxDateTime m_BuildStartTime
Definition: compilergcc.h:323
virtual void OnRelease(bool appShutDown)
bool IsValidTarget(const wxString &target) const
void TextURL(wxTextUrlEvent &event)
const BuildJobTarget & PeekNextJob()
virtual int Clean(const wxString &target)
Same as Clean(ProjectBuildTarget*) but with a wxString argument.
void PrepareCompileFilePM(wxFileName &file)
wxString m_BuildLogFilename
Definition: compilergcc.h:320
wxToolBar * m_pTbar
Definition: compilergcc.h:286
void UpdateProjectTargets(cbProject *project)
bool IsProcessRunning(int idx=-1) const
virtual void BuildMenu(wxMenuBar *menuBar)
std::vector< CompilerProcess > CompilerProcessList
Definition: compilergcc.h:270
void DoRegisterCompilers()
void OnProjectCompilerOptions(wxCommandEvent &event)
void OnConfig(wxCommandEvent &event)
BuildState
Defines the current state of the compiler.
Definition: compilergcc.h:51
void OnCleanFile(wxCommandEvent &event)
MakeCommand
virtual ~CompilerGCC()
void OnCompileAll(wxCommandEvent &event)
void AddToCommandQueue(const wxArrayString &commands)
void SwitchCompiler(const wxString &id)
virtual void BuildModuleMenu(const ModuleType type, wxMenu *menu, const FileTreeData *data=0)
void OnRebuild(wxCommandEvent &event)
void DoClean(const wxArrayString &commands)
void OnNextError(wxCommandEvent &event)
CompilerOptionsType
Definition: compilergcc.h:28
void PrintBanner(BuildAction action, cbProject *prj=0, ProjectBuildTarget *target=0)
static const int cgCompiler
Compiler related.
Definition: cbplugin.h:68
size_t m_MaxProgress
Definition: compilergcc.h:326
CompilerErrors m_Errors
Definition: compilergcc.h:295
void OnTargetCompilerOptions(wxCommandEvent &event)
wxTimer m_timerIdleWakeUp
Definition: compilergcc.h:287
virtual void OnAttach()
Any descendent plugin should override this virtual method and perform any necessary initialization...
void OnProjectActivated(CodeBlocksEvent &event)
BuildState GetNextStateBasedOnJob()
int GetNextAvailableProcessIndex() const
wxMenu * m_TargetMenu
Definition: compilergcc.h:282
size_t m_CurrentProgress
Definition: compilergcc.h:327
virtual int BuildWorkspace(const wxString &target=wxEmptyString)
Build all open projects.
virtual int RunSingleFile(const wxString &filename)
void DoPrepareQueue(bool clearLog)
const wxString & GetCurrentCompilerID()
void OnSelectTarget(wxCommandEvent &event)
wxString GetTargetString(int index=-1)
void BuildStateManagement()
This uses m_BuildJob.
virtual int CompileFileWithoutProject(const wxString &file)
void OnCleanAll(wxCommandEvent &event)
void DoUpdateTargetMenu(int targetIndex)
ProjectBuildTarget * DoAskForTarget()
virtual int CleanWorkspace(const wxString &target=wxEmptyString)
Clean all open projects.
int GetConfigurationGroup() const
Return the configuration group for this plugin.
Definition: compilergcc.h:123
void CalculateWorkspaceDependencies(wxArrayInt &deps)
virtual int RebuildWorkspace(const wxString &target=wxEmptyString)
Rebuild all open projects.
wxString GetMinSecStr()
bool m_IsWorkspaceOperation
Definition: compilergcc.h:318
void NotifyJobDone(bool showNothingToBeDone=false)
Represents a file in a Code::Blocks project.
Definition: projectfile.h:39
LogTarget
Definition: compilergcc.h:64
wxString GetErrWarnStr()
A generic Code::Blocks event.
Definition: sdk_events.h:20
wxString ProjectMakefile()
void Dispatcher(wxCommandEvent &event)
Base class for compiler plugins.
Definition: cbplugin.h:263
CompilerLineType
Enum categorizing compiler&#39;s output line as warning/error/info/normal.
Definition: compiler.h:66
int m_RealTargetsStartIndex
Definition: compilergcc.h:274
void OnProjectLoaded(CodeBlocksEvent &event)
FileTreeData * DoSwitchProjectTemporarily()
BuildJobTarget(cbProject *p=0, const wxString &n=wxEmptyString)
Definition: compilergcc.h:252
wxLongLong m_StartTime
Definition: compilergcc.h:298
void DoGotoNextError()
wxString m_BuildLogContents
Definition: compilergcc.h:322
void OnRebuildAll(wxCommandEvent &event)
virtual int KillProcess()
Abort the current build process.
BuildJobTarget GetNextJob()
Not currently building.
Definition: compilergcc.h:44
Represents a Code::Blocks project.
Definition: cbproject.h:96
wxString m_LastTargetName
Definition: compilergcc.h:296
CompilerProcessList m_CompilerProcessList
Definition: compilergcc.h:271
void DoGotoPreviousError()
virtual bool BuildToolBar(wxToolBar *toolBar)
wxArrayString m_Targets
Definition: compilergcc.h:273
int m_LastExitCode
Definition: compilergcc.h:294
ModuleType
The type of module offering a context menu.
Definition: globals.h:38
void OnCompileAndRun(wxCommandEvent &event)
int GetTargetIndexFromName(cbProject *prj, const wxString &name)
void AskForActiveProject()
void InitBuildState(BuildJob job, const wxString &target)
int m_TargetIndex
Definition: compilergcc.h:283
bool CheckProject()
bool m_LogBuildProgressPercentage
Definition: compilergcc.h:328
bool UseMake(cbProject *project=0)
cbProject * m_pBuildingProject
Definition: compilergcc.h:301
wxString GetMakeCommandFor(MakeCommand cmd, cbProject *project, ProjectBuildTarget *target)
wxString m_RunCmd
Definition: compilergcc.h:293
void DoClearTargetMenu()
void ResetBuildState()
void DoRecreateTargetMenu()
void OnTimer(wxTimerEvent &event)
void AddOutputLine(const wxString &output, bool forceErrorColour=false)
wxString wxEmptyString
void OnWorkspaceClosed(CodeBlocksEvent &event)
virtual int CompileFile(const wxString &file)
Compile a specific file.
wxString m_BuildLogTitle
Definition: compilergcc.h:321
virtual int Configure(cbProject *project, ProjectBuildTarget *target=0L)
Display configuration dialog.
cbProject * m_pProject
Definition: compilergcc.h:285
BuildJob
Helper enum for compiler&#39;s state. This state signifies the kind of build the compiler is working on...
Definition: compilergcc.h:42
Building the workspace.
Definition: compilergcc.h:45
int DoWorkspaceBuild(const wxString &target, bool clean, bool build, bool clearLog=true)
BuildAction
Definition: compilergcc.h:72
ProjectBuildTarget * GetBuildTargetForFile(ProjectFile *pf)
Base class for plugin configuration panels.
int GetActiveProcessCount() const
virtual int GetExitCode() const
Get the exit code of the last build process.
Definition: compilergcc.h:119
void StartCompileFile(wxFileName file)
void OnCompile(wxCommandEvent &event)
std::queue< BuildJobTarget > BuildJobTargetsList
Definition: compilergcc.h:256
wxMenu * m_pErrorsMenu
Definition: compilergcc.h:284
void OnPreviousError(wxCommandEvent &event)
void SaveOptions()
wxArray< int > wxArrayInt
void OnGCCOutput(CodeBlocksEvent &event)
Abstract base class for compilers.
Definition: compiler.h:274
void ExpandTargets(cbProject *project, const wxString &targetName, wxArrayString &result)
virtual int Rebuild(ProjectBuildTarget *target=0L)
Rebuild the project/target.
void NotifyCleanWorkspace()
void AllocProcesses()
bool m_NotifiedMaxErrors
Definition: compilergcc.h:297
void LogWarningOrError(CompilerLineType lt, cbProject *prj, const wxString &filename, const wxString &line, const wxString &msg)
wxChoice * m_pToolTarget
Definition: compilergcc.h:290
BuildJobTargetsList m_BuildJobTargetsList
Definition: compilergcc.h:257
void SaveBuildLog()
virtual int CompileFileDefault(cbProject *project, ProjectFile *pf, ProjectBuildTarget *bt)
bool m_LastBuildStep
Definition: compilergcc.h:313
Building the target.
Definition: compilergcc.h:47
int m_RealTargetIndex
Definition: compilergcc.h:275
void CalculateProjectDependencies(cbProject *prj, wxArrayInt &deps)
BuildState m_NextBuildState
Definition: compilergcc.h:305
wxString m_CompilerId
Definition: compilergcc.h:278
CompilerValidResult CompilerValid(ProjectBuildTarget *target=0)
void OnIdle(wxIdleEvent &event)
void OnClearErrors(wxCommandEvent &event)
virtual int Build(ProjectBuildTarget *target=0L)
Build the project/target.
bool m_RunTargetPostBuild
Definition: compilergcc.h:315
void InitBuildLog(bool workspaceBuild)
void OnCompileFile(wxCommandEvent &event)
wxString m_BuildingTargetName
Definition: compilergcc.h:302
void LogMessage(const wxString &message, CompilerLineType lt=cltNormal, LogTarget log=ltAll, bool forceErrorColour=false, bool isTitle=false, bool updateProgress=false)
bool DoCleanWithMake(ProjectBuildTarget *bt)
BuildState m_BuildState
Definition: compilergcc.h:304
Represents a Code::Blocks project build target.
int m_ListPageIndex
Definition: compilergcc.h:280
void OnClean(wxCommandEvent &event)
wxMenu * m_Menu
Definition: compilergcc.h:281
void PrepareCompileFile(wxFileName &file)
cbProject * m_pLastBuildingProject
Definition: compilergcc.h:306
ErrorType
Definition: compilergcc.h:34
BuildLogger * m_pLog
Definition: compilergcc.h:288
int DoGUIAskForTarget()
void PrintInvalidCompiler(ProjectBuildTarget *target, Compiler *compiler, const wxString &finalMessage)
void OnRun(wxCommandEvent &event)
virtual int GetToolBarPriority()
This method return the priority of the plugin&#39;s toolbar, the less value indicates a more preceding po...
Definition: compilergcc.h:98
void PreprocessJob(cbProject *project, const wxString &targetName)
cbConfigurationPanel * GetConfigurationPanel(wxWindow *parent)
int DoBuild(bool clean, bool build)
bool StopRunningDebugger()
void OnGCCTerminated(CodeBlocksEvent &event)
void OnUpdateUI(wxUpdateUIEvent &event)
bool m_RunProjectPostBuild
Definition: compilergcc.h:316
BuildJob m_BuildJob
Definition: compilergcc.h:303
void OnProjectUnloaded(CodeBlocksEvent &event)
ProjectBuildTarget * m_pLastBuildingTarget
Definition: compilergcc.h:307
void LoadOptions()
void OnGCCError(CodeBlocksEvent &event)
bool ReAllocProcesses()
virtual int Run(ProjectBuildTarget *target=0L)
Run the project/target.
virtual int DistClean(ProjectBuildTarget *target=0L)
DistClean the project/target.
CompilerQueue m_CommandQueue
Definition: compilergcc.h:277
void DoClearErrors()
void SetupEnvironment()
const wxString lt(_T("<"))
void NotifyCleanProject(const wxString &target)
Building the project.
Definition: compilergcc.h:46
void FreeProcesses()
void ClearLog(bool switchToLog)
bool m_RunAfterCompile
Definition: compilergcc.h:291
wxString m_CdRun
Definition: compilergcc.h:292