diff --git a/dagger/build.go b/dagger/build.go index 5d0b076a..36e8f1e2 100644 --- a/dagger/build.go +++ b/dagger/build.go @@ -11,12 +11,12 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog/log" - "dagger.cloud/go/dagger/cc" + "dagger.cloud/go/dagger/compiler" "dagger.cloud/go/stdlib" ) // Build a cue configuration tree from the files in fs. -func CueBuild(ctx context.Context, fs FS, args ...string) (*cc.Value, error) { +func CueBuild(ctx context.Context, fs FS, args ...string) (*compiler.Value, error) { var ( err error lg = log.Ctx(ctx) @@ -59,9 +59,9 @@ func CueBuild(ctx context.Context, fs FS, args ...string) (*cc.Value, error) { if len(instances) != 1 { return nil, errors.New("only one package is supported at a time") } - inst, err := cc.Cue().Build(instances[0]) + inst, err := compiler.Cue().Build(instances[0]) if err != nil { return nil, errors.New(cueerrors.Details(err, &cueerrors.Config{})) } - return cc.Wrap(inst.Value(), inst), nil + return compiler.Wrap(inst.Value(), inst), nil } diff --git a/dagger/cc/cc.go b/dagger/cc/cc.go deleted file mode 100644 index f5039de7..00000000 --- a/dagger/cc/cc.go +++ /dev/null @@ -1,37 +0,0 @@ -package cc - -import ( - "cuelang.org/go/cue" - - cueerrors "cuelang.org/go/cue/errors" - "github.com/pkg/errors" -) - -var ( - // Shared global compiler - cc = &Compiler{} -) - -func Compile(name string, src interface{}) (*Value, error) { - return cc.Compile(name, src) -} - -func EmptyStruct() (*Value, error) { - return cc.EmptyStruct() -} - -// FIXME can be refactored away now? -func Wrap(v cue.Value, inst *cue.Instance) *Value { - return cc.Wrap(v, inst) -} - -func Cue() *cue.Runtime { - return cc.Cue() -} - -func Err(err error) error { - if err == nil { - return nil - } - return errors.New(cueerrors.Details(err, &cueerrors.Config{})) -} diff --git a/dagger/cc/compiler.go b/dagger/cc/compiler.go deleted file mode 100644 index 136c18cf..00000000 --- a/dagger/cc/compiler.go +++ /dev/null @@ -1,56 +0,0 @@ -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) -} diff --git a/dagger/client.go b/dagger/client.go index c2f19ec5..98e1e2da 100644 --- a/dagger/client.go +++ b/dagger/client.go @@ -24,7 +24,7 @@ import ( "github.com/containerd/console" "github.com/moby/buildkit/util/progress/progressui" - "dagger.cloud/go/dagger/cc" + "dagger.cloud/go/dagger/compiler" ) const ( @@ -52,8 +52,8 @@ func NewClient(ctx context.Context, host string) (*Client, error) { }, nil } -// FIXME: return completed *Env, instead of *cc.Value -func (c *Client) Compute(ctx context.Context, env *Env) (*cc.Value, error) { +// FIXME: return completed *Env, instead of *compiler.Value +func (c *Client) Compute(ctx context.Context, env *Env) (*compiler.Value, error) { lg := log.Ctx(ctx) eg, gctx := errgroup.WithContext(ctx) @@ -77,7 +77,7 @@ func (c *Client) Compute(ctx context.Context, env *Env) (*cc.Value, error) { // Spawn output retriever var ( - out *cc.Value + out *compiler.Value err error ) eg.Go(func() error { @@ -86,7 +86,7 @@ func (c *Client) Compute(ctx context.Context, env *Env) (*cc.Value, error) { return err }) - return out, cc.Err(eg.Wait()) + return out, compiler.Err(eg.Wait()) } func (c *Client) buildfn(ctx context.Context, env *Env, ch chan *bk.SolveStatus, w io.WriteCloser) error { @@ -157,11 +157,11 @@ func (c *Client) buildfn(ctx context.Context, env *Env, ch chan *bk.SolveStatus, } // Read tar export stream from buildkit Build(), and extract cue output -func (c *Client) outputfn(ctx context.Context, r io.Reader) (*cc.Value, error) { +func (c *Client) outputfn(ctx context.Context, r io.Reader) (*compiler.Value, error) { lg := log.Ctx(ctx) // FIXME: merge this into env output. - out, err := cc.EmptyStruct() + out, err := compiler.EmptyStruct() if err != nil { return nil, err } @@ -187,7 +187,7 @@ func (c *Client) outputfn(ctx context.Context, r io.Reader) (*cc.Value, error) { } lg.Debug().Msg("outputfn: compiling & merging") - v, err := cc.Compile(h.Name, tr) + v, err := compiler.Compile(h.Name, tr) if err != nil { return nil, err } diff --git a/dagger/compiler/compiler.go b/dagger/compiler/compiler.go new file mode 100644 index 00000000..cfa39434 --- /dev/null +++ b/dagger/compiler/compiler.go @@ -0,0 +1,91 @@ +package compiler + +import ( + "errors" + "sync" + + "cuelang.org/go/cue" + cueerrors "cuelang.org/go/cue/errors" +) + +var ( + // DefaultCompiler is the default Compiler and is used by Compile + DefaultCompiler = &Compiler{} +) + +func Compile(name string, src interface{}) (*Value, error) { + return DefaultCompiler.Compile(name, src) +} + +func EmptyStruct() (*Value, error) { + return DefaultCompiler.EmptyStruct() +} + +// FIXME can be refactored away now? +func Wrap(v cue.Value, inst *cue.Instance) *Value { + return DefaultCompiler.Wrap(v, inst) +} + +func Cue() *cue.Runtime { + return DefaultCompiler.Cue() +} + +func Err(err error) error { + return DefaultCompiler.Err(err) +} + +// 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 (c *Compiler) lock() { + c.l.Lock() +} + +func (c *Compiler) unlock() { + c.l.Unlock() +} + +func (c *Compiler) rlock() { + c.l.RLock() +} + +func (c *Compiler) runlock() { + c.l.RUnlock() +} + +func (c *Compiler) Cue() *cue.Runtime { + return &(c.Runtime) +} + +// Compile an empty struct +func (c *Compiler) EmptyStruct() (*Value, error) { + return c.Compile("", "") +} + +func (c *Compiler) Compile(name string, src interface{}) (*Value, error) { + c.lock() + defer c.unlock() + + inst, err := c.Cue().Compile(name, src) + if err != nil { + // FIXME: cleaner way to unwrap cue error details? + return nil, Err(err) + } + return c.Wrap(inst.Value(), inst), nil +} + +func (c *Compiler) Wrap(v cue.Value, inst *cue.Instance) *Value { + return wrapValue(v, inst, c) +} + +func (c *Compiler) Err(err error) error { + if err == nil { + return nil + } + return errors.New(cueerrors.Details(err, &cueerrors.Config{})) +} diff --git a/dagger/cc/cc_test.go b/dagger/compiler/compiler_test.go similarity index 78% rename from dagger/cc/cc_test.go rename to dagger/compiler/compiler_test.go index ba5be5d4..b60fcec9 100644 --- a/dagger/cc/cc_test.go +++ b/dagger/compiler/compiler_test.go @@ -1,4 +1,4 @@ -package cc +package compiler import ( "testing" @@ -6,7 +6,8 @@ import ( // Test that a non-existing field is detected correctly func TestFieldNotExist(t *testing.T) { - root, err := Compile("test.cue", `foo: "bar"`) + c := &Compiler{} + root, err := c.Compile("test.cue", `foo: "bar"`) if err != nil { t.Fatal(err) } @@ -22,7 +23,8 @@ func TestFieldNotExist(t *testing.T) { // Test that a non-existing definition is detected correctly func TestDefNotExist(t *testing.T) { - root, err := Compile("test.cue", `foo: #bla: "bar"`) + c := &Compiler{} + root, err := c.Compile("test.cue", `foo: #bla: "bar"`) if err != nil { t.Fatal(err) } @@ -37,14 +39,16 @@ func TestDefNotExist(t *testing.T) { } func TestSimple(t *testing.T) { - _, err := EmptyStruct() + c := &Compiler{} + _, err := c.EmptyStruct() if err != nil { t.Fatal(err) } } func TestJSON(t *testing.T) { - v, err := Compile("", `foo: hello: "world"`) + c := &Compiler{} + v, err := c.Compile("", `foo: hello: "world"`) if err != nil { t.Fatal(err) } diff --git a/dagger/cc/json.go b/dagger/compiler/json.go similarity index 89% rename from dagger/cc/json.go rename to dagger/compiler/json.go index 9eef5fef..96c1f373 100644 --- a/dagger/cc/json.go +++ b/dagger/compiler/json.go @@ -1,4 +1,4 @@ -package cc +package compiler import ( "fmt" @@ -6,7 +6,6 @@ import ( "cuelang.org/go/cue" cuejson "cuelang.org/go/encoding/json" "github.com/KromDaniel/jonson" - "github.com/pkg/errors" ) type JSON []byte @@ -20,7 +19,7 @@ func (s JSON) Get(path ...string) ([]byte, error) { ) root, err := jonson.Parse(s) if err != nil { - return nil, errors.Wrap(err, "parse root json") + return nil, fmt.Errorf("parse root json: %w", err) } pointer := root for _, key := range path { @@ -40,7 +39,7 @@ func (s JSON) Unset(path ...string) (JSON, error) { ) root, err := jonson.Parse(s) if err != nil { - return nil, errors.Wrap(err, "unset: parse root json") + return nil, fmt.Errorf("unset: parse root json: %w", err) } var ( pointer = root @@ -71,11 +70,11 @@ func (s JSON) Set(valueJSON []byte, path ...string) (JSON, error) { ) root, err := jonson.Parse(s) if err != nil { - return nil, errors.Wrap(err, "parse root json") + return nil, fmt.Errorf("parse root json: %w", err) } value, err = jonson.Parse(valueJSON) if err != nil { - return nil, errors.Wrapf(err, "SetJSON: parse value json: |%s|", valueJSON) + return nil, fmt.Errorf("SetJSON: parse value json: |%s|: %w", valueJSON, err) } var ( pointer = root diff --git a/dagger/cc/utils.go b/dagger/compiler/utils.go similarity index 96% rename from dagger/cc/utils.go rename to dagger/compiler/utils.go index bf2d6d29..1ea36789 100644 --- a/dagger/cc/utils.go +++ b/dagger/compiler/utils.go @@ -1,4 +1,4 @@ -package cc +package compiler import ( "cuelang.org/go/cue" diff --git a/dagger/cc/value.go b/dagger/compiler/value.go similarity index 94% rename from dagger/cc/value.go rename to dagger/compiler/value.go index e9b73182..28984554 100644 --- a/dagger/cc/value.go +++ b/dagger/compiler/value.go @@ -1,4 +1,4 @@ -package cc +package compiler import ( "cuelang.org/go/cue" @@ -9,6 +9,7 @@ import ( // Use instead of cue.Value and cue.Instance type Value struct { val cue.Value + cc *Compiler inst *cue.Instance } @@ -17,20 +18,21 @@ func (v *Value) CueInst() *cue.Instance { } func (v *Value) Wrap(v2 cue.Value) *Value { - return wrapValue(v2, v.inst) + return wrapValue(v2, v.inst, v.cc) } -func wrapValue(v cue.Value, inst *cue.Instance) *Value { +func wrapValue(v cue.Value, inst *cue.Instance, cc *Compiler) *Value { return &Value{ val: v, + cc: cc, inst: inst, } } // Fill the value in-place, unlike Merge which returns a copy. func (v *Value) Fill(x interface{}) error { - cc.lock() - defer cc.unlock() + v.cc.lock() + defer v.cc.unlock() // If calling Fill() with a Value, we want to use the underlying // cue.Value to fill. @@ -44,8 +46,8 @@ func (v *Value) Fill(x interface{}) error { // LookupPath is a concurrency safe wrapper around cue.Value.LookupPath func (v *Value) LookupPath(p cue.Path) *Value { - cc.rlock() - defer cc.runlock() + v.cc.rlock() + defer v.cc.runlock() return v.Wrap(v.val.LookupPath(p)) } @@ -147,9 +149,9 @@ func (v *Value) Merge(x interface{}, path ...string) (*Value, error) { x = xval.val } - cc.lock() + v.cc.lock() result := v.Wrap(v.val.Fill(x, path...)) - cc.unlock() + v.cc.unlock() return result, result.Validate() } @@ -220,8 +222,8 @@ func (v *Value) Validate() error { // Return cue source for this value func (v *Value) Source() ([]byte, error) { - cc.rlock() - defer cc.runlock() + v.cc.rlock() + defer v.cc.runlock() return cueformat.Node(v.val.Eval().Syntax()) } diff --git a/dagger/dagger_test.go b/dagger/dagger_test.go index fac41884..4725098e 100644 --- a/dagger/dagger_test.go +++ b/dagger/dagger_test.go @@ -3,7 +3,7 @@ package dagger import ( "testing" - "dagger.cloud/go/dagger/cc" + "dagger.cloud/go/dagger/compiler" ) func TestLocalDirs(t *testing.T) { @@ -38,14 +38,14 @@ func mkEnv(t *testing.T, updater, input string) *Env { if err != nil { t.Fatal(err) } - u, err := cc.Compile("updater.cue", updater) + u, err := compiler.Compile("updater.cue", updater) if err != nil { t.Fatal(err) } if err := env.SetUpdater(u); err != nil { t.Fatal(err) } - i, err := cc.Compile("input.cue", input) + i, err := compiler.Compile("input.cue", input) if err != nil { t.Fatal(err) } diff --git a/dagger/env.go b/dagger/env.go index 3cd18f43..9bd443ed 100644 --- a/dagger/env.go +++ b/dagger/env.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog/log" - "dagger.cloud/go/dagger/cc" + "dagger.cloud/go/dagger/compiler" ) type Env struct { @@ -18,30 +18,30 @@ type Env struct { // FIXME: simplify Env by making it single layer? Each layer is one env. // How to update the base configuration - updater *cc.Value + updater *compiler.Value // Layer 1: base configuration - base *cc.Value + base *compiler.Value // Layer 2: user inputs - input *cc.Value + input *compiler.Value // Layer 3: computed values - output *cc.Value + output *compiler.Value // All layers merged together: base + input + output - state *cc.Value + state *compiler.Value } -func (env *Env) Updater() *cc.Value { +func (env *Env) Updater() *compiler.Value { return env.updater } // Set the updater script for this environment. -func (env *Env) SetUpdater(v *cc.Value) error { +func (env *Env) SetUpdater(v *compiler.Value) error { if v == nil { var err error - v, err = cc.Compile("", "[]") + v, err = compiler.Compile("", "[]") if err != nil { return err } @@ -51,7 +51,7 @@ func (env *Env) SetUpdater(v *cc.Value) error { } func NewEnv() (*Env, error) { - empty, err := cc.EmptyStruct() + empty, err := compiler.EmptyStruct() if err != nil { return nil, err } @@ -67,18 +67,18 @@ func NewEnv() (*Env, error) { return env, nil } -func (env *Env) State() *cc.Value { +func (env *Env) State() *compiler.Value { return env.state } -func (env *Env) Input() *cc.Value { +func (env *Env) Input() *compiler.Value { return env.input } -func (env *Env) SetInput(i *cc.Value) error { +func (env *Env) SetInput(i *compiler.Value) error { if i == nil { var err error - i, err = cc.EmptyStruct() + i, err = compiler.EmptyStruct() if err != nil { return err } @@ -112,11 +112,11 @@ func (env *Env) Update(ctx context.Context, s Solver) error { ) } -func (env *Env) Base() *cc.Value { +func (env *Env) Base() *compiler.Value { return env.base } -func (env *Env) Output() *cc.Value { +func (env *Env) Output() *compiler.Value { return env.output } @@ -126,9 +126,9 @@ func (env *Env) Output() *cc.Value { // by user-specified scripts. func (env *Env) LocalDirs() map[string]string { dirs := map[string]string{} - localdirs := func(code ...*cc.Value) { + localdirs := func(code ...*compiler.Value) { Analyze( - func(op *cc.Value) error { + func(op *compiler.Value) error { do, err := op.Get("do").String() if err != nil { return err @@ -148,7 +148,7 @@ func (env *Env) LocalDirs() map[string]string { } // 1. Scan the environment state env.State().Walk( - func(v *cc.Value) bool { + func(v *compiler.Value) bool { compute := v.Get("#dagger.compute") if !compute.Exists() { // No compute script @@ -164,14 +164,14 @@ func (env *Env) LocalDirs() map[string]string { return dirs } -// FIXME: this is just a 3-way merge. Add var args to cc.Value.Merge. -func (env *Env) set(base, input, output *cc.Value) (err error) { - // FIXME: make this cleaner in *cc.Value by keeping intermediary instances +// FIXME: this is just a 3-way merge. Add var args to compiler.Value.Merge. +func (env *Env) set(base, input, output *compiler.Value) (err error) { + // FIXME: make this cleaner in *compiler.Value by keeping intermediary instances // FIXME: state.CueInst() must return an instance with the same // contents as state.v, for the purposes of cueflow. - // That is not currently how *cc.Value works, so we prepare the cue + // That is not currently how *compiler.Value works, so we prepare the cue // instance manually. - // --> refactor the cc.Value API to do this for us. + // --> refactor the compiler.Value API to do this for us. stateInst := env.state.CueInst() stateInst, err = stateInst.Fill(base.Cue()) @@ -187,7 +187,7 @@ func (env *Env) set(base, input, output *cc.Value) (err error) { return errors.Wrap(err, "merge output with base & input") } - state := cc.Wrap(stateInst.Value(), stateInst) + state := compiler.Wrap(stateInst.Value(), stateInst) // commit env.base = base @@ -201,9 +201,9 @@ func (env *Env) set(base, input, output *cc.Value) (err error) { // (Use with FS.Change) func (env *Env) Export(fs FS) (FS, error) { // FIXME: we serialize as JSON to guarantee a self-contained file. - // cc.Value.Save() leaks imports, so requires a shared cue.mod with + // compiler.Value.Save() leaks imports, so requires a shared cue.mod with // client which is undesirable. - // Once cc.Value.Save() resolves non-builtin imports with a tree shake, + // Once compiler.Value.Save() resolves non-builtin imports with a tree shake, // we can use it here. // FIXME: Exporting base/input/output separately causes merge errors. @@ -237,11 +237,11 @@ func (env *Env) Compute(ctx context.Context, s Solver) error { flowInst := env.state.CueInst() lg. Debug(). - Str("value", cc.Wrap(flowInst.Value(), flowInst).JSON().String()). + Str("value", compiler.Wrap(flowInst.Value(), flowInst).JSON().String()). Msg("walking") // Initialize empty output - output, err := cc.EmptyStruct() + output, err := compiler.EmptyStruct() if err != nil { return err } @@ -279,7 +279,7 @@ func (env *Env) Compute(ctx context.Context, s Solver) error { } // Cueflow match func flowMatchFn := func(flowVal cue.Value) (cueflow.Runner, error) { - v := cc.Wrap(flowVal, flowInst) + v := compiler.Wrap(flowVal, flowInst) compute := v.Get("#dagger.compute") if !compute.Exists() { // No compute script @@ -303,7 +303,7 @@ func (env *Env) Compute(ctx context.Context, s Solver) error { Str("dependency", dep.Path().String()). Msg("dependency detected") } - v := cc.Wrap(t.Value(), flowInst) + v := compiler.Wrap(t.Value(), flowInst) p := NewPipeline(s, NewFillable(t)) return p.Do(ctx, v) }), nil diff --git a/dagger/fs.go b/dagger/fs.go index 3234deac..6515e2dc 100644 --- a/dagger/fs.go +++ b/dagger/fs.go @@ -11,7 +11,7 @@ import ( "github.com/pkg/errors" fstypes "github.com/tonistiigi/fsutil/types" - "dagger.cloud/go/dagger/cc" + "dagger.cloud/go/dagger/compiler" ) type Stat struct { @@ -27,7 +27,7 @@ type FS struct { s Solver } -func (fs FS) WriteValueJSON(filename string, v *cc.Value) FS { +func (fs FS) WriteValueJSON(filename string, v *compiler.Value) FS { return fs.Change(func(st llb.State) llb.State { return st.File( llb.Mkfile(filename, 0600, v.JSON()), @@ -35,7 +35,7 @@ func (fs FS) WriteValueJSON(filename string, v *cc.Value) FS { }) } -func (fs FS) WriteValueCUE(filename string, v *cc.Value) (FS, error) { +func (fs FS) WriteValueCUE(filename string, v *compiler.Value) (FS, error) { src, err := v.Source() if err != nil { return fs, err diff --git a/dagger/input.go b/dagger/input.go index 42f9ca17..92020dbe 100644 --- a/dagger/input.go +++ b/dagger/input.go @@ -9,16 +9,16 @@ import ( "cuelang.org/go/cue" "github.com/spf13/pflag" - "dagger.cloud/go/dagger/cc" + "dagger.cloud/go/dagger/compiler" ) // A mutable cue value with an API suitable for user inputs, // such as command-line flag parsing. type InputValue struct { - root *cc.Value + root *compiler.Value } -func (iv *InputValue) Value() *cc.Value { +func (iv *InputValue) Value() *compiler.Value { return iv.root } @@ -28,7 +28,7 @@ func (iv *InputValue) String() string { } func NewInputValue(base interface{}) (*InputValue, error) { - root, err := cc.Compile("base", base) + root, err := compiler.Compile("base", base) if err != nil { return nil, err } @@ -101,7 +101,7 @@ func (f dirFlag) Set(s string) error { if err != nil { return nil, err } - return cc.Compile("", fmt.Sprintf( + return compiler.Compile("", fmt.Sprintf( `#dagger: compute: [{do:"local",dir:"%s", include:%s}]`, s, include, @@ -139,7 +139,7 @@ func (f gitFlag) Set(s string) error { u.Fragment = "" remote := u.String() - return cc.Compile("", fmt.Sprintf( + return compiler.Compile("", fmt.Sprintf( `#dagger: compute: [{do:"fetch-git", remote:"%s", ref:"%s"}]`, remote, ref, @@ -177,7 +177,7 @@ func (f sourceFlag) Set(s string) error { } switch u.Scheme { case "", "file": - return cc.Compile( + return compiler.Compile( "source", // FIXME: include only cue files as a shortcut. Make this configurable somehow. fmt.Sprintf(`[{do:"local",dir:"%s",include:["*.cue","cue.mod"]}]`, u.Host+u.Path), @@ -210,7 +210,7 @@ type cueFlag struct { func (f cueFlag) Set(s string) error { return f.iv.Set(s, func(s string) (interface{}, error) { - return cc.Compile("cue input", s) + return compiler.Compile("cue input", s) }) } diff --git a/dagger/pipeline.go b/dagger/pipeline.go index 41903208..fbaf81ba 100644 --- a/dagger/pipeline.go +++ b/dagger/pipeline.go @@ -10,7 +10,7 @@ import ( "github.com/rs/zerolog/log" "gopkg.in/yaml.v3" - "dagger.cloud/go/dagger/cc" + "dagger.cloud/go/dagger/compiler" ) // An execution pipeline @@ -32,8 +32,8 @@ func (p *Pipeline) FS() FS { return p.fs } -func ops(code ...*cc.Value) ([]*cc.Value, error) { - ops := []*cc.Value{} +func ops(code ...*compiler.Value) ([]*compiler.Value, error) { + ops := []*compiler.Value{} // 1. Decode 'code' into a single flat array of operations. for _, x := range code { // 1. attachment array @@ -58,7 +58,7 @@ func ops(code ...*cc.Value) ([]*cc.Value, error) { return ops, nil } -func Analyze(fn func(*cc.Value) error, code ...*cc.Value) error { +func Analyze(fn func(*compiler.Value) error, code ...*compiler.Value) error { ops, err := ops(code...) if err != nil { return err @@ -71,7 +71,7 @@ func Analyze(fn func(*cc.Value) error, code ...*cc.Value) error { return nil } -func analyzeOp(fn func(*cc.Value) error, op *cc.Value) error { +func analyzeOp(fn func(*compiler.Value) error, op *compiler.Value) error { if err := fn(op); err != nil { return err } @@ -83,7 +83,7 @@ func analyzeOp(fn func(*cc.Value) error, op *cc.Value) error { case "load", "copy": return Analyze(fn, op.Get("from")) case "exec": - return op.Get("mount").RangeStruct(func(dest string, mnt *cc.Value) error { + return op.Get("mount").RangeStruct(func(dest string, mnt *compiler.Value) error { if from := mnt.Get("from"); from.Exists() { return Analyze(fn, from) } @@ -97,7 +97,7 @@ func analyzeOp(fn func(*cc.Value) error, op *cc.Value) error { // 1) a single operation // 2) an array of operations // 3) a value with an attached array of operations -func (p *Pipeline) Do(ctx context.Context, code ...*cc.Value) error { +func (p *Pipeline) Do(ctx context.Context, code ...*compiler.Value) error { ops, err := ops(code...) if err != nil { return err @@ -132,7 +132,7 @@ func (p *Pipeline) Do(ctx context.Context, code ...*cc.Value) error { return nil } -func (p *Pipeline) doOp(ctx context.Context, op *cc.Value) error { +func (p *Pipeline) doOp(ctx context.Context, op *compiler.Value) error { do, err := op.Get("do").String() if err != nil { return err @@ -165,7 +165,7 @@ func (p *Pipeline) Tmp() *Pipeline { return NewPipeline(p.s, nil) } -func (p *Pipeline) Subdir(ctx context.Context, op *cc.Value) error { +func (p *Pipeline) Subdir(ctx context.Context, op *compiler.Value) error { // FIXME: this could be more optimized by carrying subdir path as metadata, // and using it in copy, load or mount. @@ -186,7 +186,7 @@ func (p *Pipeline) Subdir(ctx context.Context, op *cc.Value) error { return nil } -func (p *Pipeline) Copy(ctx context.Context, op *cc.Value) error { +func (p *Pipeline) Copy(ctx context.Context, op *compiler.Value) error { // Decode copy options src, err := op.Get("src").String() if err != nil { @@ -218,7 +218,7 @@ func (p *Pipeline) Copy(ctx context.Context, op *cc.Value) error { return nil } -func (p *Pipeline) Local(ctx context.Context, op *cc.Value) error { +func (p *Pipeline) Local(ctx context.Context, op *compiler.Value) error { dir, err := op.Get("dir").String() if err != nil { return err @@ -237,7 +237,7 @@ func (p *Pipeline) Local(ctx context.Context, op *cc.Value) error { return nil } -func (p *Pipeline) Exec(ctx context.Context, op *cc.Value) error { +func (p *Pipeline) Exec(ctx context.Context, op *compiler.Value) error { opts := []llb.RunOption{} var cmd struct { Args []string @@ -284,9 +284,9 @@ func (p *Pipeline) Exec(ctx context.Context, op *cc.Value) error { return nil } -func (p *Pipeline) mountAll(ctx context.Context, mounts *cc.Value) ([]llb.RunOption, error) { +func (p *Pipeline) mountAll(ctx context.Context, mounts *compiler.Value) ([]llb.RunOption, error) { opts := []llb.RunOption{} - err := mounts.RangeStruct(func(dest string, mnt *cc.Value) error { + err := mounts.RangeStruct(func(dest string, mnt *compiler.Value) error { o, err := p.mount(ctx, dest, mnt) if err != nil { return err @@ -297,7 +297,7 @@ func (p *Pipeline) mountAll(ctx context.Context, mounts *cc.Value) ([]llb.RunOpt return opts, err } -func (p *Pipeline) mount(ctx context.Context, dest string, mnt *cc.Value) (llb.RunOption, error) { +func (p *Pipeline) mount(ctx context.Context, dest string, mnt *compiler.Value) (llb.RunOption, error) { if s, err := mnt.String(); err == nil { // eg. mount: "/foo": "cache" switch s { @@ -338,7 +338,7 @@ func (p *Pipeline) mount(ctx context.Context, dest string, mnt *cc.Value) (llb.R return llb.AddMount(dest, from.FS().LLB(), mo...), nil } -func (p *Pipeline) Export(ctx context.Context, op *cc.Value) error { +func (p *Pipeline) Export(ctx context.Context, op *compiler.Value) error { source, err := op.Get("source").String() if err != nil { return err @@ -419,7 +419,7 @@ func unmarshalAnything(data []byte, fn unmarshaller) (interface{}, error) { return o, err } -func (p *Pipeline) Load(ctx context.Context, op *cc.Value) error { +func (p *Pipeline) Load(ctx context.Context, op *compiler.Value) error { // Execute 'from' in a tmp pipeline, and use the resulting fs from := p.Tmp() if err := from.Do(ctx, op.Get("from")); err != nil { @@ -429,7 +429,7 @@ func (p *Pipeline) Load(ctx context.Context, op *cc.Value) error { return nil } -func (p *Pipeline) FetchContainer(ctx context.Context, op *cc.Value) error { +func (p *Pipeline) FetchContainer(ctx context.Context, op *compiler.Value) error { ref, err := op.Get("ref").String() if err != nil { return err @@ -439,7 +439,7 @@ func (p *Pipeline) FetchContainer(ctx context.Context, op *cc.Value) error { return nil } -func (p *Pipeline) FetchGit(ctx context.Context, op *cc.Value) error { +func (p *Pipeline) FetchGit(ctx context.Context, op *compiler.Value) error { remote, err := op.Get("remote").String() if err != nil { return err