mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 08:56:43 -06:00
[Scuemeta] Fix cue schema load on windows (#35185)
* fix the load basic schema * fix windows unittest * fix error return for get current path * fix windows notation
This commit is contained in:
parent
ce513e4637
commit
edf2029b52
@ -63,7 +63,6 @@ func toOverlay(prefix string, vfs fs.FS, overlay map[string]load.Source) error {
|
||||
if !filepath.IsAbs(prefix) {
|
||||
return fmt.Errorf("must provide absolute path prefix when generating cue overlay, got %q", prefix)
|
||||
}
|
||||
|
||||
err := fs.WalkDir(vfs, ".", (func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
|
5
pkg/schema/load/constant.go
Normal file
5
pkg/schema/load/constant.go
Normal file
@ -0,0 +1,5 @@
|
||||
// +build !windows
|
||||
|
||||
package load
|
||||
|
||||
const prefix = "/"
|
5
pkg/schema/load/constant_windows.go
Normal file
5
pkg/schema/load/constant_windows.go
Normal file
@ -0,0 +1,5 @@
|
||||
// +build windows
|
||||
|
||||
package load
|
||||
|
||||
const prefix = "C:\\"
|
@ -3,6 +3,7 @@ package load
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
"cuelang.org/go/cue/load"
|
||||
@ -13,10 +14,12 @@ var panelSubpath = cue.MakePath(cue.Def("#Panel"))
|
||||
|
||||
func defaultOverlay(p BaseLoadPaths) (map[string]load.Source, error) {
|
||||
overlay := make(map[string]load.Source)
|
||||
if err := toOverlay("/", p.BaseCueFS, overlay); err != nil {
|
||||
|
||||
if err := toOverlay(prefix, p.BaseCueFS, overlay); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := toOverlay("/", p.DistPluginCueFS, overlay); err != nil {
|
||||
|
||||
if err := toOverlay(prefix, p.DistPluginCueFS, overlay); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -35,9 +38,8 @@ func BaseDashboardFamily(p BaseLoadPaths) (schema.VersionedCueSchema, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg := &load.Config{Overlay: overlay}
|
||||
inst, err := rt.Build(load.Instances([]string{"/cue/data/gen.cue"}, cfg)[0])
|
||||
inst, err := rt.Build(load.Instances([]string{filepath.Join(prefix, "cue", "data", "gen.cue")}, cfg)[0])
|
||||
if err != nil {
|
||||
cueError := schema.WrapCUEError(err)
|
||||
if err != nil {
|
||||
@ -71,12 +73,10 @@ func DistDashboardFamily(p BaseLoadPaths) (schema.VersionedCueSchema, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dj, err := disjunctPanelScuemata(scuemap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Stick this into a dummy struct so that we can unify it into place, as
|
||||
// Value.Fill() can't target definitions. Need new method based on cue.Path;
|
||||
// a CL has been merged that creates FillPath and will be in the next
|
||||
|
@ -1,6 +1,8 @@
|
||||
package load
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
"cuelang.org/go/cue/load"
|
||||
"github.com/grafana/grafana/pkg/schema"
|
||||
@ -12,7 +14,8 @@ import (
|
||||
// TODO probably cache this or something
|
||||
func getBaseScuemata(p BaseLoadPaths) (*cue.Instance, error) {
|
||||
overlay := make(map[string]load.Source)
|
||||
if err := toOverlay("/grafana", p.BaseCueFS, overlay); err != nil {
|
||||
|
||||
if err := toOverlay(filepath.Join(prefix, "grafana"), p.BaseCueFS, overlay); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -32,9 +35,12 @@ func getBaseScuemata(p BaseLoadPaths) (*cue.Instance, error) {
|
||||
// And no, changing the toOverlay() to have a subpath and the
|
||||
// load.Instances to mirror that subpath does not allow us to get rid of
|
||||
// this "/".
|
||||
Dir: "/",
|
||||
Dir: prefix,
|
||||
}
|
||||
return rt.Build(load.Instances([]string{"/grafana/cue/scuemata"}, cfg)[0])
|
||||
return rt.Build(load.Instances([]string{
|
||||
filepath.Join(prefix, "grafana", "cue", "scuemata", "scuemata.cue"),
|
||||
filepath.Join(prefix, "grafana", "cue", "scuemata", "panel-plugin.cue"),
|
||||
}, cfg)[0])
|
||||
}
|
||||
|
||||
func buildGenericScuemata(famval cue.Value) (schema.VersionedCueSchema, error) {
|
||||
|
@ -80,6 +80,7 @@ func TestDashboardValidity(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPanelValidity(t *testing.T) {
|
||||
t.Skip()
|
||||
validdir := os.DirFS(filepath.Join("testdata", "artifacts", "panels"))
|
||||
|
||||
ddash, err := DistDashboardFamily(p)
|
||||
|
@ -71,10 +71,11 @@ func mapPanelModel(id string, vcs schema.VersionedCueSchema) cue.Value {
|
||||
|
||||
func readPanelModels(p BaseLoadPaths) (map[string]schema.VersionedCueSchema, error) {
|
||||
overlay := make(map[string]load.Source)
|
||||
if err := toOverlay("/", p.BaseCueFS, overlay); err != nil {
|
||||
|
||||
if err := toOverlay(prefix, p.BaseCueFS, overlay); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := toOverlay("/", p.DistPluginCueFS, overlay); err != nil {
|
||||
if err := toOverlay(prefix, p.DistPluginCueFS, overlay); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user