cleanup: solver/fs
- Solver: Encapsulates all access to Buildkit. Can solve plain LLB, invoke external frontends (for DockerBuild) and export (for ContainerPush) - FS (now BuildkitFS) implements the standard Go 1.16 io/fs.FS interface and provides a read-only filesystem on top of a buildkit result. It can be used with built-ins such as fs.WalkDir (no need to have our own Walk functions anymore) - Moved CueBuild into compiler.Build since it no longer depends on Buildkit. Instead it relies on the io/fs.FS interface, which is used both for the base config and the stdlib (go:embed also uses io/fs.FS). Overlaying base and the stdlib is now done by the same code. Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
@@ -2,48 +2,14 @@ package stdlib
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
cueload "cuelang.org/go/cue/load"
|
||||
)
|
||||
|
||||
// FS contains the filesystem of the stdlib.
|
||||
//go:embed **/*.cue **/*/*.cue
|
||||
var FS embed.FS
|
||||
var (
|
||||
// FS contains the filesystem of the stdlib.
|
||||
//go:embed **/*.cue **/*/*.cue
|
||||
FS embed.FS
|
||||
|
||||
const (
|
||||
stdlibPackageName = "dagger.io"
|
||||
PackageName = "dagger.io"
|
||||
Path = path.Join("cue.mod", "pkg", PackageName)
|
||||
)
|
||||
|
||||
func Overlay(prefixPath string) (map[string]cueload.Source, error) {
|
||||
overlay := map[string]cueload.Source{}
|
||||
|
||||
err := fs.WalkDir(FS, ".", func(p string, entry fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !entry.Type().IsRegular() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if filepath.Ext(entry.Name()) != ".cue" {
|
||||
return nil
|
||||
}
|
||||
|
||||
contents, err := FS.ReadFile(p)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", p, err)
|
||||
}
|
||||
|
||||
overlayPath := path.Join(prefixPath, "cue.mod", "pkg", stdlibPackageName, p)
|
||||
|
||||
overlay[overlayPath] = cueload.FromBytes(contents)
|
||||
return nil
|
||||
})
|
||||
|
||||
return overlay, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user