void PSCustomBuildPage::Load(BuildConfigPtr buildConf) { m_checkEnableCustomBuild->SetValue(buildConf->IsCustomBuild()); m_textCtrlCustomBuildWD->SetValue(buildConf->GetCustomBuildWorkingDir()); m_dvListCtrlTargets->DeleteAllItems(); wxVector<wxVariant> cols; cols.clear(); cols.push_back(ProjectCustomBuildTragetDlg::CUSTOM_TARGET_BUILD); cols.push_back(buildConf->GetCustomBuildCmd()); m_dvListCtrlTargets->AppendItem(cols); cols.clear(); cols.push_back(ProjectCustomBuildTragetDlg::CUSTOM_TARGET_CLEAN); cols.push_back(buildConf->GetCustomCleanCmd()); m_dvListCtrlTargets->AppendItem(cols); cols.clear(); cols.push_back(ProjectCustomBuildTragetDlg::CUSTOM_TARGET_REBUILD); cols.push_back(buildConf->GetCustomRebuildCmd()); m_dvListCtrlTargets->AppendItem(cols); cols.clear(); cols.push_back(ProjectCustomBuildTragetDlg::CUSTOM_TARGET_COMPILE_SINGLE_FILE); cols.push_back(buildConf->GetSingleFileBuildCommand()); m_dvListCtrlTargets->AppendItem(cols); cols.clear(); cols.push_back(ProjectCustomBuildTragetDlg::CUSTOM_TARGET_PREPROCESS_FILE); cols.push_back(buildConf->GetPreprocessFileCommand()); m_dvListCtrlTargets->AppendItem(cols); // Initialize the custom build targets std::map<wxString, wxString> targets = buildConf->GetCustomTargets(); std::map<wxString, wxString>::iterator titer = targets.begin(); for(; titer != targets.end(); ++titer) { if(ProjectCustomBuildTragetDlg::IsPredefinedTarget(titer->first)) continue; cols.clear(); cols.push_back(titer->first); cols.push_back(titer->second); m_dvListCtrlTargets->AppendItem(cols); } m_dlg->SetCustomBuildEnabled(m_checkEnableCustomBuild->IsChecked()); }
void CustomBuildRequest::Process(IManager* manager) { wxString cmd; wxString errMsg; wxStringMap_t om; clCxxWorkspace* w(manager->GetWorkspace()); EnvironmentConfig* env(manager->GetEnv()); ProjectPtr proj = w->FindProjectByName(m_info.GetProject(), errMsg); if(!proj) { AppendLine(_("Cant find project: ") + m_info.GetProject()); return; } // Notify plugins that a compile process is going to start clBuildEvent event(wxEVT_BUILD_STARTING); event.SetProjectName(proj->GetName()); 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; } SendStartMsg(); BuildConfigPtr bldConf = w->GetProjBuildConf(m_info.GetProject(), m_info.GetConfiguration()); if(!bldConf) { wxLogMessage(wxString::Format(wxT("Failed to find build configuration for project '%s' and configuration '%s'"), m_info.GetProject().c_str(), m_info.GetConfiguration().c_str())); return; } // try the special targets first: bool isClean(false); if(m_info.GetCustomBuildTarget() == wxT("Build")) { cmd = bldConf->GetCustomBuildCmd(); } else if(m_info.GetCustomBuildTarget() == wxT("Clean")) { cmd = bldConf->GetCustomCleanCmd(); isClean = true; } else if(m_info.GetCustomBuildTarget() == wxT("Rebuild")) { cmd = bldConf->GetCustomRebuildCmd(); } else if(m_info.GetCustomBuildTarget() == wxT("Compile Single File")) { cmd = bldConf->GetSingleFileBuildCommand(); } else if(m_info.GetCustomBuildTarget() == wxT("Preprocess File")) { cmd = bldConf->GetPreprocessFileCommand(); } // if still no luck, try with the other custom targets if(cmd.IsEmpty()) { std::map<wxString, wxString> targets = bldConf->GetCustomTargets(); std::map<wxString, wxString>::iterator iter = targets.find(m_info.GetCustomBuildTarget()); if(iter != targets.end()) { cmd = iter->second; } } 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; } // Working directory: // By default we use the project path ////////////////////////////////////////////////////// DirSaver ds; // first set the path to the project working directory ::wxSetWorkingDirectory(proj->GetFileName().GetPath()); // If a working directory was specified, use it instead wxString wd = bldConf->GetCustomBuildWorkingDir(); wd.Trim().Trim(false); wxString filename; if(manager->GetActiveEditor()) { filename = manager->GetActiveEditor()->GetFileName().GetFullPath(); } if(wd.IsEmpty()) { // use the project path wd = proj->GetFileName().GetPath(); } else { // expand macros from the working directory wd = ExpandAllVariables(wd, clCxxWorkspaceST::Get(), proj->GetName(), bldConf->GetName(), filename); } { // Ensure that the path to the working directory exist wxFileName fnwd(wd, ""); if(!fnwd.DirExists()) { fnwd.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); } } ::wxSetWorkingDirectory(wd); // Print message to the build tab AppendLine(wxString::Format(_("MESSAGE: Entering directory `%s'\n"), wd.c_str())); // Command handling: ////////////////////////////////////////////////////// // expand the variables of the command cmd = ExpandAllVariables(cmd, w, m_info.GetProject(), m_info.GetConfiguration(), filename); // in case our configuration includes post/pre build commands // we generate a makefile to include them as well and we update // the build command bool bCommandAltered = DoUpdateCommand(manager, cmd, proj, bldConf, isClean); #ifdef __WXMSW__ // Windows CD command requires the paths to be backslashe if(cmd.Find(wxT("cd ")) != wxNOT_FOUND) cmd.Replace(wxT("/"), wxT("\\")); #endif // Wrap the build command in the shell, so it will be able // to perform 'chain' commands like // cd SOMEWHERE && make && ... // Dont wrap the command if it was altered previously if(!bCommandAltered) { WrapInShell(cmd); } // print the build command AppendLine(cmd + wxT("\n")); wxString configName(m_info.GetConfiguration()); // also, send another message to the main frame, indicating which project is being built // and what configuration wxString text; if(isClean) { text << wxGetTranslation(CLEAN_PROJECT_PREFIX); } else { text << wxGetTranslation(BUILD_PROJECT_PREFIX); } text << m_info.GetProject() << wxT(" - ") << configName << wxT(" ]----------\n"); AppendLine(text); // Avoid Unicode chars coming from the compiler by setting LC_ALL to "C" om["LC_ALL"] = "C"; EnvSetter environment(env, &om, proj->GetName()); 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; } }