📄 compilergcc.cpp
字号:
switch (ret)
{
case wxYES:
{
Compile(target);
return -1;
}
case wxNO:
break;
default:
return -1;
}
}
Manager::Get()->GetMacrosManager()->ReplaceEnvVars(m_CdRun);
Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Executing: %s (in %s)"), cmd.c_str(), m_CdRun.c_str());
m_Queue.Add(cmd);
m_IsRun = true;
return 0;
}
int CompilerGCC::Clean(ProjectBuildTarget* target)
{
DoPrepareQueue();
if (!CompilerValid(target))
return -1;
if (CompilerFactory::CompilerIndexOK(m_CompilerIdx))
CompilerFactory::Compilers[m_CompilerIdx]->GetCustomVars().ApplyVarsToEnvironment();
m_Project->GetCustomVars().ApplyVarsToEnvironment();
Manager::Get()->GetMessageManager()->Open();
wxSetWorkingDirectory(m_Project->GetBasePath());
if (UseMake(target))
{
wxString cmd;
wxString make = CompilerFactory::Compilers[m_CompilerIdx]->GetPrograms().MAKE;
if (target)
cmd << make << _T(" -f ") << m_LastTempMakefile << _T(" clean_") << target->GetTitle();
else
cmd << make << _T(" -f ") << m_LastTempMakefile << _T(" clean");
m_Queue.Add(cmd);
return DoRunQueue();
}
else
{
DirectCommands dc(this, CompilerFactory::Compilers[m_CompilerIdx], m_Project, m_PageIndex);
wxArrayString clean = dc.GetCleanCommands(target, false);
Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Cleaning %s..."), target ? target->GetTitle().c_str() : m_Project->GetTitle().c_str());
for (unsigned int i = 0; i < clean.GetCount(); ++i)
{
wxRemoveFile(clean[i]);
}
Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Done."));
Manager::Get()->GetMessageManager()->Close();
}
return 0;
}
int CompilerGCC::DistClean(ProjectBuildTarget* target)
{
DoPrepareQueue();
if (!CompilerValid(target))
return -1;
if (CompilerFactory::CompilerIndexOK(m_CompilerIdx))
CompilerFactory::Compilers[m_CompilerIdx]->GetCustomVars().ApplyVarsToEnvironment();
m_Project->GetCustomVars().ApplyVarsToEnvironment();
Manager::Get()->GetMessageManager()->Open();
wxSetWorkingDirectory(m_Project->GetBasePath());
if (UseMake(target))
{
wxString cmd;
wxString make = CompilerFactory::Compilers[m_CompilerIdx]->GetPrograms().MAKE;
if (target)
cmd << make << _T(" -f ") << m_LastTempMakefile << _T(" distclean_") << target->GetTitle();
else
cmd << make << _T(" -f ") << m_LastTempMakefile << _T(" distclean");
m_Queue.Add(cmd);
return DoRunQueue();
}
else
{
DirectCommands dc(this, CompilerFactory::Compilers[m_CompilerIdx], m_Project, m_PageIndex);
wxArrayString clean = dc.GetCleanCommands(target, true);
Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Dist-cleaning %s..."), target ? target->GetTitle().c_str() : m_Project->GetTitle().c_str());
for (unsigned int i = 0; i < clean.GetCount(); ++i)
{
wxRemoveFile(clean[i]);
}
Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Done."));
Manager::Get()->GetMessageManager()->Close();
}
return 0;
}
int CompilerGCC::CreateDist()
{
DoPrepareQueue();
if (!CompilerValid())
return -1;
Manager::Get()->GetMessageManager()->Open();
wxString cmd;
if (UseMake())
{
wxString make = CompilerFactory::Compilers[m_CompilerIdx]->GetPrograms().MAKE;
cmd << make << _T(" -f ") << m_LastTempMakefile << _T(" dist");
m_Queue.Add(cmd);
return DoRunQueue();
}
else
wxMessageBox(_("\"Create distribution\" is only valid when using GNU \"make\"..."));
return -1;
}
void CompilerGCC::OnExportMakefile(wxCommandEvent& event)
{
if (!CompilerValid())
return;
wxString makefile = wxGetTextFromUser(_("Please enter the \"Makefile\" name:"), _("Export Makefile"), ProjectMakefile());
if (makefile.IsEmpty())
return;
Manager::Get()->GetMessageManager()->Open();
wxSetWorkingDirectory(m_Project->GetBasePath());
if (UseMake())
{
DoCreateMakefile(false, makefile);
}
else
{
MakefileGenerator generator(this, m_Project, makefile, m_PageIndex);
generator.CreateMakefile();
}
wxString msg;
msg.Printf(_("\"%s\" has been exported in the same directory as the project file."), makefile.c_str());
wxMessageBox(msg);
}
int CompilerGCC::Compile(ProjectBuildTarget* target)
{
DoClearErrors();
DoPrepareQueue();
if (!m_Project || !CompilerValid(target))
return -2;
if (CompilerFactory::CompilerIndexOK(m_CompilerIdx))
CompilerFactory::Compilers[m_CompilerIdx]->GetCustomVars().ApplyVarsToEnvironment();
m_Project->GetCustomVars().ApplyVarsToEnvironment();
Manager::Get()->GetMessageManager()->Open();
wxString cmd;
wxSetWorkingDirectory(m_Project->GetBasePath());
if (UseMake(target))
{
wxString make = CompilerFactory::Compilers[m_CompilerIdx]->GetPrograms().MAKE;
if (target)
cmd << make << _T(" -f ") << m_LastTempMakefile << _T(" ") << target->GetTitle();
else
cmd << make << _T(" -f ") << m_LastTempMakefile;
m_Queue.Add(cmd);
}
else
{
DirectCommands dc(this, CompilerFactory::Compilers[m_CompilerIdx], m_Project, m_PageIndex);
wxArrayString compile = dc.GetCompileCommands(target);
dc.AppendArray(compile, m_Queue);
}
return DoRunQueue();
}
int CompilerGCC::Rebuild(ProjectBuildTarget* target)
{
DoPrepareQueue();
if (!CompilerValid(target))
return -1;
if (CompilerFactory::CompilerIndexOK(m_CompilerIdx))
CompilerFactory::Compilers[m_CompilerIdx]->GetCustomVars().ApplyVarsToEnvironment();
m_Project->GetCustomVars().ApplyVarsToEnvironment();
Manager::Get()->GetMessageManager()->Open();
if (UseMake(target))
{
wxString cmd;
wxString make = CompilerFactory::Compilers[m_CompilerIdx]->GetPrograms().MAKE;
if (target)
{
cmd << make << _T(" -f ") << m_LastTempMakefile << _T(" clean_") << target->GetTitle();
m_Queue.Add(cmd);
cmd.Clear();
cmd << make << _T(" -f ") << m_LastTempMakefile << _T(" ") << target->GetTitle();
m_Queue.Add(cmd);
}
else
{
cmd << make << _T(" -f ") << m_LastTempMakefile << _T(" clean");
m_Queue.Add(cmd);
cmd.Clear();
cmd << make << _T(" -f ") << m_LastTempMakefile;
m_Queue.Add(cmd);
}
}
else
{
Clean(target);
Compile(target);
}
return DoRunQueue();
}
int CompilerGCC::CompileAll()
{
Manager::Get()->GetMessageManager()->Open();
DoPrepareMultiProjectCommand(mpjCompile);
DoPrepareQueue();
ClearLog();
ProjectBuildTarget* target = DoAskForTarget();
return Compile(target);
}
int CompilerGCC::RebuildAll()
{
Manager::Get()->GetMessageManager()->Open();
DoPrepareMultiProjectCommand(mpjRebuild);
DoPrepareQueue();
ClearLog();
ProjectBuildTarget* target = DoAskForTarget();
return Rebuild(target);
}
int CompilerGCC::KillProcess()
{
if (!m_Process || !m_Pid)
return -1;
wxKillError ret;
bool isdirect=(!UseMake());
m_Queue.Clear();
// Close input pipe
m_Process->CloseOutput();
ret = wxProcess::Kill(m_Pid, wxSIGTERM);
if(isdirect && ret!=wxKILL_OK)
{
// No need to tell the user about the errors - just keep him waiting.
Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Aborting..."));
}
else switch (ret)
{
case wxKILL_ACCESS_DENIED: wxMessageBox(_("Access denied")); break;
case wxKILL_NO_PROCESS: wxMessageBox(_("No process")); break;
case wxKILL_BAD_SIGNAL: wxMessageBox(_("Bad signal")); break;
case wxKILL_ERROR: wxMessageBox(_("Unspecified error")); break;
case wxKILL_OK:
default: Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Process killed..."));
}
return ret;
}
ProjectBuildTarget* CompilerGCC::GetBuildTargetForFile(ProjectFile* pf)
{
if (!pf)
return 0;
if (!pf->buildTargets.GetCount())
{
wxMessageBox(_("That file isn't assigned to any target."),
_("Information"), wxICON_INFORMATION);
return 0;
}
else if (pf->buildTargets.GetCount() == 1)
return m_Project->GetBuildTarget(pf->buildTargets[0]);
// belongs to two or more build targets
ProjectBuildTarget* bt = 0;
// if "All" is selected, ask for build target
if (m_HasTargetAll && m_TargetIndex == -1)
{
int idx = DoGUIAskForTarget();
if (idx == -1)
return 0;
bt = m_Project->GetBuildTarget(idx);
}
else // use the currently selected build target
bt = m_Project->GetBuildTarget(m_TargetIndex); // pick the selected target
return bt;
}
ProjectBuildTarget* CompilerGCC::GetBuildTargetForFile(const wxString& file)
{
ProjectFile* pf = m_Project ? m_Project->GetFileByFilename(file, true, false) : 0;
return GetBuildTargetForFile(pf);
}
int CompilerGCC::CompileFile(const wxString& file)
{
DoPrepareQueue();
if (!CompilerValid())
return -1;
Manager::Get()->GetMessageManager()->Open();
if (m_Project)
wxSetWorkingDirectory(m_Project->GetBasePath());
ProjectFile* pf = m_Project ? m_Project->GetFileByFilename(file, true, false) : 0;
ProjectBuildTarget* bt = GetBuildTargetForFile(pf);
bool useMake = UseMake(bt);
if (!pf)
{
// compile single file not belonging to a project
// switch to the default compiler
SwitchCompiler(CompilerFactory::GetDefaultCompilerIndex());
if (useMake)
{
wxMessageBox(_("That file doesn't belong to a project.\n"
"If you want to compile it as stand-alone, please use the \"Invoke compiler directly\" build method\n"
"(Settings->Compiler->Other->Build method)"),
_("Information"), wxICON_INFORMATION);
}
else
{
// get compile commands for file (always linked as console-executable)
DirectCommands dc(this, CompilerFactory::GetDefaultCompiler(), 0, m_PageIndex);
wxArrayString compile = dc.GetCompileSingleFileCommand(file);
dc.AppendArray(compile, m_Queue);
// apply global custom vars
CompilerFactory::GetDefaultCompiler()->GetCustomVars().ApplyVarsToEnvironment();
}
return DoRunQueue();
}
if (!bt)
return -2;
if (useMake)
{
wxFileName tmp = pf->GetObjName();
wxFileName o_file(bt->GetObjectOutput() + wxFILE_SEP_PATH + tmp.GetFullPath());
wxString fname = UnixFilename(o_file.GetFullPath());
MakefileGenerator mg(this, 0, _T(""), 0);
mg.ConvertToMakefileFriendly(fname, true);
// apply global custom vars
CompilerFactory::Compilers[bt->GetCompilerIndex()]->GetCustomVars().ApplyVarsToEnvironment();
wxString make = CompilerFactory::Compilers[m_CompilerIdx]->GetPrograms().MAKE;
m_Queue.Add(make + _T(" -f ") + m_LastTempMakefile + _T(" depend_") + bt->GetTitle() + _T("_DIRS")); // make the output dir
m_Queue.Add(make + _T(" -f ") + m_LastTempMakefile + _T(" ") + fname);
}
else
{
DirectCommands dc(this, CompilerFactory::Compilers[bt->GetCompilerIndex()], m_Project, m_PageIndex);
wxArrayString compile = dc.CompileFile(bt, pf);
dc.AppendArray(compile, m_Queue);
}
return DoRunQueue();
}
// events
void CompilerGCC::OnIdle(wxIdleEvent& event)
{
if (m_Process && ((PipedProcess*)m_Process)->HasInput())
event.RequestMore();
else
event.Skip();
}
void CompilerGCC::OnTimer(wxTimerEvent& event)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -