2022-01-31 20:48:32 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
programgen(go): Handle conflicting names in imported packages
This fixes how programgen generates import statements
to handle conflicting imports when two imported packages
have the same name, e.g.
github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ecs
github.com/pulumi/pulumi-awsx/sdk/go/awsx/ecs
To do this, we add a fileImporter type that tracks these imports.
It prefers unnamed imports for packages unless one of the following is
true:
- the name of the package has already been used by another import
- the name of the package does not match the last component
of the import path (e.g., `example.com/foo-go` with `package foo`).
If the name has already been used by another import,
it attempts the following in-order:
- Combine the last two path components of the import path
into an identifier and use that if available.
e.g., `awsxs3` from `sdk/go/awsx/s3`.
- Append a number to the package name and increment it
until an unused name is found.
e.g. `ecs2`, `ecs3`, and so on.
There's a change in how this information is tracked as well.
Previously, this was a pull approach: various calls returned
programImports objects which all got merged together.
This change switches to a push approach:
as code is generated and imports are requested,
they're submitted to the fileImporter which keeps track of them
until the next `Reset()` call.
The above also has a nice side effect of dropping a parameter.
Another change worth explicitly calling out:
Previously, getModOrAlias partially duplicated some of the logic
implemented in getPulumiImport, and used `mod`, `originalMod`
in a non-obvious way.
This generated incorrect imports like the following
(note the two `/aws` at the end):
github.com/pulumi/pulumi-aws/sdk/v5/go/aws/aws
This change replicates more of the logic of getPulumiImport
(now called addPulumiImport) into this function,
and addresses the discrepancy in codegen caused by `mod`/`originalMod`.
The result leaves most existing code unchanged,
except in a couple existing cases where the resulting changes make sense
given the logic for named imports outlined above.
Resolves #11176
2023-06-23 21:11:00 +00:00
|
|
|
other "git.example.org/thirdparty/sdk/go/pkg"
|
2022-10-10 23:01:53 +00:00
|
|
|
"git.example.org/thirdparty/sdk/go/pkg/module"
|
2022-01-31 20:48:32 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
pulumi.Run(func(ctx *pulumi.Context) error {
|
programgen(go): Handle conflicting names in imported packages
This fixes how programgen generates import statements
to handle conflicting imports when two imported packages
have the same name, e.g.
github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ecs
github.com/pulumi/pulumi-awsx/sdk/go/awsx/ecs
To do this, we add a fileImporter type that tracks these imports.
It prefers unnamed imports for packages unless one of the following is
true:
- the name of the package has already been used by another import
- the name of the package does not match the last component
of the import path (e.g., `example.com/foo-go` with `package foo`).
If the name has already been used by another import,
it attempts the following in-order:
- Combine the last two path components of the import path
into an identifier and use that if available.
e.g., `awsxs3` from `sdk/go/awsx/s3`.
- Append a number to the package name and increment it
until an unused name is found.
e.g. `ecs2`, `ecs3`, and so on.
There's a change in how this information is tracked as well.
Previously, this was a pull approach: various calls returned
programImports objects which all got merged together.
This change switches to a push approach:
as code is generated and imports are requested,
they're submitted to the fileImporter which keeps track of them
until the next `Reset()` call.
The above also has a nice side effect of dropping a parameter.
Another change worth explicitly calling out:
Previously, getModOrAlias partially duplicated some of the logic
implemented in getPulumiImport, and used `mod`, `originalMod`
in a non-obvious way.
This generated incorrect imports like the following
(note the two `/aws` at the end):
github.com/pulumi/pulumi-aws/sdk/v5/go/aws/aws
This change replicates more of the logic of getPulumiImport
(now called addPulumiImport) into this function,
and addresses the discrepancy in codegen caused by `mod`/`originalMod`.
The result leaves most existing code unchanged,
except in a couple existing cases where the resulting changes make sense
given the logic for named imports outlined above.
Resolves #11176
2023-06-23 21:11:00 +00:00
|
|
|
_, err := other.NewThing(ctx, "Other", &other.ThingArgs{
|
2022-01-31 20:48:32 +00:00
|
|
|
Idea: pulumi.String("Support Third Party"),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = module.NewObject(ctx, "Question", &module.ObjectArgs{
|
|
|
|
Answer: pulumi.Float64(42),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-19 23:40:31 +00:00
|
|
|
_, err = module.NewObject(ctx, "Question2", &module.ObjectArgs{
|
2022-09-15 16:32:38 +00:00
|
|
|
Answer: pulumi.Float64(24),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
programgen(go): Handle conflicting names in imported packages
This fixes how programgen generates import statements
to handle conflicting imports when two imported packages
have the same name, e.g.
github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ecs
github.com/pulumi/pulumi-awsx/sdk/go/awsx/ecs
To do this, we add a fileImporter type that tracks these imports.
It prefers unnamed imports for packages unless one of the following is
true:
- the name of the package has already been used by another import
- the name of the package does not match the last component
of the import path (e.g., `example.com/foo-go` with `package foo`).
If the name has already been used by another import,
it attempts the following in-order:
- Combine the last two path components of the import path
into an identifier and use that if available.
e.g., `awsxs3` from `sdk/go/awsx/s3`.
- Append a number to the package name and increment it
until an unused name is found.
e.g. `ecs2`, `ecs3`, and so on.
There's a change in how this information is tracked as well.
Previously, this was a pull approach: various calls returned
programImports objects which all got merged together.
This change switches to a push approach:
as code is generated and imports are requested,
they're submitted to the fileImporter which keeps track of them
until the next `Reset()` call.
The above also has a nice side effect of dropping a parameter.
Another change worth explicitly calling out:
Previously, getModOrAlias partially duplicated some of the logic
implemented in getPulumiImport, and used `mod`, `originalMod`
in a non-obvious way.
This generated incorrect imports like the following
(note the two `/aws` at the end):
github.com/pulumi/pulumi-aws/sdk/v5/go/aws/aws
This change replicates more of the logic of getPulumiImport
(now called addPulumiImport) into this function,
and addresses the discrepancy in codegen caused by `mod`/`originalMod`.
The result leaves most existing code unchanged,
except in a couple existing cases where the resulting changes make sense
given the logic for named imports outlined above.
Resolves #11176
2023-06-23 21:11:00 +00:00
|
|
|
_, err = other.NewProvider(ctx, "Provider", &other.ProviderArgs{
|
2022-08-30 00:16:22 +00:00
|
|
|
ObjectProp: pulumi.StringMap{
|
|
|
|
"prop1": pulumi.String("foo"),
|
|
|
|
"prop2": pulumi.String("bar"),
|
|
|
|
"prop3": pulumi.String("fizz"),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-01-31 20:48:32 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|