Archived
1
0

Compile command created in initial working state

This commit is contained in:
Jip J. Dekker 2016-03-19 21:06:19 +01:00
parent 89c30ca5eb
commit 9ad93eb620
2 changed files with 18 additions and 4 deletions

View File

@ -15,7 +15,6 @@
package compiler
import (
"fmt"
"os"
"path/filepath"
@ -30,8 +29,16 @@ func CompileDir(path string, opts *settings.Settings) {
scores, collector := generateScores()
filepath.Walk(path, compilePath(path, opts, collector))
PrepareLilypond(opts)
for _, score := range *scores {
fmt.Println(score)
msg, err := Lilypond(score.Path)
if err != nil {
log.WithFields(log.Fields{
"message": msg,
"error": err,
"score": score,
}).Warning("score failed to compile")
}
}
}

View File

@ -18,6 +18,7 @@ import (
"os"
"os/exec"
log "github.com/Sirupsen/logrus"
"github.com/jjdekker/ponder/helpers"
"github.com/jjdekker/ponder/settings"
)
@ -30,16 +31,18 @@ var (
// PrepareLilypond sets all arguments and options for the Lilypond
// compilation function using the given settings
func PrepareLilypond(opts *settings.Settings) {
// TODO: Escape these directory strings
// Adds all includes to the lilypond arguments
for _, dir := range opts.LilypondIncludes {
lilypondArgs = append(lilypondArgs, "--include=\""+dir+"\"")
lilypondArgs = append(lilypondArgs, "--include="+dir)
}
lilypondArgs = append(lilypondArgs, "--loglevel=ERROR")
lilypondArgs = append(lilypondArgs, "--pdf")
// TODO: Make this an absolute path.
lilypondArgs = append(lilypondArgs, "--output=\""+opts.OutputDir+"\"")
lilypondArgs = append(lilypondArgs, "--output="+opts.OutputDir)
if !helpers.Exists(opts.OutputDir) {
log.WithFields(log.Fields{"path": opts.OutputDir}).Info("creating output directory")
err := os.MkdirAll(opts.OutputDir, os.ModePerm)
helpers.Check(err, "Could not create output directory")
}
@ -49,6 +52,10 @@ func PrepareLilypond(opts *settings.Settings) {
// using the arguments prepared by the PrepareLilypond function
func Lilypond(path string) (string, error) {
cmd := exec.Command(lilypondCmd, append(lilypondArgs, path)...)
log.WithFields(log.Fields{
"path": path,
"cmd": cmd,
}).Info("compiling file using lilypond")
out, err := cmd.CombinedOutput()
return string(out), err
}