Skip to content

Commit

Permalink
Expose overlay flag (#1361)
Browse files Browse the repository at this point in the history
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

- new generate flag: `--overlay` 
- fix for recursive copy of overlay files

Fixes #1360 

## Checklist

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] 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 updated the
[CHANGELOG-PENDING](https://github.com/pulumi/pulumi/blob/master/CHANGELOG_PENDING.md)
file with my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Service,
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
Service API version
<!-- @pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
  • Loading branch information
EronWright committed May 15, 2024
2 parents 21fa48b + f887fbc commit c0f1a50
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Improvements

- Plugin: will now automatically use the Gradle executor if build.gradle.kts is present
- Codegen: support for overlays

### Bug Fixes
5 changes: 5 additions & 0 deletions pkg/cmd/pulumi-java-gen/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ See https://www.pulumi.com/docs/guides/pulumi-packages/schema/#language-specific
}

var versionArg, javaSdkVersionArg, schemaArg, outArg, overrideArg, buildArg string
var overlays []string

cmd.Flags().StringVar(&versionArg, "version", "",
"default semantic version for the generated package")
Expand All @@ -102,6 +103,9 @@ See https://www.pulumi.com/docs/guides/pulumi-packages/schema/#language-specific
`)

cmd.Flags().StringArrayVar(&overlays, "overlay", nil,
"path(s) to folders to mix into the generated code by copying")

cmd.Run = cmdutil.RunFunc(func(_ *cobra.Command, _ []string) error {
rootDir, err := os.Getwd()
if err != nil {
Expand All @@ -122,6 +126,7 @@ See https://www.pulumi.com/docs/guides/pulumi-packages/schema/#language-specific
Version: version,
RootDir: rootDir,
OutputDir: outArg,
Overlays: overlays,
}

if overrideArg != "" {
Expand Down
11 changes: 7 additions & 4 deletions pkg/cmd/pulumi-java-gen/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ func readOverlays(rootDir string, overlays []string) (map[string][]byte, error)
result := map[string][]byte{}
for _, overlay := range overlays {
overlayDir := filepath.Join(rootDir, overlay)
err := filepath.WalkDir(overlayDir, func(_ string, entry fs.DirEntry, err error) error {
err := filepath.WalkDir(overlayDir, func(path string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}
if !entry.IsDir() {
sourcePath := filepath.Join(overlayDir, entry.Name())
bytes, err := os.ReadFile(sourcePath)
relativePath, err := filepath.Rel(overlayDir, path)
if err != nil {
return err
}
result[entry.Name()] = bytes
bytes, err := os.ReadFile(path)
if err != nil {
return err
}
result[relativePath] = bytes
}
return err
})
Expand Down

0 comments on commit c0f1a50

Please sign in to comment.