This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/dagger/cc/compiler.go
Solomon Hykes be8f600c59 dagger/cc: remove locking methods from public API
Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
2021-02-13 17:40:21 +00:00

57 lines
991 B
Go

package cc
import (
"sync"
"cuelang.org/go/cue"
)
// Polyfill for a cue runtime
// (we call it compiler to avoid confusion with dagger runtime)
// Use this instead of cue.Runtime
type Compiler struct {
l sync.RWMutex
cue.Runtime
}
func (cc *Compiler) lock() {
cc.l.Lock()
}
func (cc *Compiler) unlock() {
cc.l.Unlock()
}
func (cc *Compiler) rlock() {
cc.l.RLock()
}
func (cc *Compiler) runlock() {
cc.l.RUnlock()
}
func (cc *Compiler) Cue() *cue.Runtime {
return &(cc.Runtime)
}
// Compile an empty struct
func (cc *Compiler) EmptyStruct() (*Value, error) {
return cc.Compile("", "")
}
func (cc *Compiler) Compile(name string, src interface{}) (*Value, error) {
cc.lock()
defer cc.unlock()
inst, err := cc.Cue().Compile(name, src)
if err != nil {
// FIXME: cleaner way to unwrap cue error details?
return nil, Err(err)
}
return cc.Wrap(inst.Value(), inst), nil
}
func (cc *Compiler) Wrap(v cue.Value, inst *cue.Instance) *Value {
return wrapValue(v, inst)
}