Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Commit

Permalink
Expand variables in redir includes
Browse files Browse the repository at this point in the history
Expand variables in <$file style includes. Fixes
dcjones#9.
  • Loading branch information
rjkroege committed Apr 15, 2020
1 parent bb402d9 commit 4dcfa04
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.14
require (
github.com/google/go-cmp v0.4.0
github.com/mattn/go-isatty v0.0.12
github.com/sanity-io/litter v1.2.0
)
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sanity-io/litter v1.2.0 h1:DGJO0bxH/+C2EukzOSBmAlxmkhVMGqzvcx/rvySYw9M=
github.com/sanity-io/litter v1.2.0/go.mod h1:JF6pZUFgu2Q0sBZ+HSV35P8TVPI1TTzEwyu9FXAw2W4=
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
2 changes: 1 addition & 1 deletion mk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestBasicMaking(t *testing.T) {
input: "testdata/test7.mk",
output: "testdata/test7.mk.expected",
errors: "",
passes: false,
passes: true,
},
{
// Variables expanded in recipes.
Expand Down
17 changes: 12 additions & 5 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func parsePipeInclude(p *parser, t token) parserStateFun {
for i := 0; i < len(p.tokenbuf); i++ {
args[i] = p.tokenbuf[i].val
}

// TODO - might have $shell available by now, but maybe not?
// It's not populated, regardless
var shell string
Expand Down Expand Up @@ -164,9 +164,16 @@ func parseRedirInclude(p *parser, t token) parserStateFun {
for i := range p.tokenbuf {
filename += p.tokenbuf[i].val
}

filename = os.ExpandEnv(filename)


// Expand variables in paths.
parts := expand(filename, p.rules.vars, false)
if len(parts) != 1 {
mkError("filename variables need to be a single value")
}

// TODO(rjk): Be sure that this is the right behaviour.
filename = parts[0]

file, err := os.Open(filename)
if err != nil {
p.basicErrorAtToken(fmt.Sprintf("cannot open %s", filename), p.tokenbuf[0])
Expand Down Expand Up @@ -315,7 +322,7 @@ func parseRecipe(p *parser, t token) parserStateFun {
msg := fmt.Sprintf("while reading a rule's attributes expected an attribute but found \"%c\".", err.found)
p.basicErrorAtToken(msg, p.tokenbuf[i+1])
}

// If we don't have a shell set, check vars, check default shell
if r.shell == nil {
if len(p.rules.vars["shell"]) > 0 {
Expand Down

0 comments on commit 4dcfa04

Please sign in to comment.