Support comments in build rules.
Tested: sh tests/test.sh
diff --git a/ninja_defs.go b/ninja_defs.go
index a653796..0919ea4 100644
--- a/ninja_defs.go
+++ b/ninja_defs.go
@@ -73,6 +73,7 @@
// Ninja build statement. The Args field contains variable names and values
// that are set within the build statement's scope in the Ninja file.
type BuildParams struct {
+ Comment string // The comment that will appear above the definition.
Rule Rule // The rule to invoke.
Outputs []string // The list of output targets.
Inputs []string // The list of explicit input dependencies.
@@ -236,6 +237,7 @@
// A buildDef describes a build target definition.
type buildDef struct {
+ Comment string
Rule Rule
Outputs []*ninjaString
Inputs []*ninjaString
@@ -248,9 +250,11 @@
func parseBuildParams(scope scope, params *BuildParams) (*buildDef,
error) {
+ comment := params.Comment
rule := params.Rule
b := &buildDef{
+ Comment: comment,
Rule: rule,
}
@@ -315,13 +319,14 @@
func (b *buildDef) WriteTo(nw *ninjaWriter, pkgNames map[*PackageContext]string) error {
var (
+ comment = b.Comment
rule = b.Rule.fullName(pkgNames)
outputs = valueList(b.Outputs, pkgNames, outputEscaper)
explicitDeps = valueList(b.Inputs, pkgNames, inputEscaper)
implicitDeps = valueList(b.Implicits, pkgNames, inputEscaper)
orderOnlyDeps = valueList(b.OrderOnly, pkgNames, inputEscaper)
)
- err := nw.Build(rule, outputs, explicitDeps, implicitDeps, orderOnlyDeps)
+ err := nw.Build(comment, rule, outputs, explicitDeps, implicitDeps, orderOnlyDeps)
if err != nil {
return err
}