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 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); } }