-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocal.go
51 lines (43 loc) · 1.02 KB
/
local.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package exec
import (
"bytes"
"context"
"os/exec"
"github.com/digineo/texd/tex"
"go.uber.org/zap"
)
type localExec struct {
baseExec
path string // overrides command to execute (in tests)
}
func LocalExec(doc Document) Exec {
return &localExec{
baseExec: baseExec{doc: doc},
}
}
func (x *localExec) Run(ctx context.Context, log *zap.Logger) error {
dir, args, err := x.extract()
if err != nil {
return tex.CompilationError("invalid document", err, nil)
}
if x.path != "" {
// in tests, we don't want to actually execute latexmk
args[0] = x.path
}
var stderr bytes.Buffer
cmd := exec.CommandContext(ctx, args[0], args[1:]...)
cmd.Dir = dir
cmd.Stderr = &stderr
log.Debug("running latexmk", zap.Strings("args", args[1:]))
if err := cmd.Run(); err != nil {
log.Error("compilation failed",
zap.String("stderr", stderr.String()),
zap.Error(err))
return tex.CompilationError("compilation failed", err, tex.KV{
"cmd": args[0],
"args": args[1:],
"output": stderr.String(),
})
}
return nil
}