kindsys: Fix CUE code generation on Windows (#62812)
* fix Windows paths * fix remaining paths issues * clean up multiple use of Dir() * fix headers in generated files
This commit is contained in:
@@ -47,7 +47,7 @@ func SlashHeaderMapper(maingen string) codejen.FileMapper {
|
|||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
if err := tmpls.Lookup("gen_header.tmpl").Execute(buf, tvars_gen_header{
|
if err := tmpls.Lookup("gen_header.tmpl").Execute(buf, tvars_gen_header{
|
||||||
MainGenerator: maingen,
|
MainGenerator: filepath.ToSlash(maingen),
|
||||||
Using: f.From,
|
Using: f.From,
|
||||||
Leader: leader,
|
Leader: leader,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
|||||||
+2
-2
@@ -116,7 +116,7 @@ func prefixFS(prefix string, fsys fs.FS) (fs.FS, error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := fs.ReadFile(fsys, path)
|
b, err := fs.ReadFile(fsys, filepath.ToSlash(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -217,7 +217,7 @@ func BuildGrafanaInstance(ctx *cue.Context, relpath string, pkg string, overlay
|
|||||||
//
|
//
|
||||||
// NOTE This function will be deprecated in favor of a more generic loader
|
// NOTE This function will be deprecated in favor of a more generic loader
|
||||||
func LoadInstanceWithGrafana(fsys fs.FS, dir string, opts ...load.Option) (*build.Instance, error) {
|
func LoadInstanceWithGrafana(fsys fs.FS, dir string, opts ...load.Option) (*build.Instance, error) {
|
||||||
if modf, err := fs.ReadFile(fsys, filepath.Join("cue.mod", "module.cue")); err != nil {
|
if modf, err := fs.ReadFile(fsys, "cue.mod/module.cue"); err != nil {
|
||||||
// delegate error handling
|
// delegate error handling
|
||||||
return load.InstanceWithThema(fsys, dir, opts...)
|
return load.InstanceWithThema(fsys, dir, opts...)
|
||||||
} else if modname, err := cuecontext.New().CompileBytes(modf).LookupPath(cue.MakePath(cue.Str("module"))).String(); err != nil {
|
} else if modname, err := cuecontext.New().CompileBytes(modf).LookupPath(cue.MakePath(cue.Str("module"))).String(); err != nil {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func (psr *declParser) Parse(root fs.FS) ([]*PluginDecl, error) {
|
|||||||
|
|
||||||
decls := make([]*PluginDecl, 0)
|
decls := make([]*PluginDecl, 0)
|
||||||
for _, plugin := range plugins {
|
for _, plugin := range plugins {
|
||||||
path := filepath.Dir(plugin)
|
path := filepath.ToSlash(filepath.Dir(plugin))
|
||||||
base := filepath.Base(path)
|
base := filepath.Base(path)
|
||||||
if skip, ok := psr.skip[base]; ok && skip {
|
if skip, ok := psr.skip[base]; ok && skip {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ func ParsePluginFS(fsys fs.FS, rt *thema.Runtime) (ParsedPlugin, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ensureCueMod(fsys fs.FS, pdef plugindef.PluginDef) (fs.FS, error) {
|
func ensureCueMod(fsys fs.FS, pdef plugindef.PluginDef) (fs.FS, error) {
|
||||||
if modf, err := fs.ReadFile(fsys, filepath.Join("cue.mod", "module.cue")); err != nil {
|
if modf, err := fs.ReadFile(fsys, "cue.mod/module.cue"); err != nil {
|
||||||
if !errors.Is(err, fs.ErrNotExist) {
|
if !errors.Is(err, fs.ErrNotExist) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"cuelang.org/go/cue/cuecontext"
|
"cuelang.org/go/cue/cuecontext"
|
||||||
"github.com/dave/dst"
|
"github.com/dave/dst"
|
||||||
@@ -40,8 +39,8 @@ func main() {
|
|||||||
fmt.Fprintf(os.Stderr, "could not get working directory: %s", err)
|
fmt.Fprintf(os.Stderr, "could not get working directory: %s", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
grootp := strings.Split(cwd, string(os.PathSeparator))
|
|
||||||
groot := filepath.Join(string(os.PathSeparator), filepath.Join(grootp[:len(grootp)-3]...))
|
groot := filepath.Clean(filepath.Join(cwd, "../../.."))
|
||||||
|
|
||||||
jfs := elsedie(jl.GenerateFS(lin))("plugindef jenny pipeline failed")
|
jfs := elsedie(jl.GenerateFS(lin))("plugindef jenny pipeline failed")
|
||||||
if _, set := os.LookupEnv("CODEGEN_VERIFY"); set {
|
if _, set := os.LookupEnv("CODEGEN_VERIFY"); set {
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(fmt.Errorf("could not get working directory: %s", err))
|
log.Fatal(fmt.Errorf("could not get working directory: %s", err))
|
||||||
}
|
}
|
||||||
grootp := strings.Split(cwd, sep)
|
groot := filepath.Clean(filepath.Join(cwd, "../../.."))
|
||||||
groot := filepath.Join(sep, filepath.Join(grootp[:len(grootp)-3]...))
|
|
||||||
rt := cuectx.GrafanaThemaRuntime()
|
rt := cuectx.GrafanaThemaRuntime()
|
||||||
|
|
||||||
pluginKindGen := codejen.JennyListWithNamer(func(d *pfs.PluginDecl) string {
|
pluginKindGen := codejen.JennyListWithNamer(func(d *pfs.PluginDecl) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user