-
Notifications
You must be signed in to change notification settings - Fork 524
Support env variable substitution with defaults in rebar shell #2948
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
Conversation
|
Would be nice to get this merged - it allows you to write sys.config.src files like this: and get the variables replaced at build time if set, and with reasonable default values if not. |
ferd
left a comment
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.
Should be good to go, but I'm proposing a bit of a simplification/encapsulation change to the parsing rule.
apps/rebar/src/rebar_file_utils.erl
Outdated
| nomatch -> | ||
| error; | ||
| {match, [Name,Default]} -> | ||
| %% the Default part will include the ":-" prefix if present |
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.
using ([a-zA-Z_]+[a-zA-Z0-9_]*)(:-([^}]*))?} for the regex would let you capture [1,3] and not have to handle the :- operator in the output, and simplify replace_varname/2.
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 idea. When testing this, it turned out that the regex also needed to be left-anchored, otherwise it will match on the later part of a variable with a bad character, e.g. "HELLO-FERD}" would return a match on FERD as the variable name.
The sys.config.src file may since OTP 21 contain env variables with
defaults using the standard shell syntax `${FOO:-some_default}`. The
only place where Rebar itself needs to worry about this is in the
`shell` command which wants to load the sys.config, and must then
perform the substitutions first. This commit implements support for
such env variable defaults. Previously, Rebar would crash if it
encountered this syntax.
Also ensures match is left-anchored.
6fb2b3e to
d1606ef
Compare
The sys.config.src file may since OTP 21 contain env variables with defaults using the standard shell syntax
${FOO:-some_default}. The only place where Rebar itself needs to worry about this is in theshellcommand which wants to load the sys.config, and must then perform the substitutions first. This commit implements support for such env variable defaults. Previously, Rebar would crash if it encountered this syntax.By some simple refactoring, this also makes the
rebar3 ct --sys_configoption work onsys.config.srcfiles.