Skip to content

Commit

Permalink
groot/cmd/root-gen-streamer: use an in-memory buffer for generation
Browse files Browse the repository at this point in the history
This CL modifies root-gen-streamer to use an in-memory buffer as the
destination of the code generation.
This is needed because the Go-1.19.10 version of x/go/packages.Load will
choke on an empty "output_gen.go" file.
This was the case as the old version root-gen-streamer was creating the
destination file for the code generation before calling the streamer
generation.

Signed-off-by: Sebastien Binet <binet@cern.ch>
  • Loading branch information
sbinet committed Jun 22, 2023
1 parent c00ff1a commit d85e15f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion groot/cmd/root-gen-streamer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package main // import "go-hep.org/x/hep/groot/cmd/root-gen-streamer"

import (
"bytes"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -54,8 +55,14 @@ options:
var (
err error
out io.WriteCloser
buf = new(bytes.Buffer)
)

err = generate(buf, *pkgPath, types)
if err != nil {
log.Fatal(err)
}

switch *output {
case "":
out = os.Stdout
Expand All @@ -67,7 +74,7 @@ options:
defer out.Close()
}

err = generate(out, *pkgPath, types)
_, err = io.Copy(out, buf)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit d85e15f

Please sign in to comment.