From 447606047bdd32f79029a4be5424af3a09ea15f2 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Fri, 2 Apr 2021 13:16:44 +0200 Subject: [PATCH] cmd/cue/cmd: load import dependencies of tool files Fixes #869 Fixes #871 Change-Id: I7c439d298d819bfc20c33f2e028a0216a57c4307 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9303 Reviewed-by: CUE cueckoo Reviewed-by: Paul Jolly --- cmd/cue/cmd/common.go | 9 ++++++++ cmd/cue/cmd/testdata/script/cmd_deppkg.txt | 25 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 cmd/cue/cmd/testdata/script/cmd_deppkg.txt diff --git a/cmd/cue/cmd/common.go b/cmd/cue/cmd/common.go index 1b51472a6..0e08f39a9 100644 --- a/cmd/cue/cmd/common.go +++ b/cmd/cue/cmd/common.go @@ -615,6 +615,15 @@ func buildTools(cmd *Command, tags, args []string) (*cue.Instance, error) { inst = cue.Merge(insts...) } + r := internal.GetRuntime(inst).(*cue.Runtime) + for _, b := range binst { + for _, i := range b.Imports { + if _, err := r.Build(i); err != nil { + return nil, err + } + } + } + inst = inst.Build(ti) return inst, inst.Err } diff --git a/cmd/cue/cmd/testdata/script/cmd_deppkg.txt b/cmd/cue/cmd/testdata/script/cmd_deppkg.txt new file mode 100644 index 000000000..7e817f827 --- /dev/null +++ b/cmd/cue/cmd/testdata/script/cmd_deppkg.txt @@ -0,0 +1,25 @@ +cue cmd foo +cmp stdout cue_cmd_foo_both.golden + +-- cue.mod/module.cue -- +module: "example.org/test" +-- sub/sub.cue -- +package sub + +User: "sub" +-- x_tool.cue -- +package x + +import ( + "tool/cli" + + "example.org/test/sub" +) + +command: foo: cli.Print & { + text: "test \(sub.User)" +} +-- cue_eval.golden -- +x: "sub" +-- cue_cmd_foo_both.golden -- +test sub \ No newline at end of file