Implement variable expansion in includes
Signed-off-by: Florian Limberger <flo@purplekraken.com>
This commit is contained in:
parent
73d1b31466
commit
cf75e9e7b8
2 changed files with 20 additions and 4 deletions
8
mk.go
8
mk.go
|
|
@ -328,7 +328,13 @@ func main() {
|
||||||
mkError("unable to find mkfile's absolute path")
|
mkError("unable to find mkfile's absolute path")
|
||||||
}
|
}
|
||||||
|
|
||||||
rs := parse(string(input), mkfilepath, abspath)
|
env := make(map[string][]string)
|
||||||
|
for _, elem := range os.Environ() {
|
||||||
|
vals := strings.SplitN(elem, "=", 2)
|
||||||
|
env[vals[0]] = append(env[vals[0]], vals[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
rs := parse(string(input), mkfilepath, abspath, env)
|
||||||
if quiet {
|
if quiet {
|
||||||
for i := range rs.rules {
|
for i := range rs.rules {
|
||||||
rs.rules[i].attributes.quiet = true
|
rs.rules[i].attributes.quiet = true
|
||||||
|
|
|
||||||
16
parse.go
16
parse.go
|
|
@ -52,8 +52,8 @@ func (p *parser) clear() {
|
||||||
type parserStateFun func(*parser, token) parserStateFun
|
type parserStateFun func(*parser, token) parserStateFun
|
||||||
|
|
||||||
// Parse a mkfile, returning a new ruleSet.
|
// Parse a mkfile, returning a new ruleSet.
|
||||||
func parse(input string, name string, path string) *ruleSet {
|
func parse(input string, name string, path string, env map[string][]string) *ruleSet {
|
||||||
rules := &ruleSet{make(map[string][]string),
|
rules := &ruleSet{env,
|
||||||
make([]rule, 0),
|
make([]rule, 0),
|
||||||
make(map[string][]int)}
|
make(map[string][]int)}
|
||||||
parseInto(input, name, rules, path)
|
parseInto(input, name, rules, path)
|
||||||
|
|
@ -115,7 +115,12 @@ func parsePipeInclude(p *parser, t token) parserStateFun {
|
||||||
|
|
||||||
args := make([]string, len(p.tokenbuf))
|
args := make([]string, len(p.tokenbuf))
|
||||||
for i := 0; i < len(p.tokenbuf); i++ {
|
for i := 0; i < len(p.tokenbuf); i++ {
|
||||||
args[i] = p.tokenbuf[i].val
|
s := p.tokenbuf[i].val
|
||||||
|
expanded := expand(s, p.rules.vars, false)
|
||||||
|
if len(expanded) > 0 {
|
||||||
|
s = expanded[0]
|
||||||
|
}
|
||||||
|
args[i] = s
|
||||||
}
|
}
|
||||||
|
|
||||||
output, success := subprocess("sh", args, "", true)
|
output, success := subprocess("sh", args, "", true)
|
||||||
|
|
@ -155,6 +160,11 @@ func parseRedirInclude(p *parser, t token) parserStateFun {
|
||||||
for i := range p.tokenbuf {
|
for i := range p.tokenbuf {
|
||||||
filename += p.tokenbuf[i].val
|
filename += p.tokenbuf[i].val
|
||||||
}
|
}
|
||||||
|
expanded := expand(filename, p.rules.vars, false)
|
||||||
|
if len(expanded) > 0 {
|
||||||
|
filename = expanded[0]
|
||||||
|
}
|
||||||
|
fmt.Printf("parsed filename: %v\nexpanded filename: %v\n", filename, expanded)
|
||||||
file, err := os.Open(filename)
|
file, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.basicErrorAtToken(fmt.Sprintf("cannot open %s", filename), p.tokenbuf[0])
|
p.basicErrorAtToken(fmt.Sprintf("cannot open %s", filename), p.tokenbuf[0])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue