Skip to content

Commit

Permalink
Add implicit prereq attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
zyedidia committed Nov 11, 2022
1 parent a37409f commit 6cb02a1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
4 changes: 4 additions & 0 deletions docs/knit.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ bar:V: foo[Q]
The `foo` rule will be quiet only when used as a prerequisite to the `bar`
rule.

Some attributes can only be applied in this way:

* `I` (implicit): this prereq does not appear in `$input`.

### Recipes

A recipe is a list of commands to execute. They are executed within the `sh`
Expand Down
15 changes: 13 additions & 2 deletions rules/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (g *Graph) resolveTargetForRuleSet(rs *RuleSet, dir string, target string,
if len(r.recipe) != 0 {
// recipe exists -- overwrite prereqs
prereqs = r.prereqs
expprereqs = r.prereqs
expprereqs = explicits(r.prereqs)
} else {
// recipe is empty -- only add the prereqs
prereqs = append(prereqs, r.prereqs...)
Expand Down Expand Up @@ -405,7 +405,7 @@ func (g *Graph) resolveTargetForRuleSet(rs *RuleSet, dir string, target string,

// success -- add the prereqs
rule.prereqs = append(rule.prereqs, metarule.prereqs...)
expprereqs = metarule.prereqs
expprereqs = explicits(metarule.prereqs)
// overwrite the recipe/attrs/targets if the matched rule has a
// recipe, or we don't yet have a recipe
if len(mr.recipe) > 0 || len(rule.recipe) == 0 {
Expand Down Expand Up @@ -506,6 +506,17 @@ func (g *Graph) resolveTargetForRuleSet(rs *RuleSet, dir string, target string,
return n, nil
}

func explicits(prereqs []string) []string {
exp := make([]string, 0, len(prereqs))
for _, p := range prereqs {
parsed, _ := parsePrereq(p)
if !parsed.attrs.Implicit {
exp = append(exp, parsed.name)
}
}
return exp
}

func (n *node) inputs() []string {
ins := make([]string, 0, len(n.myPrereqs))
for i, prereq := range n.myPrereqs {
Expand Down
19 changes: 11 additions & 8 deletions rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ func (r *MetaRule) String() string {
}

type AttrSet struct {
Regex bool // regular expression meta-rule
Virtual bool // targets are not files
Quiet bool // is not displayed as part of the build process
NoMeta bool // cannot be matched by meta rules
NonStop bool // does not stop if the recipe fails
Rebuild bool // this rule is always out-of-date
Linked bool // only run this rule if a sub-rule that requires it needs to run
Order bool
Regex bool // regular expression meta-rule
Virtual bool // targets are not files
Quiet bool // is not displayed as part of the build process
NoMeta bool // cannot be matched by meta rules
NonStop bool // does not stop if the recipe fails
Rebuild bool // this rule is always out-of-date
Linked bool // only run this rule if a sub-rule that requires it needs to run
Implicit bool // not listed in $input
Order bool
}

func (a *AttrSet) UpdateFrom(other AttrSet) {
Expand Down Expand Up @@ -211,6 +212,8 @@ func ParseAttribs(input string) (AttrSet, error) {
attrs.Linked = true
case 'O':
attrs.Order = true
case 'I':
attrs.Implicit = true
default:
return attrs, attrError{c}
}
Expand Down
6 changes: 6 additions & 0 deletions test/implicit/Knitfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
return b{
$ a: foo[I] bar
echo $input
$ foo:V:
$ bar:V:
}
12 changes: 12 additions & 0 deletions test/implicit/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name = "Check implicit attributes"

[flags]

knitfile = "Knitfile"
ncpu = 1
dryrun = true

[[builds]]

args = []
output = "echo bar"

0 comments on commit 6cb02a1

Please sign in to comment.