Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smoke Tests Codegen Working #3155

Merged
merged 51 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
feeaccd
v1 codegen
sbera87 Oct 15, 2024
76ef3f9
updates
sbera87 Oct 16, 2024
f877902
updates
sbera87 Oct 16, 2024
ae0b5b2
codegen fixes
sbera87 Oct 16, 2024
1bba920
add service filter in configuration
sbera87 Oct 16, 2024
4dec4b3
add deps
sbera87 Oct 16, 2024
fbfb5c6
deps
sbera87 Oct 16, 2024
18f0386
projections test
sbera87 Oct 17, 2024
4b5a7f0
working codegen from script
sbera87 Oct 17, 2024
0233376
codegen script updates
sbera87 Oct 18, 2024
346c1f0
working codegen with script
sbera87 Oct 18, 2024
dc6da8d
ignore temp files for smithy codegen
sbera87 Oct 18, 2024
fb8414b
cleanup + codegen fixes
sbera87 Oct 18, 2024
872c19b
tweaks
sbera87 Oct 18, 2024
049a36d
remove temp files
sbera87 Oct 18, 2024
320e03d
remove temp files
sbera87 Oct 18, 2024
5ca8987
This release launches the CreateIntegration, DeleteIntegration, Descr…
aws-sdk-cpp-automation Oct 15, 2024
6b97b8c
Add support for the new optional bucket-region and prefix query param…
aws-sdk-cpp-automation Oct 16, 2024
785f364
Update API model
aws-sdk-cpp-automation Oct 17, 2024
1273eb9
This is an Amazon ECS documentation only update to address tickets.
aws-sdk-cpp-automation Oct 17, 2024
97e4f61
Don't continue polling input stream in case it is closed or in a bad …
SergeyRyabinin Oct 17, 2024
cbad9dc
Revert "Don't continue polling input stream in case it is closed or i…
SergeyRyabinin Oct 18, 2024
b49ca3a
Update API model
aws-sdk-cpp-automation Oct 18, 2024
ac1b079
Added converse support for custom imported models
aws-sdk-cpp-automation Oct 18, 2024
9cb4e54
codegen script updates
sbera87 Oct 18, 2024
d44f0eb
This release launches the CreateIntegration, DeleteIntegration, Descr…
aws-sdk-cpp-automation Oct 15, 2024
7a3f507
Add support for the new optional bucket-region and prefix query param…
aws-sdk-cpp-automation Oct 16, 2024
f16a2c1
merge
sbera87 Oct 20, 2024
b8bc77f
codegen fixes with cas
sbera87 Oct 21, 2024
1cf31c7
remove stray lines
sbera87 Oct 21, 2024
d3100ca
changes to get all clients to compile
sbera87 Oct 21, 2024
f9852cb
handle legacy and new service code generation
sbera87 Oct 22, 2024
5ae8434
fixes
sbera87 Oct 22, 2024
03cf379
cleanup
sbera87 Oct 22, 2024
b27da0e
cleanup
sbera87 Oct 23, 2024
31c8317
utilize importer for dependencies
sbera87 Oct 23, 2024
0c96460
handle num
sbera87 Oct 23, 2024
3f9f29b
cleanup + resolve PR comments
sbera87 Oct 24, 2024
c75a2d7
restore
sbera87 Oct 24, 2024
efa5bb4
remove helper for case conversion
sbera87 Oct 24, 2024
1be4d61
cleanup unused functions
sbera87 Oct 24, 2024
b27e018
remove commented lines
sbera87 Oct 25, 2024
e1c9608
PR comments fix
sbera87 Oct 25, 2024
febfcaf
cleanup
sbera87 Oct 25, 2024
c1a3350
cleanup
sbera87 Oct 25, 2024
aec431a
cleanup
sbera87 Oct 25, 2024
d336778
cleanup
sbera87 Oct 25, 2024
d2c23a6
formatting fixes
sbera87 Oct 25, 2024
b599f31
remove exceptions
sbera87 Oct 25, 2024
90f1772
PR feedback changes
sbera87 Oct 28, 2024
69600c5
remove catch exceptions
sbera87 Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup + resolve PR comments
  • Loading branch information
sbera87 committed Oct 24, 2024
commit 3f9f29b58e4bf838eb5c7c8ad3a3b615d72544e8
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,34 @@
import java.util.List;
import lombok.Data;

//Helper class for C++ code blocks for scope management
/*
Generic Helper class for C++ code blocks for scope management
C++ code has blocks, for example function, loops, empty blocks.

Variables defined in those blocks have their scope defined in them.
Blocks can be deeply nested.
This class manages blocks, scope of variables in such blocks
along with indentation of code defined in those blocks.

One of the use cases:
Code writer keeps adding blocks to say 5 levels, at the fifth level
if the writer wants to extract the code, all the nested blocks will be
automaticallty closed in order of the stack making top level writer not
worry about it.
*/
public class CppBlockWriter {

public static String GetForLoopRangeInitializer(String variableName, String iterableExpr)
{
//preset logic for some types of blocks
public static String GetForLoopRangeInitializer(String variableName, String iterableExpr){
return String.format("for (auto %s in %s)", variableName, iterableExpr);
}

public static String GetContainerDeclaration(String containerType, String containerTemplateParam, String variableName)
{
public static String GetContainerDeclaration(String containerType, String containerTemplateParam, String variableName){
return String.format("%s<%s> %s",containerType, containerTemplateParam,variableName );
}

//args will always be even number Type followed by name
public static String GetFunctionBlock(String returnType, String functionName, String... args)
{
public static String GetFunctionBlock(String returnType, String functionName, String... args){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < args.length - 1; i += 2)
{
Expand All @@ -37,8 +49,7 @@ public static String GetFunctionBlock(String returnType, String functionName, St
}


public static String GetLambdaBlock(String returnType, String functionName, String... args)
{
public static String GetLambdaBlock(String returnType, String functionName, String... args){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < args.length - 1; i += 2)
{
Expand Down Expand Up @@ -116,8 +127,7 @@ public CppBlockWriter(int level){
}

//opens a new block
public CppBlockWriter openCodeBlock(String blockHead)
{
public CppBlockWriter openCodeBlock(String blockHead){
//add new block to stack
//use its string builder to add "{"
Block block = new Block(blockHead, indentLevel);
Expand All @@ -126,8 +136,7 @@ public CppBlockWriter openCodeBlock(String blockHead)
return this;
}

public CppBlockWriter continueCodeBlock(String code)
{
public CppBlockWriter continueCodeBlock(String code){
//add new block to stack
//use its string builder to add "{"
Block block = new Block(indentLevel);
Expand All @@ -144,8 +153,7 @@ public CppBlockWriter continueCodeBlock(String code)


//add code to current block
public CppBlockWriter addCode(String code)
{
public CppBlockWriter addCode(String code){
if (!blockStack.isEmpty()) {

Block top = blockStack.peek();
Expand All @@ -155,8 +163,7 @@ public CppBlockWriter addCode(String code)
}

//closes current block
public CppBlockWriter closeCodeBlock()
{
public CppBlockWriter closeCodeBlock(){
List<String> codeLines = new ArrayList<String>();
//if root block is not a new scope and it is the root block,
//need not close scope then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public final class CppImportContainer implements ImportContainer {
public CppImportContainer(String namespace) {
this.clientNamespace = SmokeTestsParser.removeSpaces(namespace);
this.folderNamespace = SmokeTestsParser.toKebabCase(namespace);
this.c2jNamespace = SmithyC2JNamespaceMap.getC2JServiceName(this.folderNamespace);
this.c2jNamespace = SmithyC2JNamespaceMap.getInstance().getC2JServiceName(this.folderNamespace);
this.coreHeaders = new HashSet<>();
this.dynamicHeaders = new HashSet<>();
Collections.addAll(coreHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,37 @@

package com.amazonaws.util.awsclientsmithygenerator.generators;

import software.amazon.smithy.codegen.core.*;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.*;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.DocumentShape;
import software.amazon.smithy.model.shapes.LongShape;
import software.amazon.smithy.model.shapes.StringShape;
import software.amazon.smithy.model.shapes.MemberShape;
import software.amazon.smithy.model.shapes.UnionShape;
import software.amazon.smithy.model.shapes.ResourceShape;
import software.amazon.smithy.model.shapes.ByteShape;
import software.amazon.smithy.model.shapes.BlobShape;
import software.amazon.smithy.model.shapes.BooleanShape;
import software.amazon.smithy.model.shapes.ListShape;
import software.amazon.smithy.model.shapes.MapShape;
import software.amazon.smithy.model.shapes.IntEnumShape;
import software.amazon.smithy.model.shapes.DoubleShape;
import software.amazon.smithy.model.shapes.ShortShape;
import software.amazon.smithy.model.shapes.FloatShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeVisitor;
import software.amazon.smithy.model.shapes.EnumShape;
import software.amazon.smithy.model.shapes.TimestampShape;
import software.amazon.smithy.model.shapes.BigDecimalShape;
import software.amazon.smithy.model.shapes.BigIntegerShape;
import software.amazon.smithy.model.shapes.StructureShape;
import software.amazon.smithy.model.shapes.IntegerShape;


import software.amazon.smithy.utils.StringUtils;

import java.util.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public interface GenericCodegenAdapter<SHAPE, DATA> {

public SHAPE getShapeFromOperation(String OperationName);

//public boolean isEnum(DATA d);

public boolean isFloat(DATA d);

public boolean isBoolean(DATA d);
Expand Down Expand Up @@ -153,8 +151,7 @@ else if (isMap(value) && isMapShape(shape))

//prepare function code and save it for the variable name
//return only the function name
blockWriter.addCode(String.format("return %s;\n",varName))
.closeCodeBlock();
blockWriter.addCode(String.format("return %s;\n",varName)).closeCodeBlock();
functionMap.put(functionName, blockWriter.getCode() );
functionOrder.add(functionName);
functionName = functionName.concat("()");
Expand All @@ -173,11 +170,9 @@ else if (isList(value) && isListShape(shape))

String returnType = "Aws::Vector<"+listType+">";
//open function body and use vector setter
CppBlockWriter blockWriter = new CppBlockWriter
(
CppBlockWriter.GetLambdaBlock(returnType, functionName), 0).
addCode(String.format("Aws::Vector<%s> %s = ",listType, varName))
.openCodeBlock("");
CppBlockWriter blockWriter = new CppBlockWriter(CppBlockWriter.GetLambdaBlock(returnType, functionName), 0)
.addCode(String.format("Aws::Vector<%s> %s = ",listType, varName))
.openCodeBlock("");

for (int i = 0; i < list.size(); i++)
{
Expand Down Expand Up @@ -213,7 +208,7 @@ else if (isString(value) && isEnumShape(shape))
}
else
{
System.err.println(String.format("shape not supported:%s",shape));
throw new Exception(String.format("shape not supported:%s",shape));
}

return functionName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class SmokeTestsParser implements Runnable{
final private CppSymbolVisitor symbolProvider;
final private Map<ShapeId, String> operationToServiceMap;
final private Map<String, ServiceShape> serviceShapeMap;
// Static member to store the flipped map
final private Set<String> serviceFilter;

public SmokeTestsParser(PluginContext context)
Expand Down Expand Up @@ -109,8 +108,6 @@ public SmokeTestsParser(PluginContext context)
this.serviceShapeMap.put(serviceName, serviceShape);
});
});

//System.out.println(String.format("Number of services with smoke tests detected=%d",serviceShapeMap.size()));
}

public static String removeSpaces(String input)
Expand All @@ -127,7 +124,6 @@ private String getServiceName(ServiceShape serviceShape) throws Exception
{
if(!serviceShape.getTrait(ServiceTrait.class).isPresent())
{
//System.err.println(String.format("No service trait detected in service shape with name=%s",serviceShape.getId().getName()));
throw new Exception(String.format("No service trait detected in service shape with name=%s",serviceShape.getId().getName()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont throw exception, everyon up chain has to check it, never throw or check Exception, subclass or throw a RuntimeException

Copy link
Contributor Author

@sbera87 sbera87 Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your recommendation how I should handle this? I understand that stack unwinding will happen on exception but what do i return when service trait is missing. I can throw a Runtimeexception

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they have a concept of "checked and unchecked exceptions" in java.
additionally, simple regular Exception is too broad and the exception handling error code must catch it and do it's logic accordingly to the exception string message (vs simply type of the exception).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack. I will switch to runtime exception as it is one of those cases where I have to throw if service trait not found

}

Expand Down Expand Up @@ -302,9 +298,6 @@ public Map<ServiceShape, List<SmokeTestData> > extractServiceSmokeTests()
//get serviceShape
String serviceName = operationToServiceMap.get(operationShape.getId());
ServiceShape serviceShape = serviceShapeMap.get(serviceName);
//System.out.println("OperationShape: " + operationShape.getId().getName());
//System.out.println("serviceName: " + serviceName);

//for one service, we have one smoke test file
//So, we for a given service we import dependencies (symbol types and their respective headers)
List<SmokeTestData> tests = serviceSmokeTestsMap.getOrDefault(serviceShape, new ArrayList<>());
Expand All @@ -323,7 +316,6 @@ public Map<ServiceShape, List<SmokeTestData> > extractServiceSmokeTests()

@Override
public void run(){
//System.out.println("run smoke tests parser");

Map<ServiceShape, List<SmokeTestData> > smoketests = extractServiceSmokeTests();

Expand All @@ -334,7 +326,7 @@ public void run(){
SmokeTestsCMakeDelegator cmakedelegator = new SmokeTestsCMakeDelegator(this.context.getFileManifest(), this.symbolProvider);

String client = getServiceName(serviceShape);
String c2jClientname = SmithyC2JNamespaceMap.getC2JServiceName(toKebabCase(client));
String c2jClientname = SmithyC2JNamespaceMap.getInstance().getC2JServiceName(toKebabCase(client));

Path relativePath = Paths.get(c2jClientname);
System.out.println(toKebabCase(client) + " mapped to " + c2jClientname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ public final class SmokeTestsSourceWriter extends SymbolWriter<SmokeTestsSourceW
private final String c2jNamespace;
private final List<SmokeTestData> smoketests;

//protected CppBlockWriter blockWriter;
public SmokeTestsSourceWriter(String namespace,List<SmokeTestData> smoketests) {
super(new CppImportContainer(namespace));
this.clientNamespace = SmokeTestsParser.removeSpaces(namespace);
this.folderNamespace = SmokeTestsParser.toKebabCase(namespace);
this.c2jNamespace = SmithyC2JNamespaceMap.getC2JServiceName(this.folderNamespace);
this.c2jNamespace = SmithyC2JNamespaceMap.getInstance().getC2JServiceName(this.folderNamespace);
this.smoketests = smoketests;
}

Expand Down Expand Up @@ -148,7 +147,7 @@ public String generate()
}

/**
* The Factory class for creating CppWriters
* The Factory class for creating CppWriters
*/
public static final class SmokeTestsSourceWriterFactory implements SymbolWriter.Factory<SmokeTestsSourceWriter> {
private final List<SmokeTestData> smoketests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import software.amazon.smithy.model.Model
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.aws.traits.ServiceTrait
//import software.amazon.smithy.smoketests.traits.SmokeTestsTrait
import software.amazon.smithy.model.shapes.OperationShape
plugins {
id("java-library")
Expand All @@ -19,7 +18,6 @@ buildscript {
classpath(codegen.model)
classpath(codegen.aws.traits)
classpath(codegen.aws.smoke.test.model)
//classpath(codegen.velocity.engine.core)
}
}
dependencies {
Expand Down Expand Up @@ -77,9 +75,7 @@ tasks.register("generate-smithy-build") {
.replace(" ", "-")
.replace("_", "-")
.lowercase()

//println("evaluating filter: $sdkId")


//service names must be match
if (filteredServiceList.isNotEmpty())
{
Expand All @@ -89,8 +85,6 @@ tasks.register("generate-smithy-build") {
}
}

//println("matched filter: $sdkId")

val projectionContents = Node.objectNodeBuilder()
.withMember("imports", Node.fromStrings("${models.absolutePath}${File.separator}${file.name}"))
.withMember("plugins", Node.objectNode()
Expand Down
4 changes: 1 addition & 3 deletions tools/scripts/run_code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,11 @@ def main():
highly_refined_percent_of_cores_to_take = 0.9
max_workers = max(1, int(highly_refined_percent_of_cores_to_take * os.cpu_count()))

#build reverse map
# Open a file using 'with' and read its contents
#build reverse map of c2j to smithy since in this script we use c2j names for legacy services
smithy_c2j_data = {}
c2j_smithy_data = {}
with open(os.path.abspath(SMITHY_TO_C2J_MAP_FILE), 'r') as file:
smithy_c2j_data = json.load(file)
# Reverse the key-value pairs
c2j_smithy_data = {value: key for key, value in smithy_c2j_data.items()}

with ProcessPoolExecutor(max_workers=max_workers) as executor:
Expand Down
Loading