diff --git a/pkg/interp/interp.go b/pkg/interp/interp.go index 09f1f864..9b0203e9 100644 --- a/pkg/interp/interp.go +++ b/pkg/interp/interp.go @@ -440,12 +440,11 @@ const ( type evalContext struct { // structcheck has problems with embedding https://gitlab.com/opennota/check#known-limitations ctx context.Context - stdout Output // TODO: rename? + stdout Output mode RunMode } type Interp struct { - // variables map[string]interface{} registry *registry.Registry os OS initFqQuery *gojq.Query @@ -454,7 +453,7 @@ type Interp struct { // global state, is ref as Interp i cloned per eval state *interface{} - // new for each run, other values are copied by ref + // new for each run, other values are copied by value evalContext evalContext } @@ -534,10 +533,6 @@ func (i *Interp) Main(ctx context.Context, stdout Output, version string) error } func (i *Interp) Eval(ctx context.Context, mode RunMode, c interface{}, src string, filename string, stdout Output) (gojq.Iter, error) { - var err error - // TODO: did not work - // nq := &(*q) - gq, err := gojq.Parse(src) if err != nil { p := queryErrorPosition(src, err) @@ -692,6 +687,23 @@ func (i *Interp) Eval(ctx context.Context, mode RunMode, c interface{}, src stri } } + // TODO: some better way of handling relative includes that + // works with @builtin etc + basePath := filepath.Dir(name) + for _, i := range q.Imports { + rewritePath := func(base, path string) string { + if strings.HasPrefix(i.IncludePath, "@") { + return path + } + if filepath.IsAbs(i.IncludePath) { + return path + } + return filepath.Join(base, path) + } + i.IncludePath = rewritePath(basePath, i.IncludePath) + i.ImportPath = rewritePath(basePath, i.ImportPath) + } + if p.cache { i.includeCache[filename] = q } diff --git a/pkg/interp/interp.jq b/pkg/interp/interp.jq index 57358a39..3cb39e29 100644 --- a/pkg/interp/interp.jq +++ b/pkg/interp/interp.jq @@ -1,6 +1,6 @@ -include "@builtin/internal"; -include "@builtin/funcs"; -include "@builtin/args"; +include "internal"; +include "funcs"; +include "args"; # will include all per format specific function etc include "@format/all";