-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Smoke tests support using smithy Interface
- Loading branch information
Showing
32 changed files
with
2,343 additions
and
40,113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
#include <aws/testing/AwsCppSdkGTestSuite.h> | ||
|
||
#if defined(HAS_UMASK) | ||
#include <sys/stat.h> | ||
#endif | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
#if defined(HAS_UMASK) | ||
// In order to fix github issue at https://github.com/aws/aws-sdk-cpp/issues/232 | ||
// Created dir by this process will be set with mode 0777, so that multiple users can build on the same machine | ||
umask(0); | ||
#endif | ||
Aws::Testing::RedirectHomeToTempIfAppropriate(); | ||
|
||
// Disable EC2 metadata in client configuration to avoid requests retrieving EC2 metadata in unit tests. | ||
Aws::Testing::SaveEnvironmentVariable("AWS_EC2_METADATA_DISABLED"); | ||
Aws::Environment::SetEnv("AWS_EC2_METADATA_DISABLED", "true", 1/*override*/); | ||
|
||
::testing::InitGoogleTest(&argc, argv); | ||
int retVal = RUN_ALL_TESTS(); | ||
|
||
return retVal; | ||
} |
34,765 changes: 0 additions & 34,765 deletions
34,765
tools/code-generation/smithy/api-descriptions/model.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...main/java/com/amazonaws/util/awsclientsmithygenerator/generators/ClientConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
package com.amazonaws.util.awsclientsmithygenerator.generators; | ||
|
||
import lombok.Getter; | ||
import software.amazon.smithy.aws.smoketests.model.BaseAwsVendorParams; | ||
|
||
// This is a wrapper class for capturing all the information we need | ||
// either directly or after processing from smithy model file | ||
@Getter | ||
public final class ClientConfiguration { | ||
|
||
private final BaseAwsVendorParams params; | ||
|
||
public ClientConfiguration(BaseAwsVendorParams params) { | ||
this.params = params; | ||
} | ||
|
||
} |
216 changes: 216 additions & 0 deletions
216
.../src/main/java/com/amazonaws/util/awsclientsmithygenerator/generators/CppBlockWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
package com.amazonaws.util.awsclientsmithygenerator.generators; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Stack; | ||
import java.util.List; | ||
import lombok.Data; | ||
|
||
/* | ||
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 { | ||
|
||
//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){ | ||
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){ | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < args.length - 1; i += 2) | ||
{ | ||
sb.append(String.format("%s %s",args[i],args[i+1] )); | ||
if(i + 2 < args.length ) | ||
{ | ||
sb.append(", "); | ||
} | ||
} | ||
return String.format("%s %s(%s)", returnType, functionName, sb.toString()); | ||
} | ||
|
||
|
||
public static String GetLambdaBlock(String returnType, String functionName, String... args){ | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < args.length - 1; i += 2) | ||
{ | ||
sb.append(String.format("%s %s",args[i],args[i+1] )); | ||
if(i + 2 < args.length ) | ||
{ | ||
sb.append(", "); | ||
} | ||
} | ||
//functionName | ||
return String.format("auto %s = [&](%s) -> %s", functionName, sb.toString(), returnType); | ||
} | ||
|
||
@Data | ||
public static class Block { | ||
private List<String> lines; | ||
private String linePrefix; | ||
public Block(String header, int indentLevel) | ||
{ | ||
lines = new ArrayList<>(); | ||
if (!header.isEmpty() ) | ||
{ | ||
addCode(header + "\n{\n", indentLevel); | ||
} | ||
else | ||
{ | ||
addCode("{\n", indentLevel); | ||
} | ||
} | ||
|
||
//Continue with current block | ||
public Block(int indentLevel) | ||
{ | ||
lines = new ArrayList<>(); | ||
addCode("\n", indentLevel); | ||
} | ||
|
||
public void addCode(String code, int indentLevel) | ||
{ | ||
String linePrefix = " ".repeat(indentLevel); | ||
//split by line and add indent. make sure to skip escaped newlines | ||
String[] splitCode = code.split("(?<!\\\\)\\n"); | ||
for (String line : splitCode) { | ||
lines.add(String.format("%s%s",linePrefix,line)); | ||
} | ||
} | ||
|
||
|
||
public List<String> getCodeLines(){ | ||
return lines; | ||
} | ||
} | ||
|
||
//A block can contain multiple blocks | ||
private Stack<Block> blockStack; | ||
private int indentLevel; | ||
private String codeBlock; | ||
private boolean isRootBlockNewScope; | ||
|
||
public CppBlockWriter(String header, int level){ | ||
indentLevel = level; | ||
blockStack = new Stack<>(); | ||
codeBlock = new String(""); | ||
isRootBlockNewScope =true; | ||
openCodeBlock(header); | ||
} | ||
|
||
|
||
public CppBlockWriter(int level){ | ||
indentLevel = level; | ||
blockStack = new Stack<>(); | ||
codeBlock = new String(""); | ||
isRootBlockNewScope =false; | ||
continueCodeBlock(""); | ||
} | ||
|
||
//opens a new block | ||
public CppBlockWriter openCodeBlock(String blockHead){ | ||
//add new block to stack | ||
//use its string builder to add "{" | ||
Block block = new Block(blockHead, indentLevel); | ||
blockStack.add(block); | ||
indentLevel++; | ||
return this; | ||
} | ||
|
||
public CppBlockWriter continueCodeBlock(String code){ | ||
//add new block to stack | ||
//use its string builder to add "{" | ||
Block block = new Block(indentLevel); | ||
if(blockStack.empty()) | ||
{ | ||
blockStack.add(block); | ||
} | ||
|
||
//merge with last block | ||
blockStack.peek().addCode(code, indentLevel); | ||
|
||
return this; | ||
} | ||
|
||
|
||
//add code to current block | ||
public CppBlockWriter addCode(String code){ | ||
if (!blockStack.isEmpty()) { | ||
|
||
Block top = blockStack.peek(); | ||
top.addCode(code, indentLevel); | ||
} | ||
return this; | ||
} | ||
|
||
//closes current block | ||
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 | ||
if(blockStack.size() == 1 && !isRootBlockNewScope) | ||
{ | ||
Block top = blockStack.peek(); | ||
top.addCode("\n", indentLevel); | ||
codeLines = top.getCodeLines(); | ||
blockStack.pop(); | ||
} | ||
//create string and close block with "}" | ||
//pop block of stack | ||
//write to prior element | ||
//return the popped one if any | ||
else if (!blockStack.isEmpty()) | ||
{ | ||
Block top = blockStack.peek(); | ||
indentLevel--; | ||
top.addCode("};\n", indentLevel); | ||
codeLines = top.getCodeLines(); | ||
blockStack.pop(); | ||
} | ||
|
||
//after close merge with previous or update root code block | ||
if(blockStack.isEmpty()) | ||
{ | ||
codeBlock = codeBlock.concat(String.join("\n", codeLines)); | ||
} | ||
else | ||
{ | ||
Block top = blockStack.peek(); | ||
top.addCode(String.join("\n", codeLines), indentLevel); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
//closes all nested blocks to generate the string block | ||
String getCode(){ | ||
//if blocks not closed close first | ||
while(!blockStack.isEmpty()) | ||
{ | ||
closeCodeBlock(); | ||
} | ||
|
||
return codeBlock; | ||
} | ||
|
||
} |
Oops, something went wrong.