# Description
This PR implements generating the generic variant of a go SDK from
Pulumi schemas. Currently the idea is to generate a directory `x` inside
the root directory of the go SDK which will contain the same SDK except
using generics and generating far less code than its current counter
part.
Also implements an enum option `$.language.go.generics` which can be set
to the following:
- `none` is the default which maintains the current behavior that
generates legacy types without generics
- `side-by-side` generates the generics sdk variant alongside the
current sdk under directory `x`
- `generics-only` generates only the new sdk with generics at the root
of the package
Still a bunch of things to do:
- [x] Generating `InvokeResult]Output` type from `Output[InvokeResult]`
and generating accessor methods for it
- [x] Generating default values for types and using the `pulumix`
subpackage to do so
- [x] Generating generic SDK variants for all test schemas we have and
making sure they compile (currently only testing
`simple-resource-schema` as shown below)
- [x] Account for plain inputs for components
- [x] Combine pulumix.Join with pulumix.Apply to generate resource
accessor methods
- [x] Problem with `GPtrOutput[T]` and `ArrayOutput[T]` being unwrapped
to `Output[*T]` and `Output[[]T]`
- [x] Remove excess untyped container types from generated enums
- [x] Fix default values for resource methods with lifted single return
value
- [x] Secret properties
Currently the following test schemas have opted for `generics:
"side-by-side"`:
- [x] output-funcs
- [x] simple-enum-schema
- [x] secrets
- [x] simple-plain-schema
- [x] plain-and-default
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
# Description
This PR adds a schema option specific to go at
`$.language.go.internalModuleName` which, when set, overrides the name
used for the internal/utilities module and everywhere it is used (see
added test example below)
Fixes#13632
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
---------
Co-authored-by: Justin Van Patten <jvp@justinvp.com>
There are situations where an MLC provider may use other resource providers inside its implementation. Such dependencies are not exposed through public APIs and aren't used at all from the generated Go SDK. Since these dependencies aren't used in the Go SDK, there's no way to specify them in the SDK's `go.mod`, as they'd be removed by `go mod tidy`. This is problematic for plugin discovery. Since the dependencies aren't able to be listed in the SDK's `go.mod`, the associated plugins will not be installed automatically for users of the SDK.
This change introduces a new Go schema option (`InternalDependencies`) that can be used to specify a set of packages that will be emitted as blank imports in the generated SDK so that the associated dependencies in `go.mod` will not be removed by `go mod tidy`.
* Add version (when env var is set)
* Correct python pypi implementation
* Add a test
* Update CHANGELOG_PENDING.md
* Set as language option
* Remove version.txt from .gitignore
* Add go support
* Correctly handle nodejs.pluginVersion
* Add test case
* Fix tests
* Add test dependencies correctly
* Feed through error handling
* Include test output
* Get types to line up
* Add remaining test files
* Update changelog
* Correctly find type paths
* Handle transitive objects
* Handle required fields
* Add feature flag for go
* Add required+default test case
* Don't `<any>` cast known types.
* Add more flags.
I realize this should really wait for PR#8400 to merge.
* Add plain object to env-helper test
This test fails right now. My next problem is fixing it.
* Handle plain types
* Handle function inputs
* Fix the indentation
* Handle output types correctly
* Remove unnecessary `!`
* Add test case
* Fix tests
* Add test dependencies correctly
* Feed through error handling
* Include test output
* Get types to line up
* Add remaining test files
* Update changelog
* Correctly find type paths
* Handle transitive objects
* Handle required fields
* Add required+default test case
* Don't `<any>` cast known types.
* Add plain object to env-helper test
This test fails right now. My next problem is fixing it.
* Handle plain types
* Handle function inputs
* Fix the indentation
* Handle output types correctly
* Remove unnecessary `!`
* Start on `genPlainObjectDefaultFunc`
* Add missing change to fix test
* Run tests with merge
* Refactor out assign
* Merge in next _index.md diff
* Change method name to `Defaults`
* Handle enums correctly
* Another attempt at _index.md
* Make module generation deterministic
* Add checks for old values
* Insert defaults in resources
* Fix docs generation
Credit to @praneetloke
* Progress on adding defaults to Resource arguments
* Handle resource argument defaults
* Don't create defaults if disableObjectDefaults
* Rename test folder
* Add test for disable flag
* Fix disable test
* Update docs
* Abstract out nil comparisons
* Use reflection to test for empty values
* Simplify Ptr and pulumi.Any type handling
* Remove unused function
* Apply defaults to functions
* Update new test with master codegen
* Tests + nil check
When working in a monorepo environment, it can be desirable to generate
Go SDKs into a structure less like the upstream SDKs, and more like
this:
github.com/x/mymonorepo/sdk/go/package-name
Where `package-name` is also the root of a Go module. Since
`package-name` is not a valid package name in Go, it's also desirable to
be able to choose a replacement name and reduce the amount of nesting.
This commit adds a new Go option to the schema, `rootPackageName`, which
can be used to modify the generated root package name (e.g. to
`mypackage` instead of `package-name`, and remove the additional layer
of nesting.
Test coverage is added to ensure that the correct file structure and
package names are generated.