Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #264 from joakim-hove/add-util-env
Browse files Browse the repository at this point in the history
Add util env
  • Loading branch information
joakim-hove authored Mar 19, 2018
2 parents cda5c56 + 0f8382a commit 5a86d50
Show file tree
Hide file tree
Showing 16 changed files with 507 additions and 42 deletions.
1 change: 1 addition & 0 deletions applications/job_queue/block_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <ert/util/util.h>
#include <ert/util/hash.h>
#include <ert/util/vector.h>
#include <ert/res_util/res_env.h>

#include <ert/job_queue/lsf_driver.h>

Expand Down
1 change: 1 addition & 0 deletions libconfig/src/conf_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>

Expand Down
4 changes: 3 additions & 1 deletion libconfig/src/config_content_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <ert/util/util.h>
#include <ert/util/stringlist.h>

#include <ert/res_util/res_env.h>

#include <ert/config/config_schema_item.h>
#include <ert/config/config_content_node.h>
#include <ert/config/config_path_elm.h>
Expand Down Expand Up @@ -199,7 +201,7 @@ const char * config_content_node_iget_as_executable( config_content_node_type *

if( !strstr( config_value, UTIL_PATH_SEP_STRING )
&& !util_file_exists( path_value ) ) {
char* tmp = util_alloc_PATH_executable( config_value );
char* tmp = res_env_alloc_PATH_executable( config_value );
if( tmp ) {
free( path_value );
path_value = tmp;
Expand Down
3 changes: 2 additions & 1 deletion libconfig/src/config_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <ert/util/vector.h>
#include <ert/util/path_stack.h>
#include <ert/res_util/subst_list.h>
#include <ert/res_util/res_env.h>

#include <ert/config/config_parser.h>
#include <ert/config/config_error.h>
Expand Down Expand Up @@ -193,7 +194,7 @@ static config_content_node_type * config_content_item_set_arg__(subst_list_type
for (iarg = 0; iarg < argc; iarg++) {
int env_offset = 0;
while (true) {
char * env_var = util_isscanf_alloc_envvar( stringlist_iget(token_list , iarg + 1) , env_offset );
char * env_var = res_env_isscanf_alloc_envvar( stringlist_iget(token_list , iarg + 1) , env_offset );
if (env_var == NULL)
break;

Expand Down
3 changes: 2 additions & 1 deletion libconfig/src/config_schema_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ert/util/set.h>
#include <ert/util/vector.h>
#include <ert/res_util/subst_list.h>
#include <ert/res_util/res_env.h>

#include <ert/config/config_error.h>
#include <ert/config/config_schema_item.h>
Expand Down Expand Up @@ -404,7 +405,7 @@ bool config_schema_item_validate_set(const config_schema_item_type * item , stri
* util_alloc_PATH_executable aborts if some parts of the path is
* not an existing dir, so call it only when its an absolute path
*/
char * path_exe = util_alloc_PATH_executable( value );
char * path_exe = res_env_alloc_PATH_executable( value );
if (path_exe != NULL)
stringlist_iset_copy( token_list , iarg , path_exe);
else
Expand Down
8 changes: 5 additions & 3 deletions libenkf/src/site_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <ert/config/config_content_node.h>
#include <ert/config/config_schema_item.h>

#include <ert/res_util/res_env.h>

#include <ert/enkf/site_config.h>
#include <ert/enkf/queue_config.h>
#include <ert/enkf/enkf_defaults.h>
Expand Down Expand Up @@ -344,9 +346,9 @@ void site_config_clear_pathvar(site_config_type * site_config) {
const char * site_value = hash_get(site_config->path_variables_site, var);

if (site_value == NULL)
util_unsetenv(var);
res_env_unsetenv(var);
else
util_setenv(var, site_value);
res_env_setenv(var, site_value);
}
}
}
Expand All @@ -361,7 +363,7 @@ void site_config_update_pathvar(site_config_type * site_config, const char * pat
site_config. We store a NULL, so can roll back
(i.e. call unsetenv()). */
}
util_update_path_var(pathvar, value, false);
res_env_update_path_var(pathvar, value, false);
}

/*****************************************************************/
Expand Down
7 changes: 4 additions & 3 deletions libjob_queue/src/environment_varlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

#include <ert/job_queue/environment_varlist.h>

#include <ert/util/util_env.h>
#include <ert/res_util/res_env.h>

#include <ert/util/hash.h>

#define ENV_VAR_KEY_STRING "global_environment"
Expand All @@ -37,11 +38,11 @@ env_varlist_type * env_varlist_alloc() {
}

void env_varlist_update_path(env_varlist_type * list, const char * path_var, const char * new_path) {
hash_insert_string( list->updatelist, path_var , util_update_path_var( path_var , new_path , false));
hash_insert_string( list->updatelist, path_var , res_env_update_path_var( path_var , new_path , false));
}

void env_varlist_setenv(env_varlist_type * list, const char * key, const char * value) {
const char * interp_value = util_interp_setenv(key, value);
const char * interp_value = res_env_interp_setenv(key, value);
hash_insert_string(list->varlist, key, interp_value);
}

Expand Down
3 changes: 2 additions & 1 deletion libjob_queue/src/ext_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ert/util/stringlist.h>
#include <ert/util/parser.h>
#include <ert/res_util/subst_list.h>
#include <ert/res_util/res_env.h>

#include <ert/config/config_parser.h>
#include <ert/config/config_content.h>
Expand Down Expand Up @@ -451,7 +452,7 @@ void ext_job_set_executable(ext_job_type * ext_job, const char * executable_abs,
} else {
if (search_path){
/* Go through the PATH variable to try to locate the executable. */
char * path_executable = util_alloc_PATH_executable( executable_input );
char * path_executable = res_env_alloc_PATH_executable( executable_input );

if (path_executable != NULL) {
ext_job_set_executable( ext_job , path_executable, NULL, search_path );
Expand Down
3 changes: 2 additions & 1 deletion libjob_queue/src/lsf_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <ert/util/stringlist.h>
#include <ert/res_util/log.h>
#include <ert/res_util/res_log.h>
#include <ert/res_util/res_env.h>

#include <ert/job_queue/queue_driver.h>
#include <ert/job_queue/lsf_driver.h>
Expand Down Expand Up @@ -1116,7 +1117,7 @@ static void lsf_driver_set_remote_server( lsf_driver_type * driver , const char
#endif
} else {
driver->remote_lsf_server = util_realloc_string_copy( driver->remote_lsf_server , remote_server );
util_unsetenv( "BSUB_QUIET" );
res_env_unsetenv( "BSUB_QUIET" );
{
char * tmp_server = util_alloc_strupr_copy( remote_server );

Expand Down
1 change: 1 addition & 0 deletions libjob_queue/src/queue_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <string.h>

Expand Down
5 changes: 5 additions & 0 deletions libres_util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_library( res_util src/res_log.c
src/template.c
src/template_loop.c
src/path_fmt.c
src/res_env.c
src/block_fs.c
src/res_version.c
src/regression.c
Expand Down Expand Up @@ -73,6 +74,10 @@ add_executable(ert_util_block_fs tests/ert_util_block_fs.c)
target_link_libraries(ert_util_block_fs res_util)
add_test(NAME ert_util_block_fs COMMAND ert_util_block_fs)

add_executable(res_util_PATH tests/res_util_PATH.c)
target_link_libraries(res_util_PATH res_util)
add_test(NAME res_util_PATH COMMAND res_util_PATH)

find_library( VALGRIND NAMES valgr )
if (VALGRIND)
set(valgrind_cmd valgrind --error-exitcode=1 --tool=memcheck)
Expand Down
40 changes: 40 additions & 0 deletions libres_util/include/ert/res_util/res_env.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright (C) 2018 Statoil ASA, Norway.
The file 'res_env.h' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/

#ifndef RESENV_H
#define RESENV_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>

char ** res_env_alloc_PATH_list();
char * res_env_alloc_PATH_executable(const char * executable );
void res_env_setenv( const char * variable , const char * value);
const char * res_env_interp_setenv( const char * variable , const char * value);
void res_env_unsetenv( const char * variable);
char * res_env_alloc_envvar( const char * value );
char * res_env_isscanf_alloc_envvar( const char * string , int env_index );
const char * res_env_update_path_var(const char * variable, const char * value, bool append);

#ifdef __cplusplus
}
#endif
#endif // RESLOG_H
1 change: 1 addition & 0 deletions libres_util/include/ert/res_util/subst_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern "C" {

#include <ert/util/type_macros.h>
#include <ert/util/buffer.h>

#include <ert/res_util/subst_func.h>

typedef struct subst_list_struct subst_list_type;
Expand Down
Loading

0 comments on commit 5a86d50

Please sign in to comment.