Variable expansion bug.

This commit is contained in:
Daniel Jones 2013-03-10 00:34:42 -08:00
parent 8cbbe9c53c
commit 587bdd6c63
8 changed files with 99 additions and 79 deletions

View file

@ -52,6 +52,9 @@ improvements.
1. A clean, modern implementation in Go, that doesn't depend on the whole Plan 1. A clean, modern implementation in Go, that doesn't depend on the whole Plan
9 stack. 9 stack.
1. Parallel by default. Modern computers can build more than one C file at a
time. Cases that should not be run in parallel are the exception. Use
`-p=1` if this is the case.
1. Use Go regular expressions, which are perl-like. The original mk used plan9 1. Use Go regular expressions, which are perl-like. The original mk used plan9
regex, which few people know or care to learn. regex, which few people know or care to learn.
1. Allow blank lines in recipes. A recipe is any indented block of text, and 1. Allow blank lines in recipes. A recipe is any indented block of text, and
@ -60,8 +63,6 @@ improvements.
1. Add an 'S' attribute to execute recipes with programs other than sh. This 1. Add an 'S' attribute to execute recipes with programs other than sh. This
way, you don't have to separate your six line python script into its own way, you don't have to separate your six line python script into its own
file. Just stick it directly in the mkfile. file. Just stick it directly in the mkfile.
1. Use sh syntax for command insertion (i.e. backticks) rather than rc shell
syntax.
1. Pretty colors. 1. Pretty colors.
# Current State # Current State

20
TODO.md Normal file
View file

@ -0,0 +1,20 @@
# Short-term
* Unit tests.
* Expanding regex matches in targets.
* Dummy rule for multiple explicit targets
* Expand `$newprereq`.
* Expand `$alltargets`.
* Man page.
* Namelist syntax.
* Environment variables.
# Long-term
* Nicer syntax for alternative-shell rules.
* An attribute to demand n processors for a particular rule. This way
resource hog rules can be run on their own without disabling parallel
make.
* A switch that prints the rules that will be executed and prompts to user
to do so. I often find myself doing `mk -n` before `mk` to make sure my
rules aren't bogus.

View file

@ -13,12 +13,13 @@ func expand(input string, vars map[string][]string, expandBackticks bool) []stri
expanded := "" expanded := ""
var i, j int var i, j int
for i = 0; i < len(input); { for i = 0; i < len(input); {
j = i + strings.IndexAny(input[i:], "\"'`$\\") j = strings.IndexAny(input[i:], "\"'`$\\")
if j < 0 { if j < 0 {
expanded += input[i:] expanded += input[i:]
break break
} }
j += i
expanded += input[i:j] expanded += input[i:j]
c, w := utf8.DecodeRuneInString(input[j:]) c, w := utf8.DecodeRuneInString(input[j:])

View file

@ -56,7 +56,6 @@ type node struct {
flags nodeFlag // bitwise combination of node flags flags nodeFlag // bitwise combination of node flags
} }
// Update a node's timestamp and 'exists' flag. // Update a node's timestamp and 'exists' flag.
func (u *node) updateTimestamp() { func (u *node) updateTimestamp() {
info, err := os.Stat(u.name) info, err := os.Stat(u.name)

3
lex.go
View file

@ -1,10 +1,9 @@
package main package main
import ( import (
"fmt"
"strings" "strings"
"unicode/utf8" "unicode/utf8"
"fmt"
) )
type tokenType int type tokenType int

View file

@ -5,10 +5,10 @@ package main
import ( import (
"fmt" "fmt"
"regexp"
"strings"
"io/ioutil" "io/ioutil"
"os" "os"
"regexp"
"strings"
) )
type parser struct { type parser struct {

View file

@ -152,7 +152,7 @@ func subprocess(program string,
var outbytes []byte var outbytes []byte
outbytes, err = cmd.Output() outbytes, err = cmd.Output()
output = string(outbytes) output = string(outbytes)
if output[len(output)-1] == '\n' { if len(output) > 0 && output[len(output)-1] == '\n' {
output = output[:len(output)-1] output = output[:len(output)-1]
} }
} else { } else {