Add flag for input registration to the go schema (#8198)

* Add flag

* Update CHANGELOG_PENDING.md

* Add this feature to an orthogonal test
This commit is contained in:
Ian Wahbe 2021-10-12 10:15:24 -07:00 committed by GitHub
parent b56d902afe
commit 208c6ec44d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 43 deletions

View file

@ -23,6 +23,9 @@
- [codegen/go] Register input types for schema object types.
[#7959](https://github.com/pulumi/pulumi/pull/7959)
- [codegen/go] Add schema flag to disable registering input types.
[#8198](https://github.com/pulumi/pulumi/pull/8198)
### Bug Fixes
- [codegen/go] - Use `importBasePath` before `name` if specified for name

View file

@ -113,6 +113,9 @@ type pkgContext struct {
// Determines whether to make single-return-value methods return an output struct or the value
liftSingleValueMethodReturns bool
// Determines if we should emit type registration code
disableInputTypeRegistrations bool
}
func (pkg *pkgContext) detailsForType(t schema.Type) *typeDetails {
@ -2144,24 +2147,26 @@ func (pkg *pkgContext) genTypeRegistrations(w io.Writer, objTypes []*schema.Obje
fmt.Fprintf(w, "func init() {\n")
// Input types.
for _, obj := range objTypes {
name, details := pkg.tokenToType(obj.Token), pkg.detailsForType(obj)
fmt.Fprintf(w, "\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sInput)(nil)).Elem(), %[1]sArgs{})\n", name)
if details.ptrElement {
fmt.Fprintf(w,
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sPtrInput)(nil)).Elem(), %[1]sArgs{})\n", name)
if !pkg.disableInputTypeRegistrations {
for _, obj := range objTypes {
name, details := pkg.tokenToType(obj.Token), pkg.detailsForType(obj)
fmt.Fprintf(w, "\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sInput)(nil)).Elem(), %[1]sArgs{})\n", name)
if details.ptrElement {
fmt.Fprintf(w,
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sPtrInput)(nil)).Elem(), %[1]sArgs{})\n", name)
}
if details.arrayElement {
fmt.Fprintf(w,
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sArrayInput)(nil)).Elem(), %[1]sArray{})\n", name)
}
if details.mapElement {
fmt.Fprintf(w,
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sMapInput)(nil)).Elem(), %[1]sMap{})\n", name)
}
}
if details.arrayElement {
fmt.Fprintf(w,
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sArrayInput)(nil)).Elem(), %[1]sArray{})\n", name)
for _, t := range types {
fmt.Fprintf(w, "\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sInput)(nil)).Elem(), %[1]s{})\n", t)
}
if details.mapElement {
fmt.Fprintf(w,
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sMapInput)(nil)).Elem(), %[1]sMap{})\n", name)
}
}
for _, t := range types {
fmt.Fprintf(w, "\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sInput)(nil)).Elem(), %[1]s{})\n", t)
}
// Output types.
@ -2552,21 +2557,22 @@ func generatePackageContextMap(tool string, pkg *schema.Package, goInfo GoPackag
pack, ok := packages[mod]
if !ok {
pack = &pkgContext{
pkg: pkg,
mod: mod,
importBasePath: goInfo.ImportBasePath,
rootPackageName: goInfo.RootPackageName,
typeDetails: map[schema.Type]*typeDetails{},
names: codegen.NewStringSet(),
schemaNames: codegen.NewStringSet(),
renamed: map[string]string{},
duplicateTokens: map[string]bool{},
functionNames: map[*schema.Function]string{},
tool: tool,
modToPkg: goInfo.ModuleToPackage,
pkgImportAliases: goInfo.PackageImportAliases,
packages: packages,
liftSingleValueMethodReturns: goInfo.LiftSingleValueMethodReturns,
pkg: pkg,
mod: mod,
importBasePath: goInfo.ImportBasePath,
rootPackageName: goInfo.RootPackageName,
typeDetails: map[schema.Type]*typeDetails{},
names: codegen.NewStringSet(),
schemaNames: codegen.NewStringSet(),
renamed: map[string]string{},
duplicateTokens: map[string]bool{},
functionNames: map[*schema.Function]string{},
tool: tool,
modToPkg: goInfo.ModuleToPackage,
pkgImportAliases: goInfo.PackageImportAliases,
packages: packages,
liftSingleValueMethodReturns: goInfo.LiftSingleValueMethodReturns,
disableInputTypeRegistrations: goInfo.DisableInputTypeRegistrations,
}
packages[mod] = pack
}

View file

@ -1,4 +1,4 @@
// Copyright 2016-2020, Pulumi Corporation.
// Copyright 2016-2021, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -56,6 +56,10 @@ type GoPackageInfo struct {
// Determines whether to make single-return-value methods return an output struct or the value.
LiftSingleValueMethodReturns bool `json:"liftSingleValueMethodReturns,omitempty"`
// Feature flag to disable generating input type registration. This is a
// space saving measure.
DisableInputTypeRegistrations bool `json:"disableInputTypeRegistrations,omitempty"`
}
// Importer implements schema.Language for Go.

View file

@ -702,16 +702,6 @@ func (o ToyMapOutput) MapIndex(k pulumi.StringInput) ToyOutput {
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*ChewInput)(nil)).Elem(), ChewArgs{})
pulumi.RegisterInputType(reflect.TypeOf((*ChewPtrInput)(nil)).Elem(), ChewArgs{})
pulumi.RegisterInputType(reflect.TypeOf((*LaserInput)(nil)).Elem(), LaserArgs{})
pulumi.RegisterInputType(reflect.TypeOf((*LaserPtrInput)(nil)).Elem(), LaserArgs{})
pulumi.RegisterInputType(reflect.TypeOf((*RecInput)(nil)).Elem(), RecArgs{})
pulumi.RegisterInputType(reflect.TypeOf((*RecPtrInput)(nil)).Elem(), RecArgs{})
pulumi.RegisterInputType(reflect.TypeOf((*ToyInput)(nil)).Elem(), ToyArgs{})
pulumi.RegisterInputType(reflect.TypeOf((*ToyPtrInput)(nil)).Elem(), ToyArgs{})
pulumi.RegisterInputType(reflect.TypeOf((*ToyArrayInput)(nil)).Elem(), ToyArray{})
pulumi.RegisterInputType(reflect.TypeOf((*ToyMapInput)(nil)).Elem(), ToyMap{})
pulumi.RegisterOutputType(ChewOutput{})
pulumi.RegisterOutputType(ChewPtrOutput{})
pulumi.RegisterOutputType(LaserOutput{})

View file

@ -139,7 +139,8 @@
}
},
"go": {
"generateResourceContainerTypes": true
"generateResourceContainerTypes": true,
"disableInputTypeRegistrations": true
},
"nodejs": {
"dependencies": {