-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment Variable Support #83
Conversation
…ome from environment variables
template <typename T> | ||
T derive_configuration(const char* key, | ||
const toml::parse_result& settings, | ||
T&& fallback) { | ||
T result = settings[key].value_or(fallback); | ||
std::string envar = toupper(std::string("ORC_") + key); | ||
if (const char* enval = std::getenv(envar.c_str())) { | ||
result = parse_enval<T>(enval); | ||
} | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This routine is the heart of the PR. Instead of taking values from the settings file directly, derive_configuration
will also look at the associated environment variable and use that if found.
@@ -32,7 +32,12 @@ jobs: | |||
id: build-orc-orc_dogfood | |||
continue-on-error: true | |||
run: | | |||
xcodebuild -project ./build/orc.xcodeproj -scheme orc_dogfood -configuration Debug | |||
ORC_OUTPUT_FILE=./output.json ORC_OUTPUT_FILE_MODE=json xcodebuild -json -project ./build/orc.xcodeproj -scheme orc_dogfood -configuration Debug -hideShellScriptEnvironment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A new test that leverages the environment variables to cause a JSON file to get dumped when running orc_dogfood
(which is a CMake target that uses ORC to build ORC). The JSON is then traversed with a couple jq
queries to make sure some boilerplate keys are in there and filled in with something meaningful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor question on the string move - I didn't follow it through to see if that saved something, or the move semantics aren't needed.
T parse_enval(std::string&&) = delete; | ||
|
||
template <> | ||
std::string parse_enval(std::string&& x) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why move semantics instead of const std::string&
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. the value coming from getenv
is a const char*
, which is then converted to a std::string
for this routine. For the std::string
specialization of parse_enval
, we can move the incoming string to the result with no additional changes. If the incoming string were const std::string&
, it would cost us a copy to make a new one to return by value.
With this PR, ORC now uses environment variables to override its configuration values. The environment variables, if set, will usurp any defaults or values found in the
orc-config
file. Environment variables can be used to override any ORC configuration setting except those that take lists (symbol_ignore
,violation_report
, andviolation_ignore
).For any given
orc-config
setting, the equivalent environment variable isORC_
appended to the name of the setting in all caps. Sooutput_file
can be overridden byORC_OUTPUT_FILE
,parallel_processing
byORC_PARALLEL_PROCESSING
, etc.This PR also comes with additional tests that leverage this new capability.