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
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2008 by Eran Ifrah
// file name : compile_request.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 "compile_request.h"
#include <wx/app.h>
#include <wx/log.h>
#include "event_notifier.h"
#include "asyncprocess.h"
#include "imanager.h"
#include "macros.h"
#include "compiler.h"
#include "build_settings_config.h"
#include "globals.h"
#include "build_config.h"
#include "environmentconfig.h"
#include "buildmanager.h"
#include "wx/process.h"
#include "workspace.h"
#include "dirsaver.h"
#include "plugin.h"
#include "cl_command_event.h"
#include "ICompilerLocator.h"
#include <wx/regex.h>
#include "macromanager.h"
#include "globals.h"
#include <wx/msgdlg.h>
CompileRequest::CompileRequest(
const QueueCommand& buildInfo, const wxString& fileName, bool runPremakeOnly, bool preprocessOnly)
: ShellCommand(buildInfo)
, m_fileName(fileName)
, m_premakeOnly(runPremakeOnly)
, m_preprocessOnly(preprocessOnly)
{
}
CompileRequest::~CompileRequest()
{
// no need to delete the process, it will be deleted by the wx library
}
// do the actual cleanup
void CompileRequest::Process(IManager* manager)
{
wxString cmd;
wxString errMsg;
wxStringMap_t om;
BuildSettingsConfig* bsc(manager ? manager->GetBuildSettingsConfigManager() : BuildSettingsConfigST::Get());
clCxxWorkspace* w(manager ? manager->GetWorkspace() : clCxxWorkspaceST::Get());
EnvironmentConfig* env(manager ? manager->GetEnv() : EnvironmentConfig::Instance());
ProjectPtr proj = w->FindProjectByName(m_info.GetProject(), errMsg);
if(!proj) {
AppendLine(_("Cant find project: ") + m_info.GetProject());
return;
}
wxString pname(proj->GetName());
wxArrayString unresolvedVars;
proj->GetUnresolvedMacros(m_info.GetConfiguration(), unresolvedVars);
if(!unresolvedVars.IsEmpty()) {
// We can't continue
wxString msg;
msg << _("The following environment variables are used in the project, but are not defined:\n");
for(size_t i = 0; i < unresolvedVars.size(); ++i) {
msg << unresolvedVars.Item(i) << "\n";
}
msg << _("Build anyway?");
wxStandardID res = ::PromptForYesNoDialogWithCheckbox(msg, "UnresolvedMacros", _("Yes"), _("No"),
_("Remember my answer and don't ask me again"), wxYES_NO | wxICON_WARNING | wxYES_DEFAULT);
if(res != wxID_YES) {
::wxMessageBox(_("Build Cancelled!"), "CodeLite", wxICON_ERROR | wxOK | wxCENTER);
return;
}
}
// Notify plugins that a compile process is going to start
clBuildEvent event(wxEVT_BUILD_STARTING);
event.SetProjectName(pname);
event.SetConfigurationName(m_info.GetConfiguration());
if(EventNotifier::Get()->ProcessEvent(event)) {
// the build is being handled by some plugin, no need to build it
// using the standard way
return;
}
// Send the EVENT_STARTED : even if this event is sent, next event will
// be post, so no way to be sure the the build process has not started
SendStartMsg();
// if we require to run the makefile generation command only, replace the 'cmd' with the
// generation command line
BuildConfigPtr bldConf = w->GetProjBuildConf(m_info.GetProject(), m_info.GetConfiguration());
if(bldConf) {
// BuilderPtr builder = bm->GetBuilder("Default");
BuilderPtr builder = bldConf->GetBuilder();
wxString args = bldConf->GetBuildSystemArguments();
if(m_fileName.IsEmpty() == false) {
// we got a complie request of a single file
cmd = m_preprocessOnly ?
builder->GetPreprocessFileCmd(
m_info.GetProject(), m_info.GetConfiguration(), args, m_fileName, errMsg) :
builder->GetSingleFileCmd(m_info.GetProject(), m_info.GetConfiguration(), args, m_fileName);
} else if(m_info.GetProjectOnly()) {
switch(m_info.GetKind()) {
case QueueCommand::kRebuild:
cmd = builder->GetPORebuildCommand(m_info.GetProject(), m_info.GetConfiguration(), args);
break;
default:
case QueueCommand::kBuild:
cmd = builder->GetPOBuildCommand(m_info.GetProject(), m_info.GetConfiguration(), args);
break;
}
} else {
cmd = builder->GetBuildCommand(m_info.GetProject(), m_info.GetConfiguration(), args);
}
wxString cmpType = bldConf->GetCompilerType();
CompilerPtr cmp = bsc->GetCompiler(cmpType);
if(cmp) {
// Add the 'bin' folder of the compiler to the PATH environment variable
wxString scxx = cmp->GetTool("CXX");
scxx.Trim().Trim(false);
scxx.StartsWith("\"", &scxx);
scxx.EndsWith("\"", &scxx);
// Strip the double quotes
wxFileName cxx(scxx);
wxString pathvar;
pathvar << cxx.GetPath() << clPATH_SEPARATOR;
// If we have an additional path, add it as well
if(!cmp->GetPathVariable().IsEmpty()) {
pathvar << cmp->GetPathVariable() << clPATH_SEPARATOR;
}
pathvar << "$PATH";
om["PATH"] = pathvar;
}
}
if(cmd.IsEmpty()) {
// if we got an error string, use it
if(errMsg.IsEmpty() == false) {
AppendLine(errMsg);
} else {
AppendLine(_("Command line is empty. Build aborted."));
}
return;
}
WrapInShell(cmd);
DirSaver ds;
DoSetWorkingDirectory(proj, false, m_fileName.IsEmpty() == false);
// expand the variables of the command
cmd = ExpandAllVariables(cmd, w, m_info.GetProject(), m_info.GetConfiguration(), m_fileName);
// print the build command
AppendLine(cmd + wxT("\n"));
if(m_info.GetProjectOnly() || m_fileName.IsEmpty() == false) {
// set working directory
DoSetWorkingDirectory(proj, false, m_fileName.IsEmpty() == false);
}
// print the prefix message of the build start. This is important since the parser relies
// on this message
if(m_info.GetProjectOnly() || m_fileName.IsEmpty() == false) {
wxString configName(m_info.GetConfiguration());
// also, send another message to the main frame, indicating which project is being built
// and what configuration
wxString text;
text << wxGetTranslation(BUILD_PROJECT_PREFIX) << m_info.GetProject() << wxT(" - ") << configName << wxT(" ]");
if(m_fileName.IsEmpty()) {
text << wxT("----------\n");
} else if(m_preprocessOnly) {
text << wxT(" (Preprocess Single File)----------\n");
} else {
text << wxT(" (Single File Build)----------\n");
}
AppendLine(text);
}
// Avoid Unicode chars coming from the compiler by setting LC_ALL to "C"
om["LC_ALL"] = "C";
EnvSetter envir(env, &om, proj->GetName(), m_info.GetConfiguration());
m_proc = CreateAsyncProcess(this, cmd);
if(!m_proc) {
wxString message;
message << _("Failed to start build process, command: ") << cmd << _(", process terminated with exit code: 0");
AppendLine(message);
return;
}
}
|