Go codegen flag to disable fnOutput generation to save space (#8106)

This commit is contained in:
Anton Tayanovskyy 2021-09-30 18:56:42 +00:00 committed by GitHub
parent 10816d6414
commit 98ef06ecb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View file

@ -1734,13 +1734,30 @@ func (pkg *pkgContext) genResource(w io.Writer, r *schema.Resource, generateReso
return nil
}
func (pkg *pkgContext) needsGoOutputVersion(f *schema.Function) bool {
fPkg := f.Package
var goInfo GoPackageInfo
contract.AssertNoError(fPkg.ImportLanguages(map[string]schema.Language{"go": Importer}))
if info, ok := fPkg.Language["go"].(GoPackageInfo); ok {
goInfo = info
}
if goInfo.DisableFunctionOutputVersions {
return false
}
return f.NeedsOutputVersion()
}
func (pkg *pkgContext) genFunctionCodeFile(f *schema.Function) string {
importsAndAliases := map[string]string{}
pkg.getImports(f, importsAndAliases)
buffer := &bytes.Buffer{}
var imports []string
if f.NeedsOutputVersion() {
if pkg.needsGoOutputVersion(f) {
imports = []string{"context", "reflect"}
}
@ -1831,7 +1848,7 @@ func (pkg *pkgContext) functionResultTypeName(f *schema.Function) string {
}
func (pkg *pkgContext) genFunctionOutputVersion(w io.Writer, f *schema.Function) {
if !f.NeedsOutputVersion() {
if !pkg.needsGoOutputVersion(f) {
return
}

View file

@ -49,6 +49,10 @@ type GoPackageInfo struct {
// The version of the Pulumi SDK used with this provider, e.g. 3.
// Used to generate doc links for pulumi builtin types. If omitted, the latest SDK version is used.
PulumiSDKVersion int `json:"pulumiSDKVersion,omitempty"`
// Feature flag to disable generating `$fnOutput` invoke
// function versions to save space.
DisableFunctionOutputVersions bool `json:"disableFunctionOutputVersions,omitempty"`
}
// Importer implements schema.Language for Go.