Пример #1
0
void ShellCommand::DoSetWorkingDirectory(ProjectPtr proj, bool isCustom, bool isFileOnly)
{
    //when using custom build, user can select different working directory
    if (proj) {
        if (isCustom) {
            //first set the path to the project working directory
            ::wxSetWorkingDirectory(proj->GetFileName().GetPath());

            BuildConfigPtr buildConf = WorkspaceST::Get()->GetProjBuildConf(m_info.GetProject(), m_info.GetConfiguration());
            if (buildConf) {
                wxString wd = buildConf->GetCustomBuildWorkingDir();
                if (wd.IsEmpty()) {
                    // use the project path
                    wd = proj->GetFileName().GetPath();
                } else {
                    // expand macros from path
                    wd = ExpandAllVariables(wd, WorkspaceST::Get(), proj->GetName(), buildConf->GetName(), wxEmptyString);
                }
                ::wxSetWorkingDirectory(wd);
            }
        } else {
            if(m_info.GetProjectOnly() || isFileOnly) {
                //first set the path to the project working directory
                ::wxSetWorkingDirectory(proj->GetFileName().GetPath());
            }
        }
    }
}
Пример #2
0
void ReconcileProjectFiletypesDlg::SetData()
{
    ProjectPtr proj = ManagerST::Get()->GetProject(m_projname);
    wxCHECK_RET(proj, "Can't find a Project with the supplied name");

    wxString topleveldir, types;
    wxArrayString ignorefiles, excludes, regexes;
    proj->GetReconciliationData(topleveldir, types, ignorefiles, excludes, regexes);

    if (topleveldir.empty()) {
        topleveldir = proj->GetFileName().GetPath();
    }
    wxFileName tld(topleveldir);
    if ( tld.IsRelative() ) {
        tld.MakeAbsolute( proj->GetFileName().GetPath() );
    }
    m_dirPickerToplevel->SetPath(tld.GetFullPath());

    if (types.empty()) {
        types << "cpp;c;h;hpp;xrc;wxcp;fbp";
    }
    m_textExtensions->ChangeValue(types);

    m_listIgnoreFiles->Clear();
    m_listIgnoreFiles->Append(ignorefiles);

    m_listExclude->Clear();
    m_listExclude->Append(excludes);

    m_listCtrlRegexes->DeleteAllItems();
    for (size_t n = 0; n < regexes.GetCount(); ++n) {
        SetRegex(regexes[n]);
    }
}
Пример #3
0
void ReconcileProjectFiletypesDlg::OnIgnoreBrowse(wxCommandEvent& WXUNUSED(event))
{
    ProjectPtr proj = ManagerST::Get()->GetProject(m_projname);
    wxCHECK_RET(proj, "Can't find a Project with the supplied name");

    wxString topleveldir, types;
    wxArrayString ignorefiles, excludes, regexes;
    proj->GetReconciliationData(topleveldir, types, ignorefiles, excludes, regexes);

    if (topleveldir.empty()) {
        topleveldir = proj->GetFileName().GetPath();
    }
    
    wxFileName tld(topleveldir);
    if ( tld.IsRelative() ) {
        tld.MakeAbsolute( proj->GetFileName().GetPath() );
    }
    wxString new_exclude = wxDirSelector(_("Select a directory to ignore:"), tld.GetFullPath(), wxDD_DEFAULT_STYLE, wxDefaultPosition, this);

    if (!new_exclude.empty()) {
        wxFileName fn = wxFileName::DirName(new_exclude);
        fn.MakeRelativeTo(topleveldir);
        new_exclude = fn.GetFullPath();

        if (m_listExclude->FindString(new_exclude) == wxNOT_FOUND) {
            m_listExclude->Append(new_exclude);
        }
    }
}
Пример #4
0
void MemCheckPlugin::CheckProject(const wxString& projectName)
{
    if(m_terminal.IsRunning()) {
        ::wxMessageBox(_("Another instance is already running. Please stop it before executing another one"),
                       "CodeLite",
                       wxICON_WARNING | wxCENTER | wxOK);
        return;
    }

    wxString errMsg;
    ProjectPtr project = m_mgr->GetWorkspace()->FindProjectByName(projectName, errMsg);
    wxString path = project->GetFileName().GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);

    wxString wd;
    wxString command = m_mgr->GetProjectExecutionCommand(projectName, wd);

    DirSaver ds;
    EnvSetter envGuard(m_mgr->GetEnv());
    wxSetWorkingDirectory(path);
    wxSetWorkingDirectory(wd);
    m_mgr->AppendOutputTabText(kOutputTab_Output, _("Launching MemCheck...\n"));
    m_mgr->AppendOutputTabText(kOutputTab_Output,
                               wxString() << _("Working directory is set to: ") << ::wxGetCwd() << "\n");
    m_mgr->AppendOutputTabText(kOutputTab_Output,
                               wxString() << "MemCheck command: " << m_memcheckProcessor->GetExecutionCommand(command)
                                          << "\n");

    wxString cmd = m_memcheckProcessor->GetExecutionCommand(command);
    m_terminal.ExecuteConsole(cmd, "", true, wxString::Format("MemCheck: %s", projectName));
}
Пример #5
0
void LLDBDebuggerPlugin::OnDebugStart(clDebugEvent& event)
{
    event.Skip();
    return;
    
    if ( ::PromptForYesNoDialogWithCheckbox(_("Would you like to use LLDB debugger as your primary debugger?"), "UseLLDB") != wxID_YES ) {
        event.Skip();
        return;
    }
    
    // Get the executable to debug
    wxString errMsg;
    ProjectPtr pProject = WorkspaceST::Get()->FindProjectByName(event.GetProjectName(), errMsg);
    if ( !pProject ) {
        event.Skip();
        return;
    }
    
    wxSetWorkingDirectory ( pProject->GetFileName().GetPath() );
    BuildConfigPtr bldConf = WorkspaceST::Get()->GetProjBuildConf ( pProject->GetName(), wxEmptyString );
    if ( !bldConf ) {
        event.Skip();
        return;
    }
    
    // Show the terminal
    ShowTerminal("LLDB Console Window");
    if ( m_debugger.Start("/home/eran/devl/TestArea/TestHang/Debug/TestHang") ) {
        m_debugger.AddBreakpoint("main");
        m_debugger.ApplyBreakpoints();
        m_debugger.Run("/tmp/in", "/tmp/out", "/tmp/err", wxArrayString(), wxArrayString(), ::wxGetCwd());
    }
}
Пример #6
0
//------------------------------------------------------------
void SnipWiz::OnClassWizard(wxCommandEvent& e)
{
    TemplateClassDlg dlg(m_mgr->GetTheApp()->GetTopWindow(), this, m_mgr);

    wxString errMsg, projectPath, projectName;
    TreeItemInfo item = m_mgr->GetSelectedTreeItemInfo(TreeFileView);

    projectName = m_mgr->GetWorkspace()->GetActiveProjectName();
    if(m_mgr->GetWorkspace()) {
        if(item.m_item.IsOk() && item.m_itemType == ProjectItem::TypeVirtualDirectory) {
            projectPath = item.m_fileName.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
        } else {
            ProjectPtr proj = m_mgr->GetWorkspace()->FindProjectByName(projectName, errMsg);
            if(proj) projectPath = proj->GetFileName().GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
        }
    }

    dlg.SetCurEol(GetEOLByOS());
    dlg.SetPluginPath(m_pluginPath);
    dlg.SetProjectPath(projectPath);
    dlg.ShowModal();

    if(dlg.GetModified()) {
        m_modified = true;
    }
}
Пример #7
0
wxString QMakePlugin::DoGetBuildCommand(const wxString &project, const wxString &config, bool projectOnly)
{
    wxUnusedVar ( config );

    wxString errMsg;
    ProjectPtr p = m_mgr->GetWorkspace()->FindProjectByName(project, errMsg);
    if ( !p ) {
        return wxEmptyString;
    }
    
    BuildConfigPtr bldConf = WorkspaceST::Get()->GetProjBuildConf(project, config);
    

    wxString cmd;

    if ( !projectOnly ) {
        cmd << wxT("@cd \"") << p->GetFileName().GetPath() << wxT("\" && ");
    }
    
    // fix: replace all Windows like slashes to POSIX
    wxString command = bldConf->GetCompiler()->GetTool("MAKE");
    command.Replace(wxT("\\"), wxT("/"));
    
    cmd << command << wxT(" \"") << p->GetName() << wxT(".mk\"");
    return cmd;
}
Пример #8
0
wxString QMakePlugin::DoGetBuildCommand(const wxString& project, const wxString& config, bool projectOnly)
{
    wxUnusedVar(config);

    wxString errMsg;
    ProjectPtr p = m_mgr->GetWorkspace()->FindProjectByName(project, errMsg);
    if(!p) { return wxEmptyString; }

    BuildConfigPtr bldConf = clCxxWorkspaceST::Get()->GetProjBuildConf(project, config);

    wxString cmd;

    wxString projectMakefile;
    projectMakefile << p->GetName() << ".mk";
    ::WrapWithQuotes(projectMakefile);
    projectMakefile.Replace("\\", "/");

    if(!projectOnly) {
        // part of a greater makefile, use $(MAKE)
        cmd << wxT("@cd \"") << p->GetFileName().GetPath() << wxT("\" && ");
        cmd << "$(MAKE) -f " << projectMakefile;
    } else {
        // project only
        cmd = bldConf->GetCompiler()->GetTool("MAKE");
        if(!cmd.Contains("-f")) { cmd << " -f "; }
        cmd << " " << projectMakefile;
    }
    return cmd;
}
Пример #9
0
void PSCustomBuildPage::OnBrowseCustomBuildWD(wxCommandEvent& event)
{
    DirSaver ds;

    // Since all paths are relative to the project, set the working directory to the
    // current project path
    ProjectPtr p = ManagerST::Get()->GetProject(m_projectName);
    if(p) {
        wxSetWorkingDirectory(p->GetFileName().GetPath());
    }

    wxFileName fn(m_textCtrlCustomBuildWD->GetValue());
    wxString initPath(wxEmptyString);

    if(fn.DirExists()) {
        fn.MakeAbsolute();
        initPath = fn.GetFullPath();
    }

    wxString new_path =
        wxDirSelector(_("Select working directory:"), initPath, wxDD_DEFAULT_STYLE, wxDefaultPosition, this);
    if(new_path.IsEmpty() == false) {
        m_textCtrlCustomBuildWD->SetValue(new_path);
    }
}
Пример #10
0
void QMakePlugin::OnExportMakefile(wxCommandEvent& event)
{
    if(m_qmakeProcess) return;

    QmakePluginData::BuildConfPluginData bcpd;

    ProjectPtr pProj = m_mgr->GetSelectedProject();
    CHECK_PTR_RET(pProj);

    BuildConfigPtr bldConf = pProj->GetBuildConfiguration();
    CHECK_PTR_RET(bldConf);

    wxString project = pProj->GetName();
    wxString config = bldConf->GetName();

    if(!DoGetData(project, config, bcpd)) {
        event.Skip();
        return;
    }

    if(bcpd.m_enabled) {
        // This project/configuration is qmake project
        QMakeProFileGenerator generator(m_mgr, project, config);

        // Regenerate the .pro file
        generator.Generate();

        // run qmake
        wxString qmake_exe = m_conf->Read(wxString::Format(wxT("%s/qmake"), bcpd.m_qmakeConfig.c_str()));
        wxString qmakespec = m_conf->Read(wxString::Format(wxT("%s/qmakespec"), bcpd.m_qmakeConfig.c_str()));
        wxString qtdir = m_conf->Read(wxString::Format(wxT("%s/qtdir"), bcpd.m_qmakeConfig.c_str()));

        // Create qmake comand
        wxString qmake_exe_line;
        qmake_exe.Trim().Trim(false);
        qmakespec.Trim().Trim(false);

        // Set QTDIR
        DirSaver ds;
        {

            wxString errMsg;
            ProjectPtr p = m_mgr->GetWorkspace()->FindProjectByName(project, errMsg);
            if(!p) { return; }

            qmake_exe_line << wxT("\"") << qmake_exe << wxT("\" -spec ") << qmakespec << wxT(" ")
                           << generator.GetProFileName();
            wxStringMap_t om;
            om.insert(std::make_pair("QTDIR", qtdir));
            EnvSetter envGuard(NULL, &om, project, config);
            m_mgr->ClearOutputTab(kOutputTab_Build);
            m_mgr->AppendOutputTabText(kOutputTab_Build, wxString() << "-- " << qmake_exe_line << "\n");
            m_qmakeProcess =
                ::CreateAsyncProcess(this, qmake_exe_line, IProcessCreateDefault, p->GetFileName().GetPath());
        }
    }
    event.Skip();
}
NewClassDlg::NewClassDlg(wxWindow* parent, IManager* mgr)
    : NewClassBaseDlg(parent)
    , m_selectedItem(wxNOT_FOUND)
    , m_mgr(mgr)
{

    NewClassDlgData data;
    EditorConfigST::Get()->ReadObject(wxT("NewClassDlgData"), &data);

    m_checkBoxCopyable->SetValue(data.GetFlags() & NewClassDlgData::NonCopyable);
    m_checkBoxImplPureVirtual->SetValue(data.GetFlags() & NewClassDlgData::ImplAllPureVirtualFuncs);
    m_checkBoxImplVirtual->SetValue(data.GetFlags() & NewClassDlgData::ImplAllVirtualFuncs);
    m_checkBoxInline->SetValue(data.GetFlags() & NewClassDlgData::FileIniline);
    m_checkBoxHpp->SetValue(data.GetFlags() & NewClassDlgData::HppHeader);
    m_checkBoxSingleton->SetValue(data.GetFlags() & NewClassDlgData::Singleton);
    m_checkBoxVirtualDtor->SetValue(data.GetFlags() & NewClassDlgData::VirtualDtor);
    m_checkBoxPragmaOnce->SetValue(data.GetFlags() & NewClassDlgData::UsePragma);

    // set two columns to our list
    m_listCtrl1->InsertColumn(0, _("Name"));
    m_listCtrl1->InsertColumn(1, _("Access"));
    m_listCtrl1->InsertColumn(2, _("File"));

    wxString vdPath;
    TreeItemInfo item = mgr->GetSelectedTreeItemInfo(TreeFileView);
    if(item.m_item.IsOk() && item.m_itemType == ProjectItem::TypeVirtualDirectory) {
        wxString path = VirtualDirectorySelectorDlg::DoGetPath(m_mgr->GetTree(TreeFileView), item.m_item, false);
        if(path.IsEmpty() == false) {
            m_textCtrlVD->ChangeValue(path);
        }
    }

    // set the class path to be the active project path
    wxString errMsg;
    if(m_mgr->GetWorkspace()) {
        wxString start_path;
        if(item.m_item.IsOk() && item.m_itemType == ProjectItem::TypeVirtualDirectory) {
            m_basePath = item.m_fileName.GetPath(wxPATH_GET_VOLUME);

        } else {

            wxString projname = m_mgr->GetWorkspace()->GetActiveProjectName();
            ProjectPtr proj = m_mgr->GetWorkspace()->FindProjectByName(projname, errMsg);
            if(proj) {
                m_basePath = proj->GetFileName().GetPath(wxPATH_GET_VOLUME);
            }
        }
    }

    DoUpdateGeneratedPath();

    GetSizer()->Layout();
    m_textClassName->SetFocus();

    GetSizer()->Fit(this);
    CentreOnParent();
}
Пример #12
0
wxString MemCheckPlugin::PrepareCommand(const wxString& projectName, wxString& wd)
{
    wd.clear();
    if(!clCxxWorkspaceST::Get()->IsOpen()) { return ""; }

    ProjectPtr proj = clCxxWorkspaceST::Get()->GetProject(projectName);
    if(!proj) {
        clWARNING() << "MemCheckPlugin::PrepareCommand(): could not find project:" << projectName;
        return wxEmptyString;
    }

    BuildConfigPtr bldConf = clCxxWorkspaceST::Get()->GetProjBuildConf(projectName, wxEmptyString);
    if(!bldConf) {
        clWARNING() << "MemCheckPlugin::PrepareCommand(): failed to find project configuration for project:"
                    << projectName;
        return wxEmptyString;
    }

    wxString projectPath = proj->GetFileName().GetPath();

    // expand variables
    wxString cmd = bldConf->GetCommand();
    cmd = MacroManager::Instance()->Expand(cmd, NULL, projectName);

    wxString cmdArgs = bldConf->GetCommandArguments();
    cmdArgs = MacroManager::Instance()->Expand(cmdArgs, NULL, projectName);

    // Execute command & cmdArgs
    wd = bldConf->GetWorkingDirectory();
    wd = MacroManager::Instance()->Expand(wd, NULL, projectName);

    wxFileName workingDir(wd, "");
    if(workingDir.IsRelative()) { workingDir.MakeAbsolute(projectPath); }

    wxFileName fileExe(cmd);
    if(fileExe.IsRelative()) { fileExe.MakeAbsolute(workingDir.GetPath()); }
    fileExe.Normalize();

#ifdef __WXMSW__
    if(!fileExe.Exists() && fileExe.GetExt().IsEmpty()) {
        // Try with .exe
        wxFileName withExe(fileExe);
        withExe.SetExt("exe");
        if(withExe.Exists()) { fileExe = withExe; }
    }
#endif
    wd = workingDir.GetPath();
    cmd = fileExe.GetFullPath();

    cmd = ::WrapWithQuotes(cmd);
    cmd << " " << cmdArgs;
    clDEBUG() << "Command to execute:" << cmd;
    clDEBUG() << "Working directory:" << wd;
    return cmd;
}
Пример #13
0
wxFileName CMakePlugin::GetProjectDirectory(const wxString& projectName) const
{
    const clCxxWorkspace* workspace = m_mgr->GetWorkspace();
    wxASSERT(workspace);

    wxString errMsg;
    const ProjectPtr proj = workspace->FindProjectByName(projectName, errMsg);
    wxASSERT(proj);

    return wxFileName::DirName(proj->GetFileName().GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME));
}
Пример #14
0
NewVirtualFolderDlg::NewVirtualFolderDlg(wxWindow* parent, const wxString& currentVD)
    : NewVirtualFolderDlgBase(parent)
{
    m_checkBoxCreateOnDisk->SetValue( clConfig::Get().Read("CreateVirtualFoldersOnDisk", false) );
    wxString project_name = currentVD.BeforeFirst(':');
    wxString vd_path = currentVD.AfterFirst(':');
    vd_path.Replace(":", wxFILE_SEP_PATH);
    wxString errmsg;
    ProjectPtr proj = WorkspaceST::Get()->FindProjectByName(project_name, errmsg);
    wxString projectPath = proj->GetFileName().GetPath();
    m_basePath = wxFileName(projectPath + wxFILE_SEP_PATH + vd_path, "").GetPath();
    WindowAttrManager::Load(this, "NewVirtualFolderDlg");
}
Пример #15
0
void QMakePlugin::OnBuildStarting(clBuildEvent& event)
{
    // call Skip() to allow the standard compilation to take place
    event.Skip();

    QmakePluginData::BuildConfPluginData bcpd;
    wxString  project = event.GetProjectName();
    wxString  config  = event.GetConfigurationName();

    if ( !DoGetData(project, config, bcpd) ) {
        return;
    }

    if ( !bcpd.m_enabled ) {
        return;
    }

    wxString errMsg;
    ProjectPtr p = m_mgr->GetWorkspace()->FindProjectByName(project, errMsg);
    if ( !p ) {
        return;
    }
    QMakeProFileGenerator generator(m_mgr, project, config);

    // regenrate the .pro file
    bool needRegeneration = generator.Generate();

    wxString qmake_exe = m_conf->Read(wxString::Format(wxT("%s/qmake"),     bcpd.m_qmakeConfig.c_str()));
    wxString qmakespec = m_conf->Read(wxString::Format(wxT("%s/qmakespec"), bcpd.m_qmakeConfig.c_str()));
    wxString qtdir     = m_conf->Read(wxString::Format(wxT("%s/qtdir"),     bcpd.m_qmakeConfig.c_str()));

    // Create qmake comand
    wxString qmake_exe_line;
    qmake_exe.Trim().Trim(false);
    qmakespec.Trim().Trim(false);

    // Set QTDIR
    DirSaver ds;
    {

        wxSetWorkingDirectory ( p->GetFileName().GetPath(wxPATH_GET_SEPARATOR|wxPATH_GET_VOLUME) );
        wxSetEnv(wxT("QTDIR"), qtdir);
        qmake_exe_line << wxT("\"") << qmake_exe << wxT("\" -spec ") << qmakespec << wxT(" ") << generator.GetProFileName();

        if ( needRegeneration ) {
            wxArrayString output;
            ProcUtils::SafeExecuteCommand(qmake_exe_line, output);
        }

    }
}
Пример #16
0
void CMakePlugin::OnProjectContextMenu(clContextMenuEvent& event)
{
    event.Skip();
    CHECK_COND_RET(clCxxWorkspaceST::Get()->IsOpen());

    ProjectPtr p = GetSelectedProject();
    CHECK_COND_RET(p);

    BuildConfigPtr buildConf = p->GetBuildConfiguration();
    CHECK_COND_RET(buildConf);

    CHECK_COND_RET(buildConf->GetBuilder()->GetName() == "CMake");

    // The selected project is using CMake builder
    // Add our context menu
    wxMenu* menu = event.GetMenu()->GetParent(); // We want to attach this action to the main menu, not the subclass
    CHECK_PTR_RET(menu);

    const wxMenuItemList& items = menu->GetMenuItems();

    size_t buildPos = 0;
    size_t settingsPos = 0;
    size_t curpos = 0;
    wxMenuItemList::const_iterator iter = items.begin();
    for(; iter != items.end(); ++iter) {
        if((*iter)->GetId() == XRCID("build_project")) {
            buildPos = curpos;
        }
        if((*iter)->GetId() == XRCID("project_properties")) {
            settingsPos = curpos;
        }
        ++curpos;
    }

    wxFileName projectFile = p->GetFileName();
    projectFile.SetFullName(CMAKELISTS_FILE);
    if(projectFile.FileExists()) {
        wxMenuItem* item = new wxMenuItem(NULL, XRCID("cmake_open_cmake"), _("Open CMakeLists.txt"));
        item->SetBitmap(m_mgr->GetStdIcons()->LoadBitmap("cmake"));
        menu->Insert(settingsPos, item);
    }

    menu->Insert(buildPos, XRCID("cmake_run_cmake"), _("Run CMake"));
    menu->InsertSeparator(buildPos);
    menu->Insert(buildPos, XRCID("cmake_export_cmakelists"), _("Export CMakeLists.txt"));
    menu->Bind(wxEVT_MENU, &CMakePlugin::OnRunCMake, this, XRCID("cmake_run_cmake"));
    menu->Bind(wxEVT_MENU, &CMakePlugin::OnOpenCMakeLists, this, XRCID("cmake_open_cmake"));
    menu->Bind(wxEVT_MENU, &CMakePlugin::OnExportCMakeLists, this, XRCID("cmake_export_cmakelists"));
}
Пример #17
0
void CMakePlugin::OnOpenCMakeLists(wxCommandEvent& event)
{
    bool openWorkspaceCMakeLists = (event.GetId() == XRCID("cmake_open_active_project_cmake"));
    wxFileName cmakelists;
    if(openWorkspaceCMakeLists) {
        cmakelists = clCxxWorkspaceST::Get()->GetFileName();
    } else {
        ProjectPtr proj = GetSelectedProject();
        CHECK_PTR_RET(proj);
        cmakelists = proj->GetFileName();
    }

    cmakelists.SetFullName(CMAKELISTS_FILE);
    if(cmakelists.FileExists()) {
        m_mgr->OpenFile(cmakelists.GetFullPath());
    }
}
Пример #18
0
void PSDebuggerPage::OnBrowseForDebuggerPath(wxCommandEvent& event)
{
    wxString debugger_path = ::wxFileSelector(_("Select debugger:"));

    if ( !debugger_path.IsEmpty() ) {
        wxString errMsg;
        ProjectPtr proj = WorkspaceST::Get()->FindProjectByName(m_dlg->GetProjectName(), errMsg);
        if ( proj ) {
            wxFileName fnDebuggerPath( debugger_path );
            wxString project_path = proj->GetFileName().GetPath();
            if ( fnDebuggerPath.MakeRelativeTo( project_path ) ) {
                debugger_path = fnDebuggerPath.GetFullPath();
            }
        }
        m_textCtrlDebuggerPath->ChangeValue( debugger_path );
        m_dlg->SetIsDirty(true);
    }
}
Пример #19
0
void ReconcileProjectFiletypesDlg::GetData(wxString& toplevelDir, wxString& types, wxArrayString& ignoreFiles, wxArrayString& excludePaths, wxArrayString& regexes) const
{
    toplevelDir = m_dirPickerToplevel->GetPath();
    types = m_textExtensions->GetValue();
    ignoreFiles = m_listIgnoreFiles->GetStrings();
    excludePaths = m_listExclude->GetStrings();
    regexes = GetRegexes();

    // While we're here, save the current data
    ProjectPtr proj = ManagerST::Get()->GetProject(m_projname);
    wxCHECK_RET(proj, "Can't find a Project with the supplied name");
    
    wxFileName relTopLevelDir(toplevelDir);
    if( relTopLevelDir.IsAbsolute() ) {
        relTopLevelDir.MakeRelativeTo( proj->GetFileName().GetPath() );
    }
    
    proj->SetReconciliationData(relTopLevelDir.GetFullPath(wxPATH_UNIX), types, ignoreFiles, excludePaths, regexes);
}
Пример #20
0
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 );
	}
}
Пример #21
0
//do the actual cleanup
void CleanRequest::Process(IManager *manager)
{
    wxString cmd;
    wxString errMsg;
    wxStringMap_t om;

    BuildSettingsConfig *bsc(manager ? manager->GetBuildSettingsConfigManager() : BuildSettingsConfigST::Get());
    BuildManager *       bm(manager ? manager->GetBuildManager() : BuildManagerST::Get());
    Workspace *          w(manager ? manager->GetWorkspace() : WorkspaceST::Get());


    ProjectPtr proj = w->FindProjectByName(m_info.GetProject(), errMsg);
    if (!proj) {
        AppendLine(_("Cant find project: ") + m_info.GetProject());
        return;
    }
    wxString             pname (proj->GetName());

    //BuilderPtr builder = bm->GetBuilder(wxT("GNU makefile for g++/gcc"));
    BuilderPtr builder = bm->GetSelectedBuilder();
    if (m_info.GetProjectOnly()) {
        cmd = builder->GetPOCleanCommand(m_info.GetProject(), m_info.GetConfiguration());
    } else {
        cmd = builder->GetCleanCommand(m_info.GetProject(), m_info.GetConfiguration());
    }

    if ( cmd.IsEmpty() ) {
        AppendLine(_("Sorry, there is no 'Clean' command available\n"));
        return;
    }

    BuildConfigPtr bldConf = w->GetProjBuildConf(m_info.GetProject(), m_info.GetConfiguration());
    if(bldConf) {
        wxString cmpType = bldConf->GetCompilerType();
        CompilerPtr cmp = bsc->GetCompiler(cmpType);
        if(cmp) {
            wxString value( cmp->GetPathVariable() );
            if(value.Trim().Trim(false).IsEmpty() == false) {
                wxLogMessage(wxString::Format(wxT("Setting PATH to '%s'"), value.c_str()));
                om[wxT("PATH")] = value.Trim().Trim(false);
            }
        }
    } else {
        AppendLine(_("Sorry, couldn't find the Build configuration\n"));
        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;
    }
    
    SendStartMsg();
    // Expand the variables of the command
    cmd = ExpandAllVariables(cmd, w, m_info.GetProject(), m_info.GetConfiguration(), wxEmptyString);
    WrapInShell(cmd);
    DirSaver ds;
    DoSetWorkingDirectory(proj, false, false);

    if (m_info.GetProjectOnly() ) {
        //need to change directory to project dir
        wxSetWorkingDirectory(proj->GetFileName().GetPath());
    }
    //print the build command
    AppendLine(cmd + wxT("\n"));

    // print the prefix message of the build start. This is important since the parser relies
    // on this message
    if(m_info.GetProjectOnly()) {
        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(CLEAN_PROJECT_PREFIX) << m_info.GetProject() << wxT(" - ") << configName << wxT(" ]");
        text << wxT("----------\n");
        AppendLine(text);
    }

    //apply environment settings
    EnvSetter env(NULL, &om, proj->GetName());
    m_proc = CreateAsyncProcess(this, cmd);
    if ( !m_proc ) {

        //remove environment settings applied
        wxString message;
        message << _("Failed to start clean process, command: ") << cmd << _(", process terminated with exit code: 0");
        AppendLine(message);
        return;
    }
}
Пример #22
0
void ContinuousBuild::DoBuild(const wxString& fileName)
{
	PRINT_MESSAGE(wxT("DoBuild\n"));
	// Make sure a workspace is opened
	if (!m_mgr->IsWorkspaceOpen()) {
		PRINT_MESSAGE(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: {
			PRINT_MESSAGE(wxT("Non source file\n"));
			return;
		}
	}

	wxString projectName = m_mgr->GetProjectNameByFile(fileName);
	if(projectName.IsEmpty()) {
		PRINT_MESSAGE(wxT("Project name is empty\n"));
		return;
	}
	
	wxString errMsg;
	ProjectPtr project = m_mgr->GetSolution()->FindProjectByName(projectName, errMsg);
	if(!project){
		PRINT_MESSAGE(wxT("Could not find project for file\n"));
		return;
	}

	// get the selected configuration to be build
	BuildConfigPtr bldConf = m_mgr->GetSolution()->GetProjBuildConf( project->GetName(), wxEmptyString );
	if ( !bldConf ) {
		PRINT_MESSAGE(wxT("Failed to locate build configuration\n"));
		return;
	}

	BuilderPtr builder = m_mgr->GetBuildManager()->GetBuilder( wxT( "GNU makefile for g++/gcc" ) );
	if(!builder){
		PRINT_MESSAGE(wxT("Failed to located builder\n"));
		return;
	}

	// Only normal file builds are supported
	if(bldConf->IsCustomBuild()){
		PRINT_MESSAGE(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;
	}
	
	PRINT_MESSAGE(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("Compiling %s..."), wxFileName(fileName).GetFullName().c_str()), 0);

	// Add this file to the UI queue
	m_view->AddFile(fileName);
}
Пример #23
0
void wxFormBuilder::DoCreateWxFormBuilderProject(const wxFBItemInfo& data)
{
	// add new virtual folder to the selected virtual directory
	wxString formbuilderVD;
	formbuilderVD = data.virtualFolder.BeforeFirst(wxT(':'));

	m_mgr->CreateGroupFolder(formbuilderVD, wxT("formbuilder"));
	wxString templateFile(m_mgr->GetInstallDirectory() + wxT("/templates/formbuilder/"));     //todo,todo

	switch (data.kind) {
	default:
	case wxFBItemKind_Dialog:
		templateFile << wxT("DialogTemplate.fbp");
		break;
	case wxFBItemKind_Frame:
		templateFile << wxT("FrameTemplate.fbp");
		break;
	case wxFBItemKind_Panel:
		templateFile << wxT("PanelTemplate.fbp");
		break;
	case wxFBItemKind_Dialog_With_Buttons:
		templateFile << wxT("DialogTemplateWithButtons.fbp");
		break;
	}

	wxFileName tmplFile(templateFile);
	if (!tmplFile.FileExists()) {
		wxMessageBox(wxString::Format(wxT("Cant find wxFormBuilder template file '%s'"), tmplFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING);
		return;
	}

	// place the files under the VD's project owner
	wxString err_msg;
	wxString project = data.virtualFolder.BeforeFirst(wxT(':'));
	ProjectPtr proj = m_mgr->GetSolution()->FindProjectByName(project, err_msg);
	if (proj) {
		wxString files_path = proj->GetFileName().GetPath(wxPATH_GET_SEPARATOR|wxPATH_GET_VOLUME);
		// copy the file to here
		wxFileName fbpFile(files_path, data.file + wxT(".fbp"));
		if (!wxCopyFile(tmplFile.GetFullPath(), fbpFile.GetFullPath())) {
			wxMessageBox(wxString::Format(wxT("Failed to copy tempalte file to '%s'"), fbpFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING);
			return;
		}
		// open the file, and replace expand its macros
		wxString content;
		if (!ReadFileWithConversion(fbpFile.GetFullPath().c_str(), content)) {
			wxMessageBox(wxString::Format(wxT("Failed to read file '%s'"), fbpFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING);
			return;
		}

		content.Replace(wxT("$(BaseFileName)"), data.file);
		content.Replace(wxT("$(ProjectName)"), data.className);
		content.Replace(wxT("$(Title)"), data.title);
		content.Replace(wxT("$(ClassName)"), data.className);

		if (!WriteFileWithBackup(fbpFile.GetFullPath().c_str(), content, false)) {
			wxMessageBox(wxString::Format(wxT("Failed to write file '%s'"), fbpFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING);
			return;
		}

		// add the file to the project
		wxArrayString paths;
		paths.Add(fbpFile.GetFullPath());
		m_mgr->AddFilesToGroupFolder(project + wxT(":formbuilder"), paths);

		// // first we launch wxFB with the -g flag set
		wxString genFileCmd;
		genFileCmd << GetWxFBPath() << wxT(" -g ") << fbpFile.GetFullPath();

		wxArrayString dummy, filesToAdd;
		ProcUtils::SafeExecuteCommand(genFileCmd, dummy);

		wxFileName cppFile(fbpFile.GetPath(), data.file + wxT(".cpp"));
		wxFileName headerFile(fbpFile.GetPath(), data.file + wxT(".h"));

		if (cppFile.FileExists()) {
			filesToAdd.Add(cppFile.GetFullPath());
		}

		if (headerFile.FileExists()) {
			filesToAdd.Add(headerFile.GetFullPath());
		}

		if (filesToAdd.GetCount()) {
			m_mgr->AddFilesToGroupFolder(data.virtualFolder, filesToAdd);
		}

		DoLaunchWxFB(fbpFile.GetFullPath());
	}
}
Пример #24
0
void DebugCoreDumpDlg::Initialize()
{
    DebugCoreDumpInfo info;
    EditorConfigST::Get()->ReadObject(wxT("DebugCoreDumpDlg"), &info);

    m_choiceDebuggers->Append(DebuggerMgr::Get().GetAvailableDebuggers());
    if(m_choiceDebuggers->GetCount()) {
        m_choiceDebuggers->SetSelection(0);
    }
    if(m_choiceDebuggers->GetCount() > (unsigned int)info.GetSelectedDbg()) {
        m_choiceDebuggers->SetSelection(info.GetSelectedDbg());
    }

    m_Core->Append(info.GetCoreFilepaths());
    if(m_Core->GetCount() > 0) {
        m_Core->SetSelection(0);
    }

    m_WD->Append(info.GetWds());
    if(m_WD->GetCount() > 0) {
        m_WD->SetSelection(0);
    }

    m_ExeFilepath->Append(info.GetExeFilepaths());
    if(m_ExeFilepath->GetCount() > 0) {
        m_ExeFilepath->SetSelection(0);
    } else {
        // determine the executable to debug:
        // - If the 'Program' field is set - we use it
        // - Else we use the project's output name
        wxString activename, conf;
        ManagerST::Get()->GetActiveProjectAndConf(activename, conf);
        BuildConfigPtr buildConf = WorkspaceST::Get()->GetProjBuildConf(activename, conf);
        if(buildConf) {
            // expand all macros with their values
            wxString programToDebug = buildConf->GetCommand();
            programToDebug.Trim().Trim(false);

            if(programToDebug.IsEmpty()) {
                programToDebug = buildConf->GetOutputFileName();
            }
            wxString outputFile =
                MacroManager::Instance()->Expand(programToDebug, PluginManager::Get(), activename, conf);

            if(m_ExeFilepath->Append(outputFile) != wxNOT_FOUND) {
                m_ExeFilepath->SetSelection(0);
            }

            // determine the working directory
            // if we have a working directory set in the project settings, use it (if it is not an
            // absolute path, it will be appended to the project's path)
            wxString projWD = MacroManager::Instance()->Expand(
                buildConf->GetWorkingDirectory(), PluginManager::Get(), activename, conf);
            projWD.Trim().Trim(false);
            wxString wd;
            ProjectPtr proj = ManagerST::Get()->GetProject(activename);
            if(proj) {
                if(projWD.IsEmpty() || !wxFileName(projWD).IsAbsolute()) {
                    wxString basePath = proj->GetFileName().GetPath();
                    wd << basePath << wxFileName::GetPathSeparator();
                }
            }
            wd << projWD;

            if(m_WD->Insert(wd, 0) != wxNOT_FOUND) {
                m_WD->SetSelection(0);
            }
        }
    }
}
Пример #25
0
bool clCxxWorkspace::OpenWorkspace(const wxString& fileName, wxString& errMsg)
{
    CloseWorkspace();
    m_buildMatrix.Reset(NULL);
    wxFileName workSpaceFile(fileName);
    if(workSpaceFile.FileExists() == false) {
        errMsg = wxString::Format(wxT("Could not open workspace file: '%s'"), fileName.c_str());
        return false;
    }

    m_fileName = workSpaceFile;
    m_doc.Load(m_fileName.GetFullPath());
    if(!m_doc.IsOk()) {
        errMsg = wxT("Corrupted workspace file");
        return false;
    }

    // Make sure we have the WORKSPACE/.codelite folder exists
    {
        wxLogNull nolog;
        wxMkdir(GetPrivateFolder());
    }

    SetWorkspaceLastModifiedTime(GetFileLastModifiedTime());

    // This function sets the working directory to the workspace directory!
    ::wxSetWorkingDirectory(m_fileName.GetPath());

    // Load all projects
    wxXmlNode* child = m_doc.GetRoot()->GetChildren();
    std::vector<wxXmlNode*> removedChildren;
    wxString tmperr;
    while(child) {
        if(child->GetName() == wxT("Project")) {
            wxString projectPath = child->GetPropVal(wxT("Path"), wxEmptyString);

            if(!DoAddProject(projectPath, errMsg)) {
                tmperr << wxString::Format(wxT("Error occured while loading project: \"%s\"\nCodeLite has removed the "
                                               "faulty project from the workspace\n"),
                                           projectPath.c_str());
                removedChildren.push_back(child);
            }
        } else if((child->GetName() == wxT("WorkspaceParserPaths")) || (child->GetName() == wxT("WorkspaceParserMacros"))) {
            wxString swtlw = wxEmptyString;
            swtlw = XmlUtils::ReadString(m_doc.GetRoot(), "SWTLW");
            if(swtlw.CmpNoCase("yes") == 0) {
                LocalWorkspaceST::Get()->SetParserFlags(LocalWorkspaceST::Get()->GetParserFlags() |
                                                        LocalWorkspace::EnableSWTLW);
                SyncToLocalWorkspaceSTParserPaths();
                SyncToLocalWorkspaceSTParserMacros();
            }
        }
        child = child->GetNext();
    }

    // Delete the faulty projects
    for(size_t i = 0; i < removedChildren.size(); i++) {
        wxXmlNode* ch = removedChildren.at(i);
        ch->GetParent()->RemoveChild(ch);
        delete ch;
    }

    errMsg.Clear();
    TagsManager* mgr = TagsManagerST::Get();
    mgr->CloseDatabase();
    mgr->OpenDatabase(GetTagsFileName().GetFullPath());

    // Update the build matrix
    DoUpdateBuildMatrix();

    // Notify about active project changed
    ProjectPtr activeProject = GetActiveProject();
    if(activeProject) {
        clProjectSettingsEvent evt(wxEVT_ACTIVE_PROJECT_CHANGED);
        evt.SetProjectName(activeProject->GetName());
        evt.SetFileName(activeProject->GetFileName().GetFullPath());
        EventNotifier::Get()->AddPendingEvent(evt);
    }
    return true;
}
Пример #26
0
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;
    }
}
Пример #27
0
void LLDBPlugin::OnDebugStart(clDebugEvent& event)
{
    if(event.GetDebuggerName() != LLDB_DEBUGGER_NAME) {
        event.Skip();
        return;
    }

    CL_DEBUG("LLDB: Initial working directory is restored to: " + ::wxGetCwd());
    {
        // Get the executable to debug
        wxString errMsg;
        ProjectPtr pProject = clCxxWorkspaceST::Get()->FindProjectByName(event.GetProjectName(), errMsg);
        if(!pProject) {
            ::wxMessageBox(wxString() << _("Could not locate project: ") << event.GetProjectName(), "LLDB Debugger",
                           wxICON_ERROR | wxOK | wxCENTER);
            return;
        }

        DirSaver ds;
        ::wxSetWorkingDirectory(pProject->GetFileName().GetPath());

        // Load LLDB settings
        LLDBSettings settings;
        settings.Load();

        BuildConfigPtr bldConf = clCxxWorkspaceST::Get()->GetProjBuildConf(pProject->GetName(), wxEmptyString);
        if(!bldConf) {
            ::wxMessageBox(wxString() << _("Could not locate the requested buid configuration"), "LLDB Debugger",
                           wxICON_ERROR | wxOK | wxCENTER);
            return;
        }

        // Launch codelite-lldb now.
        // Choose wether we need to debug a local or remote target

        // Honour the project settings
        if(bldConf->GetIsDbgRemoteTarget()) {
            long nPort(wxNOT_FOUND);
            bldConf->GetDbgHostPort().ToCLong(&nPort);
            settings.SetProxyIp(bldConf->GetDbgHostName());
            settings.SetProxyPort(nPort);
            settings.EnableFlag(kLLDBOptionUseRemoteProxy, true);
        }

        if(!settings.IsUsingRemoteProxy()) {
            // Not using a remote proxy, launch the debug server
            if(!m_connector.LaunchLocalDebugServer(settings.GetDebugserver())) { return; }
        }

        // Determine the executable to debug, working directory and arguments
        EnvSetter env(NULL, NULL, pProject ? pProject->GetName() : wxString(), bldConf->GetName());
        wxString exepath = bldConf->GetCommand();
        wxString args;
        wxString workingDirectory;
        // Get the debugging arguments.
        if(bldConf->GetUseSeparateDebugArgs()) {
            args = bldConf->GetDebugArgs();
        } else {
            args = bldConf->GetCommandArguments();
        }

        workingDirectory = ::ExpandVariables(bldConf->GetWorkingDirectory(), pProject, m_mgr->GetActiveEditor());
        exepath = ::ExpandVariables(exepath, pProject, m_mgr->GetActiveEditor());

        {
            DirSaver ds;
            ::wxSetWorkingDirectory(workingDirectory);
            wxFileName execToDebug(exepath);
            if(execToDebug.IsRelative()) { execToDebug.MakeAbsolute(); }

            //////////////////////////////////////////////////////////////////////
            // Launch terminal for IO redirection
            //////////////////////////////////////////////////////////////////////
            TerminateTerminal();

            bool isWindows = wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS;
            if(!bldConf->IsGUIProgram() && !isWindows) {
                m_debuggerTerminal.Launch(clDebuggerTerminalPOSIX::MakeExeTitle(execToDebug.GetFullPath(), args));

                if(m_debuggerTerminal.IsValid()) {
                    CL_DEBUG("Successfully launched terminal %s", m_debuggerTerminal.GetTty());

                } else {
                    // Failed to launch it...
                    DoCleanup();
                    ::wxMessageBox(_("Failed to start terminal for debugger"), "CodeLite",
                                   wxICON_ERROR | wxOK | wxCENTER);
                    return;
                }
            }

            if(!isWindows) { workingDirectory = ::wxGetCwd(); }

            CL_DEBUG("LLDB: Using executable : " + execToDebug.GetFullPath());
            CL_DEBUG("LLDB: Working directory: " + workingDirectory);

            //////////////////////////////////////////////////////////////////////
            // Initiate the connection to codelite-lldb
            //////////////////////////////////////////////////////////////////////

            LLDBConnectReturnObject retObj;
            if(m_connector.Connect(retObj, settings, 5)) {

                // Get list of breakpoints and add them ( we will apply them later on )
                BreakpointInfo::Vec_t gdbBps;
                m_mgr->GetAllBreakpoints(gdbBps);

                // remove all breakpoints from previous session
                m_connector.DeleteAllBreakpoints();

                // apply the serialized breakpoints
                m_connector.AddBreakpoints(gdbBps);

                // Setup pivot folder if needed
                SetupPivotFolder(retObj);

                LLDBCommand startCommand;
                startCommand.FillEnvFromMemory();

                // If the current platform is Windows, use the executable as it appears in the project settings
                startCommand.SetExecutable(isWindows ? exepath : execToDebug.GetFullPath());

                startCommand.SetCommandArguments(args);
                // Since we called 'wxSetWorkingDirectory' earlier, wxGetCwd() should give use the
                // correct working directory for the debugger
                startCommand.SetWorkingDirectory(workingDirectory);
                startCommand.SetRedirectTTY(m_debuggerTerminal.GetTty());
                m_connector.Start(startCommand);

                clDebugEvent cl_event(wxEVT_DEBUG_STARTED);
                EventNotifier::Get()->AddPendingEvent(cl_event);

            } else {
                // Failed to connect, notify and perform cleanup
                DoCleanup();
                wxString message;
                message << _("Could not connect to codelite-lldb at '")
                        << (settings.IsUsingRemoteProxy() ? settings.GetTcpConnectString()
                                                          : m_connector.GetConnectString())
                        << "'";
                ::wxMessageBox(message, "CodeLite", wxICON_ERROR | wxOK | wxCENTER);
                return;
            }
        }
    }
    CL_DEBUG("LLDB: Working directory is restored to: " + ::wxGetCwd());
}
Пример #28
0
void MacBundler::showSettingsDialogFor(ProjectPtr project)
{
    // project->GetSettings()->GetGlobalSettings();
    // project->GetSettings()->GetBuildConfiguration(name);

    ProjectSettingsCookie cookie;

    ProjectSettingsPtr settings = project->GetSettings();
    if(not settings) {
        wxMessageBox(_("Cannot continue, impossible to access project settings."));
        return;
    }

    std::map<wxString, BuildConfigPtr> configs;
    wxArrayString choices;

    // TODO: allow putting the rules in the config root and not in every target
    BuildConfigPtr buildConfig = settings->GetFirstBuildConfiguration(cookie);
    while(buildConfig) {

        configs[buildConfig->GetName()] = buildConfig;
        choices.Add(buildConfig->GetName());

        buildConfig = settings->GetNextBuildConfiguration(cookie);
    }

    bool accepted = false;
    bool generateInfoPlistFile = false;
    bool generateIcon = false;

    wxArrayString targetsToSet;

    wxString iconName(wxT("icon.icns"));

    {
        BundleConfigDialog configDlg(project, m_mgr->GetTheApp()->GetTopWindow(), choices, m_mgr);
        configDlg.ShowModal();
        accepted = configDlg.getResults(targetsToSet, &generateInfoPlistFile, &generateIcon);
        iconName = configDlg.getIconDestName();

        if(accepted and generateInfoPlistFile) {
            wxFileName projPath = project->GetFileName();
            projPath.SetFullName(wxT(""));
            const wxString projectDirName = projPath.GetFullPath();
            const wxString infoPlistFile = projectDirName + wxT("/Info.plist");

            if(wxFileExists(infoPlistFile)) {
                int out = wxMessageBox(wxString::Format(_("The following file:\n%s\nalready exists, overwrite it?\n"),
                                                        infoPlistFile.c_str()),
                                       _("Warning"),
                                       wxYES_NO);
                if(out == wxYES) {
                    wxTextFile file;
                    file.Open(infoPlistFile);
                    file.Clear();
                    configDlg.writeInfoPlistFile(file);
                    file.Close();
                }
            } else {
                wxTextFile file;
                if(not file.Create(infoPlistFile)) {
                    wxMessageBox(_("Could not create Info.plist file\n") + infoPlistFile);
                } else {
                    configDlg.writeInfoPlistFile(file);
                    file.Close();
                }
            }

            if(wxFileExists(infoPlistFile)) {
                // FIXME: if the file was already present, it will be added again and appear twice in the file tree
                wxArrayString paths;
                paths.Add(infoPlistFile);
                m_mgr->CreateVirtualDirectory(project->GetName(), wxT("osx"));
                m_mgr->AddFilesToVirtualFolder(project->GetName() + wxT(":osx"), paths);
            }
        } // nend if create info.plist

        if(accepted and generateIcon) {
            wxString iconSourcePath = configDlg.getIconSource();
            if(not iconSourcePath.IsEmpty()) {
                // sips doesn't like double slashes in path names
                iconSourcePath.Replace(wxT("//"), wxT("/"));

                wxFileName projPath = project->GetFileName();
                projPath.SetFullName(wxT(""));
                const wxString projectDirName = projPath.GetFullPath();
                wxString iconFileDest = projectDirName + wxT("/") + configDlg.getIconDestName();

                // sips doesn't like double slashes in path names
                iconFileDest.Replace(wxT("//"), wxT("/"));

                std::cout << "Copying icon '" << iconSourcePath.mb_str() << "' to project\n";

                if(iconSourcePath.EndsWith(wxT(".icns"))) {
                    if(not wxCopyFile(iconSourcePath, iconFileDest)) {
                        wxMessageBox(_("Sorry, could not copy icon"));
                    }
                } else {
                    wxString cmd =
                        wxT("sips -s format icns '") + iconSourcePath + wxT("' --out '") + iconFileDest + wxT("'");
                    std::cout << cmd.mb_str() << std::endl;
                    wxExecute(cmd, wxEXEC_SYNC);
                    if(not wxFileExists(iconFileDest)) {
                        wxMessageBox(_("Sorry, could not convert selected icon to icns format"));
                    }
                }

                // FIXME: if the file was already present, it will be added again and appear twice in the file tree
                if(wxFileExists(iconFileDest)) {
                    wxArrayString paths;
                    paths.Add(iconFileDest);
                    m_mgr->CreateVirtualDirectory(project->GetName(), wxT("osx"));
                    m_mgr->AddFilesToVirtualFolder(project->GetName() + wxT(":osx"), paths);
                }
            } // end if icon not null
        }     // end if generate icon
    }
    if(!accepted) return;

    for(int n = 0; n < targetsToSet.GetCount(); n++) {
        BuildConfigPtr buildConfig = configs[targetsToSet[n]];

        wxString outputFileName = buildConfig->GetOutputFileName();
        wxString output = wxT("$(ProjectName).app/Contents/MacOS/$(ProjectName)");
        buildConfig->SetOutputFileName(wxT("$(IntermediateDirectory)/") + output);
        buildConfig->SetCommand(wxT("./") + output);

        if(generateInfoPlistFile or generateIcon) {
            // get existing custom makefile targets, if any
            wxString customPreBuild = buildConfig->GetPreBuildCustom();

            wxString deps, rules;
            deps = customPreBuild.BeforeFirst(wxT('\n'));
            rules = customPreBuild.AfterFirst(wxT('\n'));

            rules = rules.Trim();
            rules = rules.Trim(false);

            deps = deps.Trim();
            deps = deps.Trim(false);

            if(generateInfoPlistFile) {
                // augment existing rules with new rules to manage Info.plist file
                deps.Append(wxT(" $(IntermediateDirectory)/$(ProjectName).app/Contents/Info.plist"));
                rules.Append(wxString(wxT("\n## rule to copy the Info.plist file into the bundle\n")) +
                             wxT("$(IntermediateDirectory)/$(ProjectName).app/Contents/Info.plist: Info.plist\n") +
                             wxT("\tmkdir -p '$(IntermediateDirectory)/$(ProjectName).app/Contents' && cp -f "
                                 "Info.plist '$(IntermediateDirectory)/$(ProjectName).app/Contents/Info.plist'"));
            }
            if(generateIcon) {
                // augment existing rules with new rules to manage Info.plist file
                deps.Append(wxT(" $(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/") + iconName);
                rules.Append(
                    wxT("\n## rule to copy the icon file into the "
                        "bundle\n$(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/") +
                    iconName + wxT(": ") + iconName +
                    wxT("\n\tmkdir -p '$(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/' && cp -f ") +
                    iconName + wxT(" '$(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/") + iconName +
                    wxT("'"));
            }

            // set the new rules
            rules = rules.Trim();
            rules = rules.Trim(false);
            deps = deps.Trim();
            deps = deps.Trim(false);

            wxString prebuilstep;
            prebuilstep << deps << wxT("\n");
            prebuilstep << rules;
            prebuilstep << wxT("\n");

            // Set the content only if there is real content to add
            wxString tmpPreBuildStep(prebuilstep);
            tmpPreBuildStep.Trim().Trim(false);
            buildConfig->SetPreBuildCustom(prebuilstep);
        } // end if

        settings->SetBuildConfiguration(buildConfig);

    } // end for

    project->SetSettings(settings);
}
Пример #29
0
wxString MacroManager::DoExpand(
    const wxString& expression, IManager* manager, const wxString& project, bool applyEnv, const wxString& confToBuild)
{
    wxString expandedString(expression);
    clCxxWorkspace* workspace = clCxxWorkspaceST::Get();

    if(!manager) {
        manager = clGetManager();
    }

    size_t retries = 0;
    wxString dummyname, dummfullname;
    while((retries < 5) && FindVariable(expandedString, dummyname, dummyname)) {
        ++retries;
        DollarEscaper de(expandedString);
        if(workspace) {
            expandedString.Replace(wxT("$(WorkspaceName)"), workspace->GetName());
            ProjectPtr proj = workspace->GetProject(project);
            if(proj) {
                wxString prjBuildWd;
                wxString prjRunWd;

                wxString project_name(proj->GetName());

                // make sure that the project name does not contain any spaces
                project_name.Replace(wxT(" "), wxT("_"));

                BuildConfigPtr bldConf = workspace->GetProjBuildConf(proj->GetName(), confToBuild);
                if(bldConf) {
                    bool isCustom = bldConf->IsCustomBuild();
                    expandedString.Replace(wxT("$(ProjectOutputFile)"), bldConf->GetOutputFileName());
                    // An alias
                    expandedString.Replace(wxT("$(OutputFile)"), bldConf->GetOutputFileName());

                    // When custom build project, use the working directory set in the
                    // custom build tab, otherwise use the project file's path
                    prjBuildWd = isCustom ? bldConf->GetCustomBuildWorkingDir() : proj->GetFileName().GetPath();
                    prjRunWd = bldConf->GetWorkingDirectory();
                }

                expandedString.Replace(wxT("$(ProjectWorkingDirectory)"), prjBuildWd);
                expandedString.Replace(wxT("$(ProjectRunWorkingDirectory)"), prjRunWd);
                expandedString.Replace(wxT("$(ProjectPath)"), proj->GetFileName().GetPath());
                expandedString.Replace(wxT("$(WorkspacePath)"), workspace->GetWorkspaceFileName().GetPath());
                expandedString.Replace(wxT("$(ProjectName)"), project_name);

                if(bldConf) {
                    expandedString.Replace(wxT("$(IntermediateDirectory)"), bldConf->GetIntermediateDirectory());
                    expandedString.Replace(wxT("$(ConfigurationName)"), bldConf->GetName());
                    expandedString.Replace(wxT("$(OutDir)"), bldConf->GetIntermediateDirectory());
                }

                if(expandedString.Find(wxT("$(ProjectFiles)")) != wxNOT_FOUND)
                    expandedString.Replace(wxT("$(ProjectFiles)"), proj->GetFiles());

                if(expandedString.Find(wxT("$(ProjectFilesAbs)")) != wxNOT_FOUND)
                    expandedString.Replace(wxT("$(ProjectFilesAbs)"), proj->GetFiles(true));
            }
        }

        if(manager) {
            IEditor* editor = manager->GetActiveEditor();
            if(editor) {
                wxFileName fn(editor->GetFileName());

                expandedString.Replace(wxT("$(CurrentFileName)"), fn.GetName());

                wxString fpath(fn.GetPath());
                fpath.Replace(wxT("\\"), wxT("/"));
                expandedString.Replace(wxT("$(CurrentFilePath)"), fpath);
                expandedString.Replace(wxT("$(CurrentFileExt)"), fn.GetExt());
                expandedString.Replace(wxT("$(CurrentFileFullName)"), fn.GetFullName());

                wxString ffullpath(fn.GetFullPath());
                ffullpath.Replace(wxT("\\"), wxT("/"));
                expandedString.Replace(wxT("$(CurrentFileFullPath)"), ffullpath);
                expandedString.Replace(wxT("$(CurrentSelection)"), editor->GetSelection());
                if(expandedString.Find(wxT("$(CurrentSelectionRange)")) != wxNOT_FOUND) {
                    int start = editor->GetSelectionStart(), end = editor->GetSelectionEnd();

                    wxString output = wxString::Format(wxT("%i:%i"), start, end);
                    expandedString.Replace(wxT("$(CurrentSelectionRange)"), output);
                }
            }
        }

        // exapand common macros
        wxDateTime now = wxDateTime::Now();
        expandedString.Replace(wxT("$(User)"), wxGetUserName());
        expandedString.Replace(wxT("$(Date)"), now.FormatDate());

        if(manager && applyEnv) {
            expandedString.Replace(wxT("$(CodeLitePath)"), manager->GetInstallDirectory());

            // Apply the environment and expand the variables
            EnvSetter es(NULL, NULL, project, confToBuild);
            expandedString = manager->GetEnv()->ExpandVariables(expandedString, false);
        }
    }
    return expandedString;
}