]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/md5: use go generate to create md5block.go
authorChaiShushan <chaishushan@gmail.com>
Thu, 28 Aug 2014 22:04:10 +0000 (15:04 -0700)
committerRob Pike <r@golang.org>
Thu, 28 Aug 2014 22:04:10 +0000 (15:04 -0700)
LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/129650043

src/pkg/crypto/md5/gen.go
src/pkg/crypto/md5/md5.go
src/pkg/crypto/md5/md5block.go

index 75295e4fcb070a21ad94bb491da7e858a2db3aa5..8cd0a6358e170f057930d33b9fe5a572d28ab73e 100644 (file)
@@ -7,7 +7,7 @@
 // This program generates md5block.go
 // Invoke as
 //
-//     go run gen.go [-full] |gofmt >md5block.go
+//     go run gen.go [-full] -output md5block.go
 //
 // The -full flag causes the generated code to do a full
 // (16x) unrolling instead of a 4x unrolling.
 package main
 
 import (
+       "bytes"
        "flag"
+       "go/format"
+       "io/ioutil"
        "log"
-       "os"
        "strings"
        "text/template"
 )
 
+var filename = flag.String("output", "md5block.go", "output file name")
+
 func main() {
        flag.Parse()
 
+       var buf bytes.Buffer
+
        t := template.Must(template.New("main").Funcs(funcs).Parse(program))
-       if err := t.Execute(os.Stdout, data); err != nil {
+       if err := t.Execute(&buf, data); err != nil {
+               log.Fatal(err)
+       }
+
+       data, err := format.Source(buf.Bytes())
+       if err != nil {
+               log.Fatal(err)
+       }
+       err = ioutil.WriteFile(*filename, data, 0644)
+       if err != nil {
                log.Fatal(err)
        }
 }
@@ -165,7 +180,7 @@ var program = `// Copyright 2013 The Go Authors. All rights reserved.
 // license that can be found in the LICENSE file.
 
 // DO NOT EDIT.
-// Generate with: go run gen.go{{if .Full}} -full{{end}} | gofmt >md5block.go
+// Generate with: go run gen.go{{if .Full}} -full{{end}} -output md5block.go
 
 package md5
 
index 1a1f35fabc0d7b696d1201ec3601583f260bc6ac..8c50c6d0bfaa7db920a48988ae5af5ecff7dd411 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:generate go run gen.go -full -output md5block.go
+
 // Package md5 implements the MD5 hash algorithm as defined in RFC 1321.
 package md5
 
index e2a17677757e55ac0b07d2477513fb38734524ba..64e1e7c1efdb15e8c06dce73f87f1cedaccea99e 100644 (file)
@@ -3,7 +3,7 @@
 // license that can be found in the LICENSE file.
 
 // DO NOT EDIT.
-// Generate with: go run gen.go -full | gofmt >md5block.go
+// Generate with: go run gen.go -full -output md5block.go
 
 package md5