wxArrayString EnvironmentConfig::GetActiveSetEnvNames(bool includeWorkspace, const wxString& project) { //read the environments variables EvnVarList vars; ReadObject(wxT("Variables"), &vars); wxArrayString envnames; // get the active environment variables set EnvMap variables = vars.GetVariables(wxEmptyString, includeWorkspace, project, wxEmptyString); for(size_t i=0; i<variables.GetCount(); ++i) { wxString key, val; variables.Get(i, key, val); envnames.Add( key ); } return envnames; }
void CodeLiteApp::MSWReadRegistry() { #ifdef __WXMSW__ EvnVarList vars; EnvironmentConfig::Instance()->Load(); EnvironmentConfig::Instance()->ReadObject(wxT("Variables"), &vars); ///////////////////////////////////////////////////////////////// // New way of registry: // Read the registry INI file ///////////////////////////////////////////////////////////////// // Update PATH environment variable with the install directory and // MinGW default installation (if exists) wxString pathEnv; wxGetEnv(wxT("PATH"), &pathEnv); wxString codeliteInstallDir; codeliteInstallDir << ManagerST::Get()->GetInstallDir() << wxT(";"); pathEnv.Prepend(codeliteInstallDir); // Load the registry file wxString iniFile; iniFile << ManagerST::Get()->GetInstallDir() << wxFileName::GetPathSeparator() << wxT("registry.ini"); if(wxFileName::FileExists(iniFile)) { clRegistry::SetFilename(iniFile); clRegistry registry; m_parserPaths.Clear(); wxString strWx, strMingw, strUnitTestPP; // registry.Read(wxT("wx"), strWx); registry.Read(wxT("mingw"), strMingw); registry.Read(wxT("unittestpp"), strUnitTestPP); // Supprot for wxWidgets if(strWx.IsEmpty() == false) { // we have WX installed on this machine, set the path of WXWIN & WXCFG to point to it EnvMap envs = vars.GetVariables(wxT("Default"), false, wxT("")); if(!envs.Contains(wxT("WXWIN"))) { vars.AddVariable(wxT("Default"), wxT("WXWIN"), strWx); vars.AddVariable(wxT("Default"), wxT("PATH"), wxT("$(WXWIN)\\lib\\gcc_dll;$(PATH)")); } if(!envs.Contains(wxT("WXCFG"))) vars.AddVariable(wxT("Default"), wxT("WXCFG"), wxT("gcc_dll\\mswu")); EnvironmentConfig::Instance()->WriteObject(wxT("Variables"), &vars); wxSetEnv(wxT("WX_INCL_HOME"), strWx + wxT("\\include")); } // Support for UnitTest++ if(strUnitTestPP.IsEmpty() == false) { // we have UnitTest++ installed on this machine EnvMap envs = vars.GetVariables(wxT("Default"), false, wxT("")); if(!envs.Contains(wxT("UNIT_TEST_PP_SRC_DIR"))) { vars.AddVariable(wxT("Default"), wxT("UNIT_TEST_PP_SRC_DIR"), strUnitTestPP); } EnvironmentConfig::Instance()->WriteObject(wxT("Variables"), &vars); } // Support for MinGW if(strMingw.IsEmpty() == false) { // Make sure that codelite's MinGW comes first before any other // MinGW installation that might exist on the machine strMingw << wxFileName::GetPathSeparator() << wxT("bin;"); pathEnv.Prepend(strMingw); } wxSetEnv(wxT("PATH"), pathEnv); } #endif }
void EnvironmentConfig::ApplyEnv(wxStringMap_t *overrideMap, const wxString &project, const wxString &config) { // We lock the CS here and it will be released in UnApplyEnv // this is safe to call without Locker since the UnApplyEnv // will always be called after ApplyEnv (ApplyEnv and UnApplyEnv are // protected functions that can only be called from EnvSetter class // which always call UnApplyEnv in its destructor) m_cs.Enter(); ++m_envApplied; if ( m_envApplied > 1 ) { //CL_DEBUG("Thread-%d: Applying environment variables... (not needed)", (int)wxThread::GetCurrentId()); return; } //CL_DEBUG("Thread-%d: Applying environment variables...", (int)wxThread::GetCurrentId()); //read the environments variables EvnVarList vars; ReadObject(wxT("Variables"), &vars); // get the active environment variables set EnvMap variables = vars.GetVariables(wxEmptyString, true, project, config); // if we have an "override map" place all the entries from the override map // into the global map before applying the environment if(overrideMap) { wxStringMap_t::iterator it = overrideMap->begin(); for(; it != overrideMap->end(); it++) { variables.Put(it->first, it->second); } } m_envSnapshot.clear(); for (size_t i=0; i<variables.GetCount(); i++) { wxString key, val; variables.Get(i, key, val); //keep old value before changing it wxString oldVal(wxEmptyString); if( wxGetEnv(key, &oldVal) == false ) { oldVal = __NO_SUCH_ENV__; } // keep the old value, however, don't override it if it // already exists as it might cause the variable to grow in size... // Simple case: // PATH=$(PATH);\New\Path // PATH=$(PATH);\Another\New\Path // If we replace the value, PATH will contain the original PATH + \New\Path if ( m_envSnapshot.count( key ) == 0 ) { m_envSnapshot.insert( std::make_pair( key, oldVal ) ); } // Incase this line contains other environment variables, expand them before setting this environment variable wxString newVal = DoExpandVariables(val); //set the new value wxSetEnv(key, newVal); } }