remove hardcoded stdlib path

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-12-01 12:03:41 -08:00
parent 5b7b1cab79
commit 337ed0d1cc
9 changed files with 21 additions and 13 deletions

View File

@ -12,6 +12,7 @@ import (
"go.dagger.io/dagger/client"
"go.dagger.io/dagger/compiler"
"go.dagger.io/dagger/state"
"go.dagger.io/dagger/stdlib"
)
func CurrentProject(ctx context.Context) *state.Project {
@ -90,7 +91,7 @@ func FormatValue(val *compiler.Value) string {
}
if val.LookupPath(cue.MakePath(
cue.Hid("_secret", "alpha.dagger.io/dagger"),
cue.Hid("_secret", stdlib.PackageName),
cue.Str("id"),
)).Exists() {
return "dagger.#Secret"

View File

@ -346,7 +346,7 @@ func walkStdlib(ctx context.Context, output, format string) {
return nil
}
pkgName := fmt.Sprintf("alpha.dagger.io/%s", p)
pkgName := fmt.Sprintf("%s/%s", stdlib.ModuleName, p)
lg.Info().Str("package", pkgName).Str("format", format).Msg("generating doc")
val, err := loadCode(pkgName)
if err != nil {

View File

@ -8,6 +8,7 @@ import (
"github.com/gofrs/flock"
"github.com/rs/zerolog/log"
"go.dagger.io/dagger/stdlib"
)
const (
@ -15,7 +16,7 @@ const (
)
func isUniverse(repoName string) bool {
return strings.HasPrefix(strings.ToLower(repoName), "alpha.dagger.io")
return strings.HasPrefix(strings.ToLower(repoName), stdlib.ModuleName)
}
func Install(ctx context.Context, workspace, repoName, versionConstraint string) (*Require, error) {

View File

@ -7,6 +7,8 @@ import (
"path/filepath"
"regexp"
"strings"
"go.dagger.io/dagger/stdlib"
)
type Require struct {
@ -25,7 +27,7 @@ func newRequire(repoName, versionConstraint string) (*Require, error) {
switch {
case strings.HasPrefix(repoName, "github.com"):
return parseGithubRepoName(repoName, versionConstraint)
case strings.HasPrefix(repoName, "alpha.dagger.io"):
case strings.HasPrefix(repoName, stdlib.ModuleName):
return parseDaggerRepoName(repoName, versionConstraint)
default:
return nil, fmt.Errorf("repo name does not match suported providers")
@ -52,7 +54,7 @@ func parseGithubRepoName(repoName, versionConstraint string) (*Require, error) {
}, nil
}
var daggerRepoNameRegex = regexp.MustCompile(`alpha.dagger.io([a-zA-Z0-9/_.-]*)@?([0-9a-zA-Z.-]*)`)
var daggerRepoNameRegex = regexp.MustCompile(stdlib.ModuleName + `([a-zA-Z0-9/_.-]*)@?([0-9a-zA-Z.-]*)`)
func parseDaggerRepoName(repoName, versionConstraint string) (*Require, error) {
repoMatches := daggerRepoNameRegex.FindStringSubmatch(repoName)
@ -62,7 +64,7 @@ func parseDaggerRepoName(repoName, versionConstraint string) (*Require, error) {
}
return &Require{
repo: "alpha.dagger.io",
repo: stdlib.ModuleName,
path: repoMatches[1],
version: repoMatches[2],
versionConstraint: versionConstraint,

View File

@ -8,11 +8,12 @@ import (
"github.com/google/uuid"
bkgw "github.com/moby/buildkit/frontend/gateway/client"
"go.dagger.io/dagger/compiler"
"go.dagger.io/dagger/stdlib"
)
var (
fsIDPath = cue.MakePath(
cue.Hid("_fs", "alpha.dagger.io/dagger"),
cue.Hid("_fs", stdlib.PackageName),
cue.Str("id"),
)
)

View File

@ -6,11 +6,12 @@ import (
"cuelang.org/go/cue"
"go.dagger.io/dagger/compiler"
"go.dagger.io/dagger/stdlib"
)
var (
secretIDPath = cue.MakePath(
cue.Hid("_secret", "alpha.dagger.io/dagger"),
cue.Hid("_secret", stdlib.PackageName),
cue.Str("id"),
)
)

View File

@ -6,11 +6,12 @@ import (
"cuelang.org/go/cue"
"go.dagger.io/dagger/compiler"
"go.dagger.io/dagger/stdlib"
)
var (
serviceIDPath = cue.MakePath(
cue.Hid("_service", "alpha.dagger.io/dagger"),
cue.Hid("_service", stdlib.PackageName),
cue.Str("id"),
)
)

View File

@ -399,7 +399,7 @@ func VendorUniverse(ctx context.Context, p string) error {
// add universe and lock file to `.gitignore`
if err := os.WriteFile(
path.Join(p, "cue.mod", "pkg", ".gitignore"),
[]byte(fmt.Sprintf("# generated by dagger\n%s\ndagger.lock\n", stdlib.PackageName)),
[]byte(fmt.Sprintf("# generated by dagger\n%s\ndagger.lock\n", stdlib.ModuleName)),
0600,
); err != nil {
return err
@ -408,7 +408,7 @@ func VendorUniverse(ctx context.Context, p string) error {
log.Ctx(ctx).Debug().Str("mod", p).Msg("vendoring universe")
if err := stdlib.Vendor(ctx, p); err != nil {
// FIXME(samalba): disabled install remote stdlib temporarily
// if _, err := mod.Install(ctx, p, "alpha.dagger.io", ""); err != nil {
// if _, err := mod.Install(ctx, p, stdlib.ModuleName, ""); err != nil {
return err
}

View File

@ -17,8 +17,9 @@ var (
//go:embed **/*.cue **/*/*.cue
FS embed.FS
PackageName = "alpha.dagger.io"
Path = path.Join("cue.mod", "pkg", PackageName)
ModuleName = "alpha.dagger.io"
PackageName = fmt.Sprintf("%s/dagger", ModuleName)
Path = path.Join("cue.mod", "pkg", ModuleName)
lockFilePath = path.Join("cue.mod", "dagger.lock")
)