This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git

commit b67f4955e330c6c95f762376f007e09a664c4661
Author: Christopher Collins <ccoll...@apache.org>
AuthorDate: Fri Oct 4 14:54:51 2019 -0700

    Replace "$ENV" vars in custom command strings
---
 newt/builder/extcmd.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/newt/builder/extcmd.go b/newt/builder/extcmd.go
index 8821e65..ba64280 100644
--- a/newt/builder/extcmd.go
+++ b/newt/builder/extcmd.go
@@ -119,13 +119,17 @@ func (t *TargetBuilder) execExtCmds(sf stage.StageFunc, 
userSrcDir string,
                return err
        }
 
-       envs := EnvVarsToSlice(env)
        toks, err := shellquote.Split(sf.Name)
        if err != nil {
                return util.FmtNewtError(
                        "invalid command string: \"%s\": %s", sf.Name, 
err.Error())
        }
 
+       // Replace environment variables in command string.
+       for i, tok := range toks {
+               toks[i] = os.ExpandEnv(tok)
+       }
+
        // If the command is in the user's PATH, expand it to its real location.
        cmd, err := exec.LookPath(toks[0])
        if err == nil {
@@ -143,6 +147,7 @@ func (t *TargetBuilder) execExtCmds(sf stage.StageFunc, 
userSrcDir string,
        defer os.Chdir(pwd)
 
        util.StatusMessage(util.VERBOSITY_DEFAULT, "Executing %s\n", sf.Name)
+       envs := EnvVarsToSlice(env)
        if err := util.ShellInteractiveCommand(toks, envs, true); err != nil {
                return err
        }

Reply via email to