Skip to content

Commit

Permalink
Responding to review
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeSiFive committed Aug 15, 2023
1 parent 259759b commit 36453b9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ Below is a full example
}
```

While there are many sources that a config option might come from, the following priority is always observed from lowest
to highest:
1) .wakeroot
2) user config
3) environment variables
4) command line options

So a command line option overides anything, an environment variable overrides user config and wakeroot, user config
overrides wakeroot, and wakeroot overrides nothing

# Documentation

Documentation for wake can be found in [share/doc/wake](share/doc/wake).
Expand Down
22 changes: 18 additions & 4 deletions src/runtime/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,26 @@ bool WakeConfig::init(const std::string& wakeroot_path, const WakeConfigOverride
}
}

// The priority of config sources is the following from lowest priority to highest:
// 1) .wakeroot
// 2) user config
// 3) environment variables
// 4) command line options
//
// When parsing the user config, the user config path can't be in the user config
// but it can be anywhere else so before parsing the user config we parse wakeroot
// and then the other two sources. Once we parse the user config though we'll have
// go overwrite anything from the user config that should be form an env-var or
// a command line option.

// Parse values from .wakeroot
_config->set_all<WakeConfigProvenance::WakeRoot>(wakeroot_json);

// Sometimes we need to the user_config with an env-var so we check env-vars first here
_config->set_all_env_var();

// Further more users may choose to override the user config at the command line level so
// we run that too only to run it again later
// Furthermore users may choose to override the user config at the command line level so
// we run that to only to run it again later
_config->override_all(overrides);

// Parse user config
Expand Down Expand Up @@ -378,10 +390,12 @@ bool WakeConfig::init(const std::string& wakeroot_path, const WakeConfigOverride
// Parse values from the user config
_config->set_all<WakeConfigProvenance::UserConfig>(user_config_json);

// Set all env-vars again as they should override user configs
// Set all env-vars again as they should override user configs. Note that
// this is the second time we set the env-vars.
_config->set_all_env_var();

// Finally apply command line overrides as they override everything
// Finally apply command line overrides as they override everything. Note that
// this is the second time we set the overrides.
_config->override_all(overrides);

return true;
Expand Down
2 changes: 1 addition & 1 deletion tests/config/nominal/pass.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ if [ $(uname) != Linux ] ; then
fi

WAKE="${1:+$1/wake}"
"${WAKE:-wake}" --config
WAKE_SHARED_CACHE_MAX_SIZE=1024 "${WAKE:-wake}" --config
2 changes: 1 addition & 1 deletion tests/config/nominal/stdout
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Wake config:
log_header = 'foobar $source: ' (WakeRoot)
log_header_source_width = '13' (WakeRoot)
label_filter = '.*' (Default)
max_cache_size = '1024' (WakeRoot)
max_cache_size = '1024' (EnvVar)
low_cache_size = '512' (WakeRoot)
cache_miss_on_failure = 'true' (WakeRoot)
log_header_align = 'true' (WakeRoot)

0 comments on commit 36453b9

Please sign in to comment.