Merge pull request #153 from colincross/build_description
Allow BuildParams to override ninja description
This commit is contained in:
commit
ea10dedba9
4 changed files with 44 additions and 10 deletions
|
@ -68,6 +68,13 @@ func (l *liveTracker) AddBuildDefDeps(def *buildDef) error {
|
|||
return err
|
||||
}
|
||||
|
||||
for _, value := range def.Variables {
|
||||
err = l.addNinjaStringDeps(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, value := range def.Args {
|
||||
err = l.addNinjaStringDeps(value)
|
||||
if err != nil {
|
||||
|
|
|
@ -79,6 +79,7 @@ type BuildParams struct {
|
|||
Comment string // The comment that will appear above the definition.
|
||||
Depfile string // The dependency file name.
|
||||
Deps Deps // The format of the dependency file.
|
||||
Description string // The description that Ninja will print for the build.
|
||||
Rule Rule // The rule to invoke.
|
||||
Outputs []string // The list of explicit output targets.
|
||||
ImplicitOutputs []string // The list of implicit output targets.
|
||||
|
@ -265,6 +266,13 @@ func parseBuildParams(scope scope, params *BuildParams) (*buildDef,
|
|||
Rule: rule,
|
||||
}
|
||||
|
||||
setVariable := func(name string, value *ninjaString) {
|
||||
if b.Variables == nil {
|
||||
b.Variables = make(map[string]*ninjaString)
|
||||
}
|
||||
b.Variables[name] = value
|
||||
}
|
||||
|
||||
if !scope.IsRuleVisible(rule) {
|
||||
return nil, fmt.Errorf("Rule %s is not visible in this scope", rule)
|
||||
}
|
||||
|
@ -301,22 +309,24 @@ func parseBuildParams(scope scope, params *BuildParams) (*buildDef,
|
|||
|
||||
b.Optional = params.Optional
|
||||
|
||||
if params.Depfile != "" || params.Deps != DepsNone {
|
||||
if b.Variables == nil {
|
||||
b.Variables = make(map[string]*ninjaString)
|
||||
}
|
||||
}
|
||||
|
||||
if params.Depfile != "" {
|
||||
value, err := parseNinjaString(scope, params.Depfile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing Depfile param: %s", err)
|
||||
}
|
||||
b.Variables["depfile"] = value
|
||||
setVariable("depfile", value)
|
||||
}
|
||||
|
||||
if params.Deps != DepsNone {
|
||||
b.Variables["deps"] = simpleNinjaString(params.Deps.String())
|
||||
setVariable("deps", simpleNinjaString(params.Deps.String()))
|
||||
}
|
||||
|
||||
if params.Description != "" {
|
||||
value, err := parseNinjaString(scope, params.Description)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing Description param: %s", err)
|
||||
}
|
||||
setVariable("description", value)
|
||||
}
|
||||
|
||||
argNameScope := rule.scope()
|
||||
|
|
|
@ -54,6 +54,7 @@ func simpleNinjaString(str string) *ninjaString {
|
|||
type parseState struct {
|
||||
scope scope
|
||||
str string
|
||||
pendingStr string
|
||||
stringStart int
|
||||
varStart int
|
||||
result *ninjaString
|
||||
|
@ -64,6 +65,9 @@ func (ps *parseState) pushVariable(v Variable) {
|
|||
// Last push was a variable, we need a blank string separator
|
||||
ps.result.strings = append(ps.result.strings, "")
|
||||
}
|
||||
if ps.pendingStr != "" {
|
||||
panic("oops, pushed variable with pending string")
|
||||
}
|
||||
ps.result.variables = append(ps.result.variables, v)
|
||||
}
|
||||
|
||||
|
@ -71,7 +75,8 @@ func (ps *parseState) pushString(s string) {
|
|||
if len(ps.result.strings) != len(ps.result.variables) {
|
||||
panic("oops, pushed string after string")
|
||||
}
|
||||
ps.result.strings = append(ps.result.strings, s)
|
||||
ps.result.strings = append(ps.result.strings, ps.pendingStr+s)
|
||||
ps.pendingStr = ""
|
||||
}
|
||||
|
||||
type stateFunc func(*parseState, int, rune) (stateFunc, error)
|
||||
|
@ -93,7 +98,7 @@ func parseNinjaString(scope scope, str string) (*ninjaString, error) {
|
|||
result: result,
|
||||
}
|
||||
|
||||
state := parseStringState
|
||||
state := parseFirstRuneState
|
||||
var err error
|
||||
for i := 0; i < len(str); i++ {
|
||||
r := rune(str[i])
|
||||
|
@ -111,6 +116,13 @@ func parseNinjaString(scope scope, str string) (*ninjaString, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func parseFirstRuneState(state *parseState, i int, r rune) (stateFunc, error) {
|
||||
if r == ' ' {
|
||||
state.pendingStr += "$"
|
||||
}
|
||||
return parseStringState(state, i, r)
|
||||
}
|
||||
|
||||
func parseStringState(state *parseState, i int, r rune) (stateFunc, error) {
|
||||
switch {
|
||||
case r == '$':
|
||||
|
|
|
@ -70,6 +70,11 @@ var ninjaParseTestCases = []struct {
|
|||
vars: nil,
|
||||
strs: []string{"foo bar"},
|
||||
},
|
||||
{
|
||||
input: " foo ",
|
||||
vars: nil,
|
||||
strs: []string{"$ foo "},
|
||||
},
|
||||
{
|
||||
input: "foo $ bar",
|
||||
err: "invalid character after '$' at byte offset 5",
|
||||
|
|
Loading…
Reference in a new issue