diff options
-rw-r--r-- | src/rebar_utils.erl | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index b633760..9bbe54e 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -453,6 +453,24 @@ reread_config(ConfigList) -> "and will be ignored.", []) end. +%% @doc Given env. variable `FOO' we want to expand all references to +%% it in `InStr'. References can have two forms: `$FOO' and `${FOO}' +%% The end of form `$FOO' is delimited with whitespace or EOL +-spec expand_env_variable(string(), string(), term()) -> string(). +expand_env_variable(InStr, VarName, RawVarValue) -> + case rebar_string:chr(InStr, $$) of + 0 -> + %% No variables to expand + InStr; + _ -> + ReOpts = [global, unicode, {return, list}], + VarValue = re:replace(RawVarValue, "\\\\", "\\\\\\\\", ReOpts), + %% Use a regex to match/replace: + %% Given variable "FOO": match $FOO\s | $FOOeol | ${FOO} + RegEx = io_lib:format("\\\$(~ts(\\W|$)|{~ts})", [VarName, VarName]), + re:replace(InStr, RegEx, [VarValue, "\\2"], ReOpts) + end. + %% ==================================================================== %% Internal functions %% ==================================================================== @@ -523,24 +541,6 @@ patch_on_windows(Cmd, Env) -> Cmd end. -%% @doc Given env. variable `FOO' we want to expand all references to -%% it in `InStr'. References can have two forms: `$FOO' and `${FOO}' -%% The end of form `$FOO' is delimited with whitespace or EOL --spec expand_env_variable(string(), string(), term()) -> string(). -expand_env_variable(InStr, VarName, RawVarValue) -> - case rebar_string:chr(InStr, $$) of - 0 -> - %% No variables to expand - InStr; - _ -> - ReOpts = [global, unicode, {return, list}], - VarValue = re:replace(RawVarValue, "\\\\", "\\\\\\\\", ReOpts), - %% Use a regex to match/replace: - %% Given variable "FOO": match $FOO\s | $FOOeol | ${FOO} - RegEx = io_lib:format("\\\$(~ts(\\W|$)|{~ts})", [VarName, VarName]), - re:replace(InStr, RegEx, [VarValue, "\\2"], ReOpts) - end. - expand_sh_flag(return_on_error) -> {error_handler, fun(_Command, Err) -> |