summaryrefslogtreecommitdiff
path: root/src/rebar_utils.erl
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2018-02-27 08:26:36 -0500
committerGitHub <noreply@github.com>2018-02-27 08:26:36 -0500
commit2917ede03d17e825226eee62aa05f1d348c3366f (patch)
tree8a56e548fdc10d6cc644624a84c3ddf145a555dc /src/rebar_utils.erl
parent8b4ef7dd834dce82532d0566dbb7f0436e8b7572 (diff)
parent57768ba22ed39d2b099ac09c834ed90f422f2336 (diff)
Merge pull request #1706 from campanja-forks/env-for-providers
Env for providers
Diffstat (limited to 'src/rebar_utils.erl')
-rw-r--r--src/rebar_utils.erl36
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) ->