universe vendoring

Rather than injecting universe at runtime, this change will vendor
alpha.dagger.io in `cue.mod` directly.

Fixes #700

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-07-01 19:42:52 +02:00
parent bf6a9f3588
commit f58ee5811b
17 changed files with 170 additions and 59 deletions

View File

@@ -1,8 +1,13 @@
package stdlib
import (
"context"
"embed"
"fmt"
"io/fs"
"os"
"path"
"path/filepath"
)
var (
@@ -13,3 +18,38 @@ var (
PackageName = "alpha.dagger.io"
Path = path.Join("cue.mod", "pkg", PackageName)
)
func Vendor(ctx context.Context, mod string) error {
// Remove any existing copy of the universe
if err := os.RemoveAll(path.Join(mod, Path)); err != nil {
return err
}
// Write the current version
return 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(FS, p)
if err != nil {
return fmt.Errorf("%s: %w", p, err)
}
overlayPath := path.Join(mod, Path, p)
if err := os.MkdirAll(filepath.Dir(overlayPath), 0755); err != nil {
return err
}
return os.WriteFile(overlayPath, contents, 0600)
})
}