-
Notifications
You must be signed in to change notification settings - Fork 107
WIP Tracefile creation #204
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,16 +25,21 @@ | |||||||||
import java.util.ServiceLoader; | ||||||||||
import java.util.Set; | ||||||||||
import java.util.TreeSet; | ||||||||||
import java.util.UUID; | ||||||||||
import java.util.logging.Logger; | ||||||||||
import software.amazon.smithy.build.FileManifest; | ||||||||||
import software.amazon.smithy.build.PluginContext; | ||||||||||
import software.amazon.smithy.codegen.core.Symbol; | ||||||||||
import software.amazon.smithy.codegen.core.SymbolDependency; | ||||||||||
import software.amazon.smithy.codegen.core.SymbolProvider; | ||||||||||
import software.amazon.smithy.codegen.core.TopologicalIndex; | ||||||||||
import software.amazon.smithy.codegen.core.trace.ArtifactDefinitions; | ||||||||||
import software.amazon.smithy.codegen.core.trace.TraceMetadata; | ||||||||||
import software.amazon.smithy.codegen.core.trace.TracingSymbolProvider; | ||||||||||
import software.amazon.smithy.model.Model; | ||||||||||
import software.amazon.smithy.model.knowledge.TopDownIndex; | ||||||||||
import software.amazon.smithy.model.neighbor.Walker; | ||||||||||
import software.amazon.smithy.model.node.Node; | ||||||||||
import software.amazon.smithy.model.shapes.OperationShape; | ||||||||||
import software.amazon.smithy.model.shapes.ServiceShape; | ||||||||||
import software.amazon.smithy.model.shapes.Shape; | ||||||||||
|
@@ -93,6 +98,7 @@ class CodegenVisitor extends ShapeVisitor.Default<Void> { | |||||||||
runtimePlugins.add(runtimePlugin); | ||||||||||
}); | ||||||||||
}); | ||||||||||
|
||||||||||
// Sort the integrations in specified order. | ||||||||||
integrations.sort(Comparator.comparingInt(TypeScriptIntegration::getOrder)); | ||||||||||
|
||||||||||
|
@@ -119,13 +125,44 @@ class CodegenVisitor extends ShapeVisitor.Default<Void> { | |||||||||
for (TypeScriptIntegration integration : integrations) { | ||||||||||
resolvedProvider = integration.decorateSymbolProvider(settings, model, resolvedProvider); | ||||||||||
} | ||||||||||
symbolProvider = SymbolProvider.cache(resolvedProvider); | ||||||||||
|
||||||||||
// Resolve the nullable protocol generator and application protocol. | ||||||||||
protocolGenerator = resolveProtocolGenerator(integrations, service, settings); | ||||||||||
applicationProtocol = protocolGenerator == null | ||||||||||
? ApplicationProtocol.createDefaultHttpApplicationProtocol() | ||||||||||
: protocolGenerator.getApplicationProtocol(); | ||||||||||
// Make the symbol provider a cachingSymbolProvider. | ||||||||||
SymbolProvider cachedProvider = SymbolProvider.cache(resolvedProvider); | ||||||||||
// Defining Definitions for TraceFile Generation. | ||||||||||
ArtifactDefinitions artifactDefinitions = ArtifactDefinitions.builder() | ||||||||||
.addType(TypeScriptShapeLinkProvider.FIELD_TYPE, | ||||||||||
"Field declaration (includes enum constants)") | ||||||||||
.addType(TypeScriptShapeLinkProvider.METHOD_TYPE, "Method declaration") | ||||||||||
.addType(TypeScriptShapeLinkProvider.TYPE_TYPE, | ||||||||||
"Class, interface (including annotation type), or enum declaration") | ||||||||||
.addTag(TypeScriptShapeLinkProvider.SERVICE_TAG, "Service client") | ||||||||||
.addTag(TypeScriptShapeLinkProvider.REQUEST_TAG, "AWS SDK request type") | ||||||||||
.addTag(TypeScriptShapeLinkProvider.RESPONSE_TAG, "AWS SDK response type") | ||||||||||
Comment on lines
+144
to
+145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
.addTag(TypeScriptShapeLinkProvider.SERIALIZER_TAG, "Command serializer") | ||||||||||
.addTag(TypeScriptShapeLinkProvider.DESERIALIZER_TAG, "Command deserializer") | ||||||||||
.build(); | ||||||||||
|
||||||||||
String serviceId = service.getId().getName(); | ||||||||||
TraceMetadata artifactMetadata = TraceMetadata.builder() | ||||||||||
.setTimestampAsNow() | ||||||||||
.id(serviceId) | ||||||||||
.version(UUID.randomUUID().toString()) | ||||||||||
.type("TypeScript") | ||||||||||
.build(); | ||||||||||
|
||||||||||
|
||||||||||
// Decorate the symbol provider using the trace file generator. | ||||||||||
symbolProvider = TracingSymbolProvider.builder() | ||||||||||
.symbolProvider(cachedProvider) | ||||||||||
.metadata(artifactMetadata) | ||||||||||
.artifactDefinitions(artifactDefinitions) | ||||||||||
.shapeLinkCreator(new TypeScriptShapeLinkProvider()) | ||||||||||
.build(); | ||||||||||
|
||||||||||
writers = new TypeScriptDelegator(settings, model, fileManifest, symbolProvider, integrations); | ||||||||||
} | ||||||||||
|
@@ -212,6 +249,13 @@ void execute() { | |||||||||
settings, model, protocol, symbolProvider, writers, protocolGenerator).run(); | ||||||||||
} | ||||||||||
|
||||||||||
// Write the TraceFile. | ||||||||||
TracingSymbolProvider traceProvider = (TracingSymbolProvider) symbolProvider; | ||||||||||
String traceName = symbolProvider.toSymbol(service).getName().replace("Client", "") | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notable that the replace here won't do anything for ssdks. That's probably fine though because we don't want them to share a filename, even if they can't be generated in the same plugin. |
||||||||||
.toLowerCase() + ".trace.json"; | ||||||||||
fileManifest.writeFile(traceName, | ||||||||||
Node.prettyPrintJson(traceProvider.buildTraceFile().toNode())); | ||||||||||
|
||||||||||
// Write each pending writer. | ||||||||||
LOGGER.fine("Flushing TypeScript writers"); | ||||||||||
List<SymbolDependency> dependencies = writers.getDependencies(); | ||||||||||
|
@@ -428,7 +472,7 @@ private void generateCommands(ServiceShape shape) { | |||||||||
TopDownIndex topDownIndex = TopDownIndex.of(model); | ||||||||||
Set<OperationShape> containedOperations = new TreeSet<>(topDownIndex.getContainedOperations(shape)); | ||||||||||
for (OperationShape operation : containedOperations) { | ||||||||||
// Right now this only generates stubs | ||||||||||
// Right now this only generates stubs. | ||||||||||
if (settings.generateClient()) { | ||||||||||
writers.useShapeWriter(operation, commandWriter -> new CommandGenerator( | ||||||||||
settings, model, operation, symbolProvider, commandWriter, | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,6 +250,7 @@ public Symbol operationShape(OperationShape shape) { | |
// Add input and output type symbols (XCommandInput / XCommandOutput). | ||
builder.putProperty("inputType", intermediate.toBuilder().name(commandName + "Input").build()); | ||
builder.putProperty("outputType", intermediate.toBuilder().name(commandName + "Output").build()); | ||
|
||
return builder.build(); | ||
} | ||
|
||
|
@@ -327,14 +328,20 @@ private Symbol.Builder addSmithyUseImport(Symbol.Builder builder, String name, S | |
|
||
@Override | ||
public Symbol unionShape(UnionShape shape) { | ||
return createObjectSymbolBuilder(shape).build(); | ||
return createObjectSymbolBuilder(shape) | ||
.putProperty("SymbolProvider", this) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public Symbol memberShape(MemberShape shape) { | ||
Shape targetShape = model.getShape(shape.getTarget()) | ||
.orElseThrow(() -> new CodegenException("Shape not found: " + shape.getTarget())); | ||
Symbol targetSymbol = toSymbol(targetShape); | ||
Symbol targetSymbol = toSymbol(targetShape) | ||
.toBuilder() | ||
.putProperty("model", model) | ||
.putProperty("SymbolProvider", this) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this safe? Any plugin that wraps the symbol provider could trip this up. Ideally they wouldn't, since they shouldn't touch members or unions, but it could become an issue. |
||
.build(); | ||
|
||
if (targetSymbol.getProperties().containsKey(EnumTrait.class.getName())) { | ||
return createMemberSymbolWithEnumTarget(targetSymbol); | ||
|
@@ -383,14 +390,20 @@ private Symbol.Builder createObjectSymbolBuilder(Shape shape) { | |
} | ||
|
||
private Symbol.Builder createSymbolBuilder(Shape shape, String typeName) { | ||
return Symbol.builder().putProperty("shape", shape).name(typeName); | ||
return Symbol.builder() | ||
.putProperty("shape", shape) | ||
.putProperty("traceFileNamespace", moduleNameDelegator.formatModuleName(shape, null)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These calls to the moduleNameDelegator are causing issues for the model chunking. This needs address before the PR can be merged. Testing with regenerating an existing client should be performed to assure that the model chunking isn't changed unnecessarily for an existing client. |
||
.putProperty("traceFileNamespaceDelimiter", "/") | ||
.name(typeName); | ||
} | ||
|
||
private Symbol.Builder createSymbolBuilder(Shape shape, String typeName, String namespace) { | ||
return Symbol.builder() | ||
.putProperty("shape", shape) | ||
.name(typeName) | ||
.namespace(namespace, "/"); | ||
.namespace(namespace, "/") | ||
.putProperty("traceFileNamespace", moduleNameDelegator.formatModuleName(shape, null)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above. Another call to moduleNameDelegator that should be addressed. |
||
.putProperty("traceFileNamespaceDelimiter", "/"); | ||
} | ||
|
||
private Symbol.Builder createGeneratedSymbolBuilder(Shape shape, String typeName, String namespace) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.