From 9e3e113f83e4e16211fa6103ea8a5895c052a25a Mon Sep 17 00:00:00 2001 From: Tyler Rhodes Date: Wed, 21 Mar 2018 17:33:08 -0700 Subject: [PATCH] Fixed up a few things with reader refactor. --- cmd/spicy/main.go | 8 +++----- run.go | 5 +++-- spec.go | 8 +++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/spicy/main.go b/cmd/spicy/main.go index b822cc3..32ef5eb 100644 --- a/cmd/spicy/main.go +++ b/cmd/spicy/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" flag "github.com/ogier/pflag" log "github.com/sirupsen/logrus" "github.com/trhodeos/n64rom" @@ -95,6 +94,8 @@ func main() { if err != nil { panic(err) } + defer f.Close() + gcc := spicy.NewRunner(*cpp_command) ld := spicy.NewRunner(*ld_command) as := spicy.NewRunner(*as_command) @@ -106,9 +107,6 @@ func main() { } for _, w := range spec.Waves { - if err != nil { - panic(err) - } entry, err := spicy.CreateEntryBinary(w, as) if err != nil { panic(err) @@ -122,7 +120,7 @@ func main() { panic(err) } - out, err := os.Create(fmt.Sprintf("%s.n64", *rom_image_file)) + out, err := os.Create(*rom_image_file) if err != nil { panic(err) } diff --git a/run.go b/run.go index 51202dd..ebdb707 100644 --- a/run.go +++ b/run.go @@ -30,6 +30,7 @@ func (e ExecRunner) Run(r io.Reader, args []string) (io.Reader, error) { cmd := exec.Command(e.command, args...) var out bytes.Buffer var errout bytes.Buffer + cmd.Stdin = r cmd.Stdout = &out cmd.Stderr = &errout err := cmd.Run() @@ -76,7 +77,7 @@ func writeTempFile(r io.Reader, prefix string) (string, error) { if err != nil { return "", err } - log.Debugln("Writing file for prefix %s to %s", prefix, path) + log.Debugf("Writing file for prefix %s to %s", prefix, path) _, err = io.Copy(tmpfile, r) if err != nil { return "", err @@ -100,7 +101,7 @@ func (e MappedFileRunner) Run(r io.Reader, args []string) (io.Reader, error) { newArgs[i] = args[i] } } - _, err := e.runner.Run(r, args) + _, err := e.runner.Run(r, newArgs) if err != nil { return nil, err } diff --git a/spec.go b/spec.go index a5e9fc4..5f25825 100644 --- a/spec.go +++ b/spec.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "github.com/alecthomas/participle" + log "github.com/sirupsen/logrus" "io" "os" "path/filepath" @@ -261,6 +262,7 @@ func PreprocessSpec(file io.Reader, gcc Runner, includeFlags []string, defineFla } func ParseSpec(r io.Reader) (*Spec, error) { + log.Infof("Parsing spec") parser, err := participle.Build(&SpecAst{}, nil) if err != nil { return nil, err @@ -271,7 +273,11 @@ func ParseSpec(r io.Reader) (*Spec, error) { if err != nil { return nil, err } - return convertAstToSpec(*specAst) + out, err := convertAstToSpec(*specAst) + if err == nil { + log.Debugf("Parsed: %v", out) + } + return out, err } func (w *Wave) checkValidity() error {