Skip to content

Commit

Permalink
Merge #11339
Browse files Browse the repository at this point in the history
11339: Account for version when caching schemas r=iwahbe a=iwahbe

This is necessary to unblock pulumi/docs#8230

Co-authored-by: Ian Wahbe <ian@wahbe.com>
  • Loading branch information
bors[bot] and iwahbe committed Nov 14, 2022
2 parents 16afb72 + 76589af commit 71f14da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 20 additions & 3 deletions pkg/codegen/schema/loader.go
Expand Up @@ -182,14 +182,31 @@ func (l *pluginLoader) LoadPackageReference(pkg string, version *semver.Version)
}

func LoadPackageReference(loader Loader, pkg string, version *semver.Version) (PackageReference, error) {
var ref PackageReference
var err error
if refLoader, ok := loader.(ReferenceLoader); ok {
return refLoader.LoadPackageReference(pkg, version)
ref, err = refLoader.LoadPackageReference(pkg, version)
} else {
p, pErr := loader.LoadPackage(pkg, version)
err = pErr
if err == nil {
ref = p.Reference()
}
}
p, err := loader.LoadPackage(pkg, version)

if err != nil {
return nil, err
}
return p.Reference(), nil

if pkg != ref.Name() || version != nil && ref.Version() != nil && !ref.Version().Equals(*version) {
if l, ok := loader.(*pluginLoader); ok {
return nil, fmt.Errorf("req: %s@%v: entries: %v (returned %s@%v)", pkg, version,
l.entries, ref.Name(), ref.Version())
}
return nil, fmt.Errorf("loader returned %s@%v: expected %s@%v", ref.Name(), ref.Version(), pkg, version)
}

return ref, nil
}

func (l *pluginLoader) loadSchemaBytes(pkg string, version *semver.Version) ([]byte, *semver.Version, error) {
Expand Down
6 changes: 5 additions & 1 deletion sdk/go/common/workspace/plugins.go
Expand Up @@ -672,7 +672,11 @@ func (info *PluginInfo) SetFileMetadata(path string) error {
info.LastUsedTime = tinfo.AccessTime()

if info.Kind == ResourcePlugin {
info.SchemaPath = filepath.Join(filepath.Dir(path), "schema-"+info.Name+".json")
var v string
if info.Version != nil {
v = "-" + info.Version.String() + "-"
}
info.SchemaPath = filepath.Join(filepath.Dir(path), "schema-"+info.Name+v+".json")
info.SchemaTime = tinfo.ModTime()
}

Expand Down

0 comments on commit 71f14da

Please sign in to comment.