From 3f79592b9a47476789cb6a47bc6ba0168d156f0e Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 26 May 2017 09:16:00 +1000 Subject: [PATCH] Add a comment about running "go generate". --- cmd/puffs-gen-c/gen.go | 11 ++++++++++- cmd/puffs-gen-c/preamble.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/puffs-gen-c/gen.go b/cmd/puffs-gen-c/gen.go index db5448c6..ef1dd754 100644 --- a/cmd/puffs-gen-c/gen.go +++ b/cmd/puffs-gen-c/gen.go @@ -27,11 +27,20 @@ func main() { } func main1() error { - in, err := ioutil.ReadFile("preamble.h") + const inFilename = "preamble.h" + in, err := ioutil.ReadFile(inFilename) if err != nil { return err } + const afterEditing = "// After editing this file," + if !bytes.HasPrefix(in, []byte(afterEditing)) { + return fmt.Errorf("%s's contents do not start with %q", inFilename, afterEditing) + } + if i := bytes.Index(in, []byte("\n\n")); i >= 0 { + in = in[i+2:] + } + out := &bytes.Buffer{} out.WriteString("// Code generated by running \"go generate\". DO NOT EDIT.\n") out.WriteString("\n") diff --git a/cmd/puffs-gen-c/preamble.h b/cmd/puffs-gen-c/preamble.h index 3865bf3d..ebcc7e23 100644 --- a/cmd/puffs-gen-c/preamble.h +++ b/cmd/puffs-gen-c/preamble.h @@ -1,3 +1,5 @@ +// After editing this file, run "go generate" in this directory. + // Use of this source code is governed by a BSD-style license that can be found // in the LICENSE file.