1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 The CodeLite Team
// file name : continuousbuild.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "continuousbuild.h"
#include "event_notifier.h"
#include "buildmanager.h"
#include "globals.h"
#include "builder.h"
#include "file_logger.h"
#include "processreaderthread.h"
#include "fileextmanager.h"
#include "build_settings_config.h"
#include "workspace.h"
#include "custombuildrequest.h"
#include "compile_request.h"
#include <wx/app.h>
#include "environmentconfig.h"
#include "continousbuildpane.h"
#include <wx/xrc/xmlres.h>
#include "continousbuildconf.h"
#include <wx/log.h>
#include <wx/imaglist.h>
#include "cl_command_event.h"
static ContinuousBuild* thePlugin = NULL;
//Define the plugin entry point
extern "C" EXPORT IPlugin *CreatePlugin(IManager *manager)
{
if (thePlugin == 0) {
thePlugin = new ContinuousBuild(manager);
}
return thePlugin;
}
extern "C" EXPORT PluginInfo GetPluginInfo()
{
PluginInfo info;
info.SetAuthor(wxT("eran"));
info.SetName(wxT("ContinuousBuild"));
info.SetDescription(_("Continuous build plugin which compiles files on save and report errors"));
info.SetVersion(wxT("v1.0"));
return info;
}
extern "C" EXPORT int GetPluginInterfaceVersion()
{
return PLUGIN_INTERFACE_VERSION;
}
BEGIN_EVENT_TABLE(ContinuousBuild, IPlugin)
EVT_COMMAND(wxID_ANY, wxEVT_PROC_DATA_READ, ContinuousBuild::OnBuildProcessOutput)
EVT_COMMAND(wxID_ANY, wxEVT_PROC_TERMINATED, ContinuousBuild::OnBuildProcessEnded)
END_EVENT_TABLE()
static const wxString CONT_BUILD = wxT("BuildQ");
ContinuousBuild::ContinuousBuild(IManager *manager)
: IPlugin(manager)
, m_buildInProgress(false)
{
m_longName = _("Continuous build plugin which compiles files on save and report errors");
m_shortName = wxT("ContinuousBuild");
m_view = new ContinousBuildPane(m_mgr->GetOutputPaneNotebook(), m_mgr, this);
// add our page to the output pane notebook
m_mgr->GetOutputPaneNotebook()->AddPage(m_view, CONT_BUILD, false, LoadBitmapFile(wxT("compfile.png")));
m_topWin = m_mgr->GetTheApp();
EventNotifier::Get()->Connect(wxEVT_FILE_SAVED, clCommandEventHandler(ContinuousBuild::OnFileSaved), NULL, this);
EventNotifier::Get()->Connect(wxEVT_FILE_SAVE_BY_BUILD_START, wxCommandEventHandler(ContinuousBuild::OnIgnoreFileSaved), NULL, this);
EventNotifier::Get()->Connect(wxEVT_FILE_SAVE_BY_BUILD_END, wxCommandEventHandler(ContinuousBuild::OnStopIgnoreFileSaved), NULL, this);
}
ContinuousBuild::~ContinuousBuild()
{
}
clToolBar *ContinuousBuild::CreateToolBar(wxWindow *parent)
{
// Create the toolbar to be used by the plugin
clToolBar *tb(NULL);
return tb;
}
void ContinuousBuild::CreatePluginMenu(wxMenu *pluginsMenu)
{
wxUnusedVar(pluginsMenu);
}
void ContinuousBuild::HookPopupMenu(wxMenu *menu, MenuType type)
{
wxUnusedVar(menu);
wxUnusedVar(type);
}
void ContinuousBuild::UnPlug()
{
// before this plugin is un-plugged we must remove the tab we added
for (size_t i=0; i<m_mgr->GetOutputPaneNotebook()->GetPageCount(); i++) {
if (m_view == m_mgr->GetOutputPaneNotebook()->GetPage(i)) {
m_mgr->GetOutputPaneNotebook()->RemovePage(i);
m_view->Destroy();
break;
}
}
EventNotifier::Get()->Disconnect(wxEVT_FILE_SAVED, clCommandEventHandler(ContinuousBuild::OnFileSaved), NULL, this);
EventNotifier::Get()->Disconnect(wxEVT_FILE_SAVE_BY_BUILD_START, wxCommandEventHandler(ContinuousBuild::OnIgnoreFileSaved), NULL, this);
EventNotifier::Get()->Disconnect(wxEVT_FILE_SAVE_BY_BUILD_END, wxCommandEventHandler(ContinuousBuild::OnStopIgnoreFileSaved), NULL, this);
}
void ContinuousBuild::OnFileSaved(clCommandEvent& e)
{
e.Skip();
CL_DEBUG(wxT("ContinuousBuild::OnFileSaved\n"));
// Dont build while the main build is in progress
if (m_buildInProgress) {
CL_DEBUG(wxT("Build already in progress, skipping\n"));
return;
}
ContinousBuildConf conf;
m_mgr->GetConfigTool()->ReadObject(wxT("ContinousBuildConf"), &conf);
if (conf.GetEnabled()) {
DoBuild( e.GetString() );
} else {
CL_DEBUG(wxT("ContinuousBuild is disabled\n"));
}
}
void ContinuousBuild::DoBuild(const wxString& fileName)
{
CL_DEBUG(wxT("DoBuild\n"));
// Make sure a workspace is opened
if (!m_mgr->IsWorkspaceOpen()) {
CL_DEBUG(wxT("No workspace opened!\n"));
return;
}
// Filter non source files
FileExtManager::FileType type = FileExtManager::GetType(fileName);
switch(type) {
case FileExtManager::TypeSourceC:
case FileExtManager::TypeSourceCpp:
case FileExtManager::TypeResource:
break;
default: {
CL_DEBUG(wxT("Non source file\n"));
return;
}
}
wxString projectName = m_mgr->GetProjectNameByFile(fileName);
if(projectName.IsEmpty()) {
CL_DEBUG(wxT("Project name is empty\n"));
return;
}
wxString errMsg;
ProjectPtr project = m_mgr->GetWorkspace()->FindProjectByName(projectName, errMsg);
if(!project) {
CL_DEBUG(wxT("Could not find project for file\n"));
return;
}
// get the selected configuration to be build
BuildConfigPtr bldConf = m_mgr->GetWorkspace()->GetProjBuildConf( project->GetName(), wxEmptyString );
if ( !bldConf ) {
CL_DEBUG(wxT("Failed to locate build configuration\n"));
return;
}
BuilderPtr builder = m_mgr->GetBuildManager()->GetBuilder( wxT( "GNU makefile for g++/gcc" ) );
if(!builder) {
CL_DEBUG(wxT("Failed to located builder\n"));
return;
}
// Only normal file builds are supported
if(bldConf->IsCustomBuild()) {
CL_DEBUG(wxT("Build is custom. Skipping\n"));
return;
}
// get the single file command to use
wxString cmd = builder->GetSingleFileCmd(projectName, bldConf->GetName(), fileName);
WrapInShell(cmd);
if( m_buildProcess.IsBusy() ) {
// add the build to the queue
if (m_files.Index(fileName) == wxNOT_FOUND) {
m_files.Add(fileName);
// update the UI
m_view->AddFile(fileName);
}
return;
}
clCommandEvent event(wxEVT_SHELL_COMMAND_STARTED);
// Associate the build event details
BuildEventDetails *eventData = new BuildEventDetails();
eventData->SetProjectName(projectName);
eventData->SetConfiguration(bldConf->GetName());
eventData->SetIsCustomProject(bldConf->IsCustomBuild());
eventData->SetIsClean(false);
event.SetClientObject(eventData);
// Fire it up
EventNotifier::Get()->AddPendingEvent(event);
EnvSetter env(NULL, NULL, projectName);
CL_DEBUG(wxString::Format(wxT("cmd:%s\n"), cmd.c_str()));
if(!m_buildProcess.Execute(cmd, fileName, project->GetFileName().GetPath(), this))
return;
// Set some messages
m_mgr->SetStatusMessage(wxString::Format(wxT("%s %s..."), _("Compiling"), wxFileName(fileName).GetFullName().c_str()), 0);
// Add this file to the UI queue
m_view->AddFile(fileName);
}
void ContinuousBuild::OnBuildProcessEnded(wxCommandEvent& e)
{
// remove the file from the UI
ProcessEventData *ped = (ProcessEventData*)e.GetClientData();
delete ped;
int pid = m_buildProcess.GetPid();
m_view->RemoveFile(m_buildProcess.GetFileName());
clCommandEvent event(wxEVT_SHELL_COMMAND_PROCESS_ENDED);
EventNotifier::Get()->AddPendingEvent(event);
int exitCode(-1);
if(IProcess::GetProcessExitCode(pid, exitCode) && exitCode != 0) {
m_view->AddFailedFile(m_buildProcess.GetFileName());
}
// Release the resources allocted for this build
m_buildProcess.Stop();
// if the queue is not empty, start another build
if (m_files.IsEmpty() == false) {
wxString fileName = m_files.Item(0);
m_files.RemoveAt(0);
DoBuild(fileName);
}
}
void ContinuousBuild::StopAll()
{
// empty the queue
m_files.Clear();
m_buildProcess.Stop();
}
void ContinuousBuild::OnIgnoreFileSaved(wxCommandEvent& e)
{
e.Skip();
m_buildInProgress = true;
// Clear the queue
m_files.Clear();
// Clear the view
m_view->ClearAll();
}
void ContinuousBuild::OnStopIgnoreFileSaved(wxCommandEvent& e)
{
e.Skip();
m_buildInProgress = false;
}
void ContinuousBuild::OnBuildProcessOutput(wxCommandEvent& e)
{
ProcessEventData *ped = (ProcessEventData*)e.GetClientData();
clCommandEvent event(wxEVT_SHELL_COMMAND_ADDLINE);
event.SetString(ped->GetData());
EventNotifier::Get()->AddPendingEvent(event);
//m_mgr->AddBuildOuptut(ped->GetData(), false);
delete ped;
}
|