void ConfigurationManagerDlg::PopulateConfigurations() { //popuplate the configurations BuildMatrixPtr matrix = ManagerST::Get()->GetWorkspaceBuildMatrix(); if (!matrix) { return; } wxFlexGridSizer *mainSizer = dynamic_cast<wxFlexGridSizer*>(m_scrolledWindow->GetSizer()); if (!mainSizer) return; Freeze(); // remove old entries from the configuration table wxSizerItemList list = mainSizer->GetChildren(); for ( wxSizerItemList::Node *node = list.GetFirst(); node; node = node->GetNext() ) { wxSizerItem *current = node->GetData(); current->GetWindow()->Destroy(); } m_projSettingsMap.clear(); std::list<CSolitionConfigurationPtr> configs = matrix->GetConfigurations(); std::list<CSolitionConfigurationPtr>::iterator iter = configs.begin(); m_choiceConfigurations->Clear(); for (; iter != configs.end(); iter++) { m_choiceConfigurations->Append((*iter)->GetName()); } // append the 'New' & 'Delete' commands m_choiceConfigurations->Append(clCMD_NEW); m_choiceConfigurations->Append(clCMD_EDIT); int sel = m_choiceConfigurations->FindString(matrix->GetSelectedConfigurationName()); if (sel != wxNOT_FOUND) { m_choiceConfigurations->SetSelection(sel); } else if (m_choiceConfigurations->GetCount() > 2) { m_choiceConfigurations->SetSelection(2); } else { m_choiceConfigurations->Append(wxT("Debug")); m_choiceConfigurations->SetSelection(2); } // keep the current workspace configuration m_currentWorkspaceConfiguration = m_choiceConfigurations->GetStringSelection(); wxArrayString projects; ManagerST::Get()->GetProjectList(projects); projects.Sort(wxStringCmpFunc); for (size_t i=0; i<projects.GetCount(); i++) { wxString selConf = matrix->GetProjectSelectedConf(matrix->GetSelectedConfigurationName(), projects.Item(i)); AddEntry(projects.Item(i), selConf); } Thaw(); mainSizer->Fit(m_scrolledWindow); Layout(); }
void WorkspaceTab::OpenProjectSettings(const wxString& project) { if(m_dlg) { m_dlg->Raise(); return; } wxString projectName = project.IsEmpty() ? ManagerST::Get()->GetActiveProjectName() : project; wxString title(projectName); title << _(" Project Settings"); // Allow plugins to process this event first clCommandEvent openEvent(wxEVT_CMD_OPEN_PROJ_SETTINGS); openEvent.SetString(project); if(EventNotifier::Get()->ProcessEvent(openEvent)) { return; } // open the project properties dialog BuildMatrixPtr matrix = ManagerST::Get()->GetWorkspaceBuildMatrix(); #ifdef __WXMAC__ // On OSX we use a modal version of the project settings // since otherwise we get some weird focus issues when the project // settings dialog popups helper dialogs ProjectSettingsDlg dlg(clMainFrame::Get(), this, matrix->GetProjectSelectedConf(matrix->GetSelectedConfigurationName(), projectName), projectName, title); dlg.ShowModal(); #else // Find the project configuration name that matches the workspace selected configuration m_dlg = new ProjectSettingsDlg(clMainFrame::Get(), this, matrix->GetProjectSelectedConf(matrix->GetSelectedConfigurationName(), projectName), projectName, title); m_dlg->Show(); #endif // Mark this project as modified ProjectPtr proj = ManagerST::Get()->GetProject(projectName); if(proj) { proj->SetModified(true); } }
BuildConfigPtr clCxxWorkspace::GetProjBuildConf(const wxString& projectName, const wxString& confName) const { BuildMatrixPtr matrix = GetBuildMatrix(); if(!matrix) { return NULL; } wxString projConf(confName); if(projConf.IsEmpty()) { wxString workspaceConfig = matrix->GetSelectedConfigurationName(); projConf = matrix->GetProjectSelectedConf(workspaceConfig, projectName); } // Get the project setting and retrieve the selected configuration wxString errMsg; ProjectPtr proj = FindProjectByName(projectName, errMsg); if(proj) { ProjectSettingsPtr settings = proj->GetSettings(); if(settings) { return settings->GetBuildConfiguration(projConf, true); } } return NULL; }
void clCxxWorkspace::RemoveProjectFromBuildMatrix(ProjectPtr prj) { BuildMatrixPtr matrix = GetBuildMatrix(); wxString selConfName = matrix->GetSelectedConfigurationName(); std::list<WorkspaceConfigurationPtr> wspList = matrix->GetConfigurations(); std::list<WorkspaceConfigurationPtr>::iterator iter = wspList.begin(); for(; iter != wspList.end(); iter++) { WorkspaceConfiguration::ConfigMappingList prjList = (*iter)->GetMapping(); WorkspaceConfiguration::ConfigMappingList::iterator it = prjList.begin(); for(; it != prjList.end(); it++) { if((*it).m_project == prj->GetName()) { prjList.erase(it); break; } } (*iter)->SetConfigMappingList(prjList); matrix->SetConfiguration((*iter)); } // and set the configuration name matrix->SetSelectedConfigurationName(selConfName); // this will also reset the build matrix pointer SetBuildMatrix(matrix); }
void WorkspaceTab::OnConfigurationManager(wxCommandEvent& e) { wxUnusedVar(e); ConfigurationManagerDlg dlg(this); dlg.ShowModal(); BuildMatrixPtr matrix = ManagerST::Get()->GetWorkspaceBuildMatrix(); m_workspaceConfig->SetStringSelection(matrix->GetSelectedConfigurationName()); }
wxArrayString Project::GetIncludePaths() { wxArrayString paths; BuildMatrixPtr matrix = WorkspaceST::Get()->GetBuildMatrix(); if(!matrix) { return paths; } wxString workspaceSelConf = matrix->GetSelectedConfigurationName(); wxString projectSelConf = matrix->GetProjectSelectedConf(workspaceSelConf, GetName()); BuildConfigPtr buildConf = WorkspaceST::Get()->GetProjBuildConf(this->GetName(), projectSelConf); // for non custom projects, take the settings from the build configuration if(buildConf && !buildConf->IsCustomBuild()) { // Get the include paths and add them wxString projectIncludePaths = buildConf->GetIncludePath(); wxArrayString projectIncludePathsArr = wxStringTokenize(projectIncludePaths, wxT(";"), wxTOKEN_STRTOK); for(size_t i=0; i<projectIncludePathsArr.GetCount(); i++) { wxFileName fn; if(projectIncludePathsArr.Item(i) == wxT("..")) { fn = wxFileName(GetFileName().GetPath(), wxT("")); fn.RemoveLastDir(); } else if(projectIncludePathsArr.Item(i) == wxT(".")) { fn = wxFileName(GetFileName().GetPath(), wxT("")); } else { fn = projectIncludePathsArr.Item(i); if(fn.IsRelative()) { fn.MakeAbsolute(GetFileName().GetPath()); } } paths.Add( fn.GetFullPath() ); } // get the compiler options and add them wxString projectCompileOptions = buildConf->GetCompileOptions(); wxArrayString projectCompileOptionsArr = wxStringTokenize(projectCompileOptions, wxT(";"), wxTOKEN_STRTOK); for(size_t i=0; i<projectCompileOptionsArr.GetCount(); i++) { wxString cmpOption (projectCompileOptionsArr.Item(i)); cmpOption.Trim().Trim(false); // expand backticks, if the option is not a backtick the value remains // unchanged wxArrayString includePaths = DoBacktickToIncludePath(cmpOption); if(includePaths.IsEmpty() == false) paths.insert(paths.end(), includePaths.begin(), includePaths.end()); } } return paths; }
void clCxxWorkspace::CreateCompileCommandsJSON(JSONElement& compile_commands) const { BuildMatrixPtr matrix = clCxxWorkspaceST::Get()->GetBuildMatrix(); if(!matrix) return; wxString workspaceSelConf = matrix->GetSelectedConfigurationName(); clCxxWorkspace::ProjectMap_t::const_iterator iter = m_projects.begin(); for(; iter != m_projects.end(); ++iter) { BuildConfigPtr buildConf = iter->second->GetBuildConfiguration(); if(buildConf && buildConf->IsProjectEnabled() && !buildConf->IsCustomBuild() && buildConf->IsCompilerRequired()) { iter->second->CreateCompileCommandsJSON(compile_commands); } } }
void WorkspaceTab::DoWorkspaceConfig() { // Update the workspace configuration BuildMatrixPtr matrix = WorkspaceST::Get()->GetBuildMatrix(); std::list<WorkspaceConfigurationPtr> confs = matrix->GetConfigurations(); m_workspaceConfig->Freeze(); m_workspaceConfig->Enable(true); m_workspaceConfig->Clear(); for (std::list<WorkspaceConfigurationPtr>::iterator iter = confs.begin() ; iter != confs.end(); iter++) { m_workspaceConfig->Append((*iter)->GetName()); } if (m_workspaceConfig->GetCount() > 0) { m_workspaceConfig->SetStringSelection(matrix->GetSelectedConfigurationName()); } m_workspaceConfig->Append(OPEN_CONFIG_MGR_STR); m_workspaceConfig->Thaw(); clMainFrame::Get()->SelectBestEnvSet(); }
wxArrayString PluginManager::GetProjectCompileFlags(const wxString& projectName, bool isCppFile) { if(IsWorkspaceOpen() == false) return wxArrayString(); wxArrayString args; // Next apppend the user include paths wxString errMsg; // First, we need to find the currently active workspace configuration BuildMatrixPtr matrix = GetWorkspace()->GetBuildMatrix(); if(!matrix) { return wxArrayString(); } wxString workspaceSelConf = matrix->GetSelectedConfigurationName(); // Now that we got the selected workspace configuration, extract the related project configuration ProjectPtr proj = GetWorkspace()->FindProjectByName(projectName, errMsg); if(!proj) { return args; } wxString projectSelConf = matrix->GetProjectSelectedConf(workspaceSelConf, proj->GetName()); BuildConfigPtr dependProjbldConf = GetWorkspace()->GetProjBuildConf(proj->GetName(), projectSelConf); if(dependProjbldConf && dependProjbldConf->IsCustomBuild() == false) { // Get the include paths and add them wxString projectIncludePaths = dependProjbldConf->GetIncludePath(); wxArrayString projectIncludePathsArr = wxStringTokenize(projectIncludePaths, wxT(";"), wxTOKEN_STRTOK); for(size_t i = 0; i < projectIncludePathsArr.GetCount(); i++) { args.Add(wxString::Format(wxT("-I%s"), projectIncludePathsArr[i].c_str())); } // get the compiler options and add them wxString projectCompileOptions = dependProjbldConf->GetCompileOptions(); wxArrayString projectCompileOptionsArr = wxStringTokenize(projectCompileOptions, wxT(";"), wxTOKEN_STRTOK); for(size_t i = 0; i < projectCompileOptionsArr.GetCount(); i++) { wxString cmpOption(projectCompileOptionsArr.Item(i)); cmpOption.Trim().Trim(false); wxString tmp; // Expand backticks / $(shell ...) syntax supported by codelite if(cmpOption.StartsWith(wxT("$(shell "), &tmp) || cmpOption.StartsWith(wxT("`"), &tmp)) { cmpOption = tmp; tmp.Clear(); if(cmpOption.EndsWith(wxT(")"), &tmp) || cmpOption.EndsWith(wxT("`"), &tmp)) { cmpOption = tmp; } if(m_backticks.find(cmpOption) == m_backticks.end()) { // Expand the backticks into their value wxArrayString outArr; // Apply the environment before executing the command EnvSetter setter(EnvironmentConfig::Instance(), NULL, projectName); ProcUtils::SafeExecuteCommand(cmpOption, outArr); wxString expandedValue; for(size_t j = 0; j < outArr.size(); j++) { expandedValue << outArr.Item(j) << wxT(" "); } m_backticks[cmpOption] = expandedValue; cmpOption = expandedValue; } else { cmpOption = m_backticks.find(cmpOption)->second; } } args.Add(cmpOption); } // get the compiler preprocessor and add them as well wxString projectPreps = dependProjbldConf->GetPreprocessor(); wxArrayString projectPrepsArr = wxStringTokenize(projectPreps, wxT(";"), wxTOKEN_STRTOK); for(size_t i = 0; i < projectPrepsArr.GetCount(); i++) { args.Add(wxString::Format(wxT("-D%s"), projectPrepsArr[i].c_str())); } } return args; }
void OutputPane::OnBuildWindowDClick(const wxString &line, int lineno) { wxString fileName, strLineNumber; bool match = false; //get the selected compiler for the current line that was DClicked if(lineno >= (int)m_buildLineInfo.GetCount()){ return; } //find the project selected build configuration for the workspace selected //configuration wxString projectName = m_buildLineInfo.Item(lineno); if(projectName.IsEmpty()) return; BuildMatrixPtr matrix = ManagerST::Get()->GetWorkspaceBuildMatrix(); wxString projecBuildConf = matrix->GetProjectSelectedConf(matrix->GetSelectedConfigurationName(), projectName ); ProjectSettingsPtr settings = ManagerST::Get()->GetProject(projectName)->GetSettings(); if(!settings) { return; } BuildConfigPtr bldConf = settings->GetBuildConfiguration(projecBuildConf); if( !bldConf ) { return; } wxString cmpType = bldConf->GetCompilerType(); CompilerPtr cmp = BuildSettingsConfigST::Get()->GetCompiler(cmpType); if( !cmp ) { return; } long idx; //try to match an error pattern to the line RegexProcessor re(cmp->GetErrPattern()); cmp->GetErrFileNameIndex().ToLong(&idx); if(re.GetGroup(line, idx, fileName)) { //we found the file name, get the line number cmp->GetErrLineNumberIndex().ToLong(&idx); re.GetGroup(line, idx, strLineNumber); match = true; } //try to match warning pattern if(!match) { RegexProcessor re(cmp->GetWarnPattern()); cmp->GetWarnFileNameIndex().ToLong(&idx); if(re.GetGroup(line, idx, fileName)) { //we found the file name, get the line number cmp->GetWarnLineNumberIndex().ToLong(&idx); re.GetGroup(line, idx, strLineNumber); match = true; } } if(match) { long lineNumber = -1; strLineNumber.ToLong(&lineNumber); // open the file in the editor // get the project name that is currently being built wxString projName(wxEmptyString); if(lineno < (int)m_buildLineInfo.GetCount()) { projName = m_buildLineInfo.Item(lineno); } // if no project found, dont do anything if(projName.IsEmpty()) { return; } DirSaver ds; ProjectPtr pro = ManagerST::Get()->GetProject(projName); ::wxSetWorkingDirectory(pro->GetFileName().GetPath()); wxFileName fn(fileName); fn.MakeAbsolute(pro->GetFileName().GetPath()); ManagerST::Get()->OpenFile(fn.GetFullPath(), projName, lineNumber - 1 ); } }
void clCxxWorkspace::AddProjectToBuildMatrix(ProjectPtr prj) { if(!prj) { wxMessageBox(_("AddProjectToBuildMatrix was called with NULL project"), _("CodeLite"), wxICON_WARNING | wxOK); return; } BuildMatrixPtr matrix = GetBuildMatrix(); wxString selConfName = matrix->GetSelectedConfigurationName(); std::list<WorkspaceConfigurationPtr> wspList = matrix->GetConfigurations(); std::list<WorkspaceConfigurationPtr>::iterator iter = wspList.begin(); for(; iter != wspList.end(); iter++) { WorkspaceConfigurationPtr workspaceConfig = (*iter); WorkspaceConfiguration::ConfigMappingList prjList = workspaceConfig->GetMapping(); wxString wspCnfName = workspaceConfig->GetName(); ProjectSettingsCookie cookie; // getSettings is a bit misleading, since it actually create new instance which represents the layout // of the XML ProjectSettingsPtr settings = prj->GetSettings(); BuildConfigPtr prjBldConf = settings->GetFirstBuildConfiguration(cookie); BuildConfigPtr matchConf; if(!prjBldConf) { // the project does not have any settings, create new one and add it prj->SetSettings(settings); settings = prj->GetSettings(); prjBldConf = settings->GetFirstBuildConfiguration(cookie); matchConf = prjBldConf; } else { matchConf = prjBldConf; // try to locate the best match to add to the workspace while(prjBldConf) { wxString projBldConfName = prjBldConf->GetName(); if(wspCnfName == projBldConfName) { // we found a suitable match use it instead of the default one matchConf = prjBldConf; break; } prjBldConf = settings->GetNextBuildConfiguration(cookie); } } ConfigMappingEntry entry(prj->GetName(), matchConf->GetName()); prjList.push_back(entry); (*iter)->SetConfigMappingList(prjList); matrix->SetConfiguration((*iter)); } // and set the configuration name matrix->SetSelectedConfigurationName(selConfName); // this will also reset the build matrix pointer SetBuildMatrix(matrix); }
void CallGraph::OnShowCallGraph(wxCommandEvent& event) { // myLog("wxThread::IsMain(%d)", (int)wxThread::IsMain()); IConfigTool *config_tool = m_mgr->GetConfigTool(); config_tool->ReadObject(wxT("CallGraph"), &confData); if (!wxFileExists(GetGprofPath()) || !wxFileExists(GetDotPath())) return MessageBox(_T("Failed to locate required tools (gprof, dot). Please check the plugin settings."), wxICON_ERROR); Workspace *ws = m_mgr->GetWorkspace(); if (!ws) return MessageBox(_("Unable to get opened workspace."), wxICON_ERROR); wxFileName ws_cfn = ws->GetWorkspaceFileName(); wxString projectName = ws->GetActiveProjectName(); BuildMatrixPtr mtx = ws->GetBuildMatrix(); if (!mtx) return MessageBox(_("Unable to get current build matrix."), wxICON_ERROR); wxString build_config_name = mtx->GetSelectedConfigurationName(); BuildConfigPtr bldConf = ws->GetProjBuildConf(projectName, build_config_name); if (!bldConf) return MessageBox(_("Unable to get opened workspace."), wxICON_ERROR); wxString projOutputFn = bldConf->GetOutputFileName(); wxString projWorkingDir = bldConf->GetWorkingDirectory(); /* myLog("WorkspaceFileName = \"%s\"", ws_cfn.GetFullPath()); myLog("projectName \"%s\"", projectName); myLog("build_config_name = \"%s\"", build_config_name); myLog("projOutputFn = \"%s\"", projOutputFn); myLog("projWorkingDir = \"%s\"", projWorkingDir); */ wxFileName cfn(ws_cfn.GetPath(), projOutputFn); cfn.Normalize(); // base path const wxString base_path = ws_cfn.GetPath(); // check source binary exists wxString bin_fpath = cfn.GetFullPath(); if (!cfn.Exists()) { bin_fpath = wxFileSelector("Please select the binary to analyze", base_path, "", ""); if (bin_fpath.IsEmpty()) return MessageBox("selected binary was canceled", wxICON_ERROR); cfn.Assign(bin_fpath, wxPATH_NATIVE); } if (!cfn.IsFileExecutable()) return MessageBox("bin/exe isn't executable", wxICON_ERROR); // check 'gmon.out' file exists wxFileName gmon_cfn(base_path, GMON_FILENAME_OUT); if (!gmon_cfn.Exists()) gmon_cfn.Normalize(); wxString gmonfn = gmon_cfn.GetFullPath(); if (!gmon_cfn.Exists()) { gmonfn = wxFileSelector("Please select the gprof file", gmon_cfn.GetPath(), "gmon", "out"); if (gmonfn.IsEmpty()) return MessageBox("selected gprof was canceled", wxICON_ERROR); gmon_cfn.Assign(gmonfn, wxPATH_NATIVE); } wxString bin, arg1, arg2; bin = GetGprofPath(); arg1 = bin_fpath; arg2 = gmonfn; wxString cmdgprof = wxString::Format("%s %s %s", bin, arg1, arg2); // myLog("about to wxExecute(\"%s\")", cmdgprof); wxProcess *proc = new wxProcess(wxPROCESS_REDIRECT); // wxStopWatch sw; const int err = ::wxExecute(cmdgprof, wxEXEC_SYNC, proc); // on sync returns 0 (success), -1 (failure / "couldn't be started") // myLog("wxExecute() returned err %d, had pid %d", err, (int)proc->GetPid()); wxInputStream *process_is = proc->GetInputStream(); if (!process_is || !process_is->CanRead()) return MessageBox(_("wxProcess::GetInputStream() can't be opened, aborting"), wxICON_ERROR); // start parsing and writing to dot language file GprofParser pgp; pgp.GprofParserStream(process_is); // myLog("gprof done (read %d lines)", (int) pgp.lines.GetCount()); delete proc; ConfCallGraph conf; config_tool->ReadObject(wxT("CallGraph"), &conf); DotWriter dotWriter; // DotWriter dotWriter.SetLineParser(&(pgp.lines)); int suggestedThreshold = pgp.GetSuggestedNodeThreshold(); if (suggestedThreshold <= conf.GetTresholdNode()) { suggestedThreshold = conf.GetTresholdNode(); dotWriter.SetDotWriterFromDialogSettings(m_mgr); } else { dotWriter.SetDotWriterFromDetails(conf.GetColorsNode(), conf.GetColorsEdge(), suggestedThreshold, conf.GetTresholdEdge(), conf.GetHideParams(), conf.GetStripParams(), conf.GetHideNamespaces()); wxString suggest_msg = wxString::Format(_("The CallGraph plugin has suggested node threshold %d to speed-up the call graph creation. You can alter it on the call graph panel."), suggestedThreshold); MessageBox(suggest_msg, wxICON_INFORMATION); } dotWriter.WriteToDotLanguage(); // build output dir cfn.Assign(base_path, ""); cfn.AppendDir(CALLGRAPH_DIR); cfn.Normalize(); if (!cfn.DirExists()) cfn.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); cfn.SetFullName(DOT_FILENAME_TXT); wxString dot_fn = cfn.GetFullPath(); dotWriter.SendToDotAppOutputDirectory(dot_fn); cfn.SetFullName(DOT_FILENAME_PNG); wxString output_png_fn = cfn.GetFullPath(); // delete any existing PNG if (wxFileExists(output_png_fn)) wxRemoveFile(output_png_fn); wxString cmddot_ln; cmddot_ln << GetDotPath() << " -Tpng -o" << output_png_fn << " " << dot_fn; // myLog("wxExecute(\"%s\")", cmddot_ln); wxExecute(cmddot_ln, wxEXEC_SYNC); // myLog("dot done"); if (!wxFileExists(output_png_fn)) return MessageBox(_("Failed to open file CallGraph.png. Please check the project settings, rebuild the project and try again."), wxICON_INFORMATION); // show image and create table in the editor tab page uicallgraphpanel *panel = new uicallgraphpanel(m_mgr->GetEditorPaneNotebook(), m_mgr, output_png_fn, base_path, suggestedThreshold, &(pgp.lines)); wxString tstamp = wxDateTime::Now().Format(wxT(" %Y-%m-%d %H:%M:%S")); wxString title = wxT("Call graph for \"") + output_png_fn + wxT("\" " + tstamp); m_mgr->AddEditorPage(panel, title); }