Skip to content

Commit

Permalink
[program-gen] Fix args and result handling of invokes in generated pr…
Browse files Browse the repository at this point in the history
…ograms (#1574)

### Description

Fix args and result handling of invokes in generated programs. Initially
by enabling `pcl.PreferOutputVersionedInvokes` when generating the
programs and accounting for wrapped `__convert` calls at the args
location of the invokes.

Unskips the following conformance tests:
 - `l2-invoke-simple`
 - `l2-invoke-variants`
 - `l2-invoke-dependencies`

Fixes #1563
  • Loading branch information
Zaid-Ajaj authored Jan 7, 2025
1 parent 784fa7b commit 963cf1b
Show file tree
Hide file tree
Showing 32 changed files with 1,515 additions and 21 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

- Fix emitted import statements in generated programs such that imports with the same symbol are fully qualified
- Fix args and result handling of invokes in generated programs

### Bug Fixes
3 changes: 0 additions & 3 deletions pkg/cmd/pulumi-language-java/language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,9 @@ var expectedFailures = map[string]string{
"l1-output-array": "#1560 Empty array literals are not generated correctly",
"l1-output-map": "#1561 Map literals are not generated correctly",
"l1-output-string": "#1562 Large string literals are not generated correctly",
"l2-invoke-dependencies": "#1563 Invoke argument and result handling",
"l2-invoke-options": "#1563 Invoke argument and result handling",
"l2-invoke-options-depends-on": "#1563 Invoke argument and result handling",
"l2-invoke-secrets": "#1563 Invoke argument and result handling",
"l2-invoke-simple": "#1563 Invoke argument and result handling",
"l2-invoke-variants": "#1563 Invoke argument and result handling",
"l2-map-keys": "#1569 Spot and qualify duplicate identifiers",
"l2-provider-grpc-config-schema-secret": "#1568 Don't generate duplicate files",
"l2-provider-grpc-config-secret": "#1568 Don't generate duplicate files",
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/pulumi-language-java/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ func (host *javaLanguageHost) GenerateProject(
extraOptions = append(extraOptions, pcl.NonStrictBindOptions()...)
}

extraOptions = append(extraOptions, pcl.PreferOutputVersionedInvokes)

program, diags, err := pcl.BindDirectory(req.SourceDirectory, loader, extraOptions...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -670,7 +672,7 @@ func (host *javaLanguageHost) GenerateProgram(
}
}

program, diags, err := pcl.BindProgram(parser.Files, pcl.Loader(loader))
program, diags, err := pcl.BindProgram(parser.Files, pcl.Loader(loader), pcl.PreferOutputVersionedInvokes)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: l2-invoke-dependencies
runtime: java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.pulumi</groupId>
<artifactId>l2-invoke-dependencies</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<encoding>UTF-8</encoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<mainClass>generated_program.App</mainClass>
<mainArgs/>
</properties>

<repositories>
<repository>
<id>repository-0</id>
<url>REPOSITORY</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>pulumi</artifactId>
<version>CORE.VERSION</version>
</dependency>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>simple</artifactId>
<version>2.0.0</version>
</dependency><dependency>
<groupId>com.pulumi</groupId>
<artifactId>simple-invoke</artifactId>
<version>10.0.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<mainClass>${mainClass}</mainClass>
<commandlineArgs>${mainArgs}</commandlineArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-wrapper-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<mavenVersion>3.8.5</mavenVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.simple.Resource;
import com.pulumi.simple.ResourceArgs;
import com.pulumi.simpleinvoke.SimpleinvokeFunctions;
import com.pulumi.simpleinvoke.inputs.SecretInvokeArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}

public static void stack(Context ctx) {
var first = new Resource("first", ResourceArgs.builder()
.value(false)
.build());

// assert that resource second depends on resource first
// because it uses .secret from the invoke which depends on first
var second = new Resource("second", ResourceArgs.builder()
.value(SimpleinvokeFunctions.secretInvoke(SecretInvokeArgs.builder()
.value("hello")
.secretResponse(first.value())
.build()).applyValue(invoke -> invoke.secret()))
.build());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: l2-invoke-simple
runtime: java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.pulumi</groupId>
<artifactId>l2-invoke-simple</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<encoding>UTF-8</encoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<mainClass>generated_program.App</mainClass>
<mainArgs/>
</properties>

<repositories>
<repository>
<id>repository-0</id>
<url>REPOSITORY</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>pulumi</artifactId>
<version>CORE.VERSION</version>
</dependency>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>simple-invoke</artifactId>
<version>10.0.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<mainClass>${mainClass}</mainClass>
<commandlineArgs>${mainArgs}</commandlineArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-wrapper-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<mavenVersion>3.8.5</mavenVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.simpleinvoke.SimpleinvokeFunctions;
import com.pulumi.simpleinvoke.inputs.MyInvokeArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}

public static void stack(Context ctx) {
ctx.export("hello", SimpleinvokeFunctions.myInvoke(MyInvokeArgs.builder()
.value("hello")
.build()).applyValue(invoke -> invoke.result()));
ctx.export("goodbye", SimpleinvokeFunctions.myInvoke(MyInvokeArgs.builder()
.value("goodbye")
.build()).applyValue(invoke -> invoke.result()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: l2-invoke-variants
runtime: java
Loading

0 comments on commit 963cf1b

Please sign in to comment.