Skip to content

Commit d17544d

Browse files
committed
reverted to have everything in pagination codegen
1 parent a114355 commit d17544d

3 files changed

Lines changed: 102 additions & 107 deletions

File tree

tools/code-generation/smithy/codegen/build.gradle.kts

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
import software.amazon.smithy.model.Model
2-
import software.amazon.smithy.model.node.Node
3-
import software.amazon.smithy.model.shapes.ServiceShape
4-
import software.amazon.smithy.aws.traits.ServiceTrait
5-
import org.gradle.api.logging.Logging
6-
import kotlin.streams.toList
7-
8-
val logger = Logging.getLogger("MyLogger")
9-
101
plugins {
112
id("java-library")
12-
id("software.amazon.smithy.gradle.smithy-base").version("1.3.0")
133
}
144

155
repositories {
@@ -22,101 +12,9 @@ allprojects {
2212
version = "0.1.0"
2313
}
2414

25-
buildscript {
26-
dependencies {
27-
classpath(codegen.model)
28-
classpath(codegen.aws.traits)
29-
classpath(codegen.aws.smoke.test.model)
30-
classpath(codegen.rules.engine)
31-
}
32-
}
33-
3415
dependencies {
35-
implementation(project(":cpp-pagination-codegen"))
36-
implementation(codegen.aws.traits)
37-
implementation(codegen.aws.cloudformation.traits)
38-
implementation(codegen.aws.iam.traits)
39-
implementation(codegen.aws.endpoints)
40-
implementation(codegen.waiters)
41-
implementation(codegen.smoke.test.traits)
42-
implementation(codegen.aws.smoke.test.model)
4316
}
4417

45-
tasks.jar {
46-
enabled = false
47-
}
48-
49-
// Generates a smithy-build.json with a projection for each service, including
50-
// only that service's model.
51-
tasks.register("generate-smithy-build") {
52-
doLast {
53-
val projectionsBuilder = Node.objectNodeBuilder()
54-
val models = project.file("../api-descriptions")
55-
val filteredServices: String = project.findProperty("servicesFilter")?.toString() ?: ""
56-
val filteredServiceList = filteredServices.split(",").map { it.trim() }.filter { it.isNotEmpty() }
57-
val c2jMapStr: String = project.findProperty("c2jMap")?.toString() ?: ""
58-
59-
fileTree(models).filter { it.isFile }.files.forEach eachFile@{ file ->
60-
val model = Model.assembler()
61-
.addImport(file.absolutePath)
62-
// Grab the result directly rather than worrying about checking for errors via unwrap.
63-
// All we care about here is the service shape, any unchecked errors will be exposed
64-
// as part of the actual build task done by the smithy gradle plugin.
65-
.assemble().result.get()
66-
val services = model.shapes(ServiceShape::class.java).sorted().toList()
67-
if (services.size != 1) return@eachFile
68-
69-
val service = services[0]
70-
val serviceTrait = service.getTrait(ServiceTrait::class.java).get()
71-
72-
// Clean up sdkId
73-
val sdkId = serviceTrait.sdkId.replace(" ", "-").replace("_", "-").lowercase()
74-
75-
// Filter by service id if necessary
76-
if (filteredServiceList.isNotEmpty() && sdkId !in filteredServiceList) return@eachFile
77-
78-
// Create projection contents
79-
val projectionContents = Node.objectNodeBuilder()
80-
.withMember("imports", Node.fromStrings("${models.absolutePath}${File.separator}${file.name}"))
81-
.withMember("plugins", Node.objectNode()
82-
.withMember("cpp-codegen-pagination-plugin", Node.objectNodeBuilder()
83-
.withMember("c2jMap", Node.from(c2jMapStr))
84-
.build()))
85-
.build()
86-
87-
// Add the projection contents to the projections builder
88-
projectionsBuilder.withMember("$sdkId.${service.version.lowercase()}", projectionContents)
89-
}
90-
91-
// TODO: Remove this workaround - legacy services should have proper Smithy model files
92-
// instead of hardcoding service names in both Gradle and Java
93-
// Currently only needed for importexport, sdb (SimpleDB), and s3-crt
94-
// Add mock projections for legacy C2J-only services
95-
val legacyServices = mapOf("importexport" to "ImportExport", "sdb" to "SimpleDB", "s3-crt" to "S3Crt")
96-
legacyServices.forEach { (c2jName, pascalName) ->
97-
if (filteredServiceList.isEmpty() || c2jName in filteredServiceList) {
98-
val mockProjectionContents = Node.objectNodeBuilder()
99-
.withMember("plugins", Node.objectNode()
100-
.withMember("cpp-codegen-pagination-plugin", Node.objectNodeBuilder()
101-
.withMember("c2jMap", Node.from(c2jMapStr))
102-
.build()))
103-
.build()
104-
projectionsBuilder.withMember("$c2jName.mock", mockProjectionContents)
105-
}
106-
}
107-
108-
val outputDirectoryArg = project.findProperty("outputDirectory")?.toString() ?: "output"
109-
file("smithy-build.json").writeText(Node.prettyPrintJson(Node.objectNodeBuilder()
110-
.withMember("version", "1.0")
111-
.withMember("projections", projectionsBuilder.build())
112-
.withMember("outputDirectory", outputDirectoryArg)
113-
.build()))
114-
}
115-
}
116-
117-
// Generate smithy-build.json before running the build
118-
tasks["build"].dependsOn(tasks["generate-smithy-build"])
119-
12018
// Prevent cpp-smoke-tests from building when root build is invoked
12119
project(":cpp-smoke-tests").tasks.configureEach {
12220
enabled = false

tools/code-generation/smithy/codegen/cpp-pagination-codegen/build.gradle.kts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
import software.amazon.smithy.model.Model
2+
import software.amazon.smithy.model.node.Node
3+
import software.amazon.smithy.model.shapes.ServiceShape
4+
import software.amazon.smithy.aws.traits.ServiceTrait
5+
import org.gradle.api.logging.Logging
6+
import kotlin.streams.toList
7+
8+
val logger = Logging.getLogger("MyLogger")
9+
110
plugins {
211
`java-library`
312
}
@@ -7,6 +16,15 @@ repositories {
716
mavenCentral()
817
}
918

19+
buildscript {
20+
dependencies {
21+
classpath("software.amazon.smithy:smithy-model:1.51.0")
22+
classpath("software.amazon.smithy:smithy-aws-traits:1.51.0")
23+
classpath("software.amazon.smithy:smithy-aws-smoke-test-model:1.51.0")
24+
classpath("software.amazon.smithy:smithy-rules-engine:1.51.0")
25+
}
26+
}
27+
1028
dependencies {
1129
implementation("software.amazon.smithy:smithy-model:1.51.0")
1230
implementation("software.amazon.smithy:smithy-codegen-core:1.51.0")
@@ -15,4 +33,83 @@ dependencies {
1533
implementation("software.amazon.smithy:smithy-rules-engine:1.51.0")
1634
implementation("software.amazon.smithy:smithy-aws-endpoints:1.51.0")
1735
implementation("software.amazon.smithy:smithy-aws-iam-traits:1.51.0")
36+
implementation("software.amazon.smithy:smithy-smoke-test-traits:1.51.0")
37+
implementation("software.amazon.smithy:smithy-aws-smoke-test-model:1.51.0")
38+
}
39+
40+
tasks.jar {
41+
enabled = true
1842
}
43+
44+
// Generates a smithy-build.json with a projection for each service, including
45+
// only that service's model.
46+
tasks.register("generate-smithy-build") {
47+
doLast {
48+
val projectionsBuilder = Node.objectNodeBuilder()
49+
val models = project.file("../../api-descriptions")
50+
val filteredServices: String = project.findProperty("servicesFilter")?.toString() ?: ""
51+
val filteredServiceList = filteredServices.split(",").map { it.trim() }.filter { it.isNotEmpty() }
52+
val c2jMapStr: String = project.findProperty("c2jMap")?.toString() ?: ""
53+
54+
fileTree(models).filter { it.isFile }.files.forEach eachFile@{ file ->
55+
// Quick check: if we have a service filter, try to match by filename first
56+
if (filteredServiceList.isNotEmpty()) {
57+
val fileName = file.nameWithoutExtension.lowercase()
58+
val matchesFilter = filteredServiceList.any { service ->
59+
fileName == service.lowercase() || fileName == service.replace("-", "").lowercase()
60+
}
61+
if (!matchesFilter) return@eachFile
62+
}
63+
64+
val model = Model.assembler()
65+
.addImport(file.absolutePath)
66+
.assemble().result.get()
67+
val services = model.shapes(ServiceShape::class.java).sorted().toList()
68+
if (services.size != 1) return@eachFile
69+
70+
val service = services[0]
71+
val serviceTrait = service.getTrait(ServiceTrait::class.java).get()
72+
73+
// Clean up sdkId
74+
val sdkId = serviceTrait.sdkId.replace(" ", "-").replace("_", "-").lowercase()
75+
76+
// Filter by service id if necessary
77+
if (filteredServiceList.isNotEmpty() && sdkId !in filteredServiceList) return@eachFile
78+
79+
// Create projection contents
80+
val projectionContents = Node.objectNodeBuilder()
81+
.withMember("imports", Node.fromStrings("${models.absolutePath}${File.separator}${file.name}"))
82+
.withMember("plugins", Node.objectNode()
83+
.withMember("cpp-codegen-pagination-plugin", Node.objectNodeBuilder()
84+
.withMember("c2jMap", Node.from(c2jMapStr))
85+
.build()))
86+
.build()
87+
88+
// Add the projection contents to the projections builder
89+
projectionsBuilder.withMember("$sdkId.${service.version.lowercase()}", projectionContents)
90+
}
91+
92+
// Add mock projections for legacy C2J-only services
93+
val legacyServices = mapOf("importexport" to "ImportExport", "sdb" to "SimpleDB", "s3-crt" to "S3Crt")
94+
legacyServices.forEach { (c2jName, pascalName) ->
95+
if (filteredServiceList.isEmpty() || c2jName in filteredServiceList) {
96+
val mockProjectionContents = Node.objectNodeBuilder()
97+
.withMember("plugins", Node.objectNode()
98+
.withMember("cpp-codegen-pagination-plugin", Node.objectNodeBuilder()
99+
.withMember("c2jMap", Node.from(c2jMapStr))
100+
.build()))
101+
.build()
102+
projectionsBuilder.withMember("$c2jName.mock", mockProjectionContents)
103+
}
104+
}
105+
106+
val outputDirectoryArg = project.findProperty("outputDirectory")?.toString() ?: "output"
107+
file("smithy-build.json").writeText(Node.prettyPrintJson(Node.objectNodeBuilder()
108+
.withMember("version", "1.0")
109+
.withMember("projections", projectionsBuilder.build())
110+
.withMember("outputDirectory", outputDirectoryArg)
111+
.build()))
112+
}
113+
}
114+
115+
tasks["build"].dependsOn(tasks["generate-smithy-build"])

tools/scripts/codegen/pagination_gen.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def generate(self, clients_to_build: set):
4444
def _generate_pagination(self, smithy_services: List[str], smithy_c2j_data: str):
4545
smithy_codegen_command = [
4646
"./gradlew",
47-
"clean",
48-
"build",
47+
":cpp-pagination-codegen:clean",
48+
":cpp-pagination-codegen:build",
4949
"-PservicesFilter=" + ",".join(smithy_services),
5050
"-Pc2jMap=" + smithy_c2j_data
5151
]
@@ -73,8 +73,8 @@ def _generate_pagination(self, smithy_services: List[str], smithy_c2j_data: str)
7373
return False
7474

7575
def _copy_cpp_codegen_contents(self, top_level_dir: str, plugin_name: str, target_dir: str):
76-
# Walk through the output directory to find plugin directories
77-
output_dir = os.path.join(top_level_dir, "output")
76+
# Walk through the cpp-pagination-codegen output directory to find plugin directories
77+
output_dir = os.path.join(top_level_dir, "cpp-pagination-codegen", "output")
7878
# TODO: Verify if this check is still needed after Smithy generator always creates output
7979
if not os.path.exists(output_dir):
8080
if self.debug:
@@ -124,7 +124,7 @@ def _copy_cpp_codegen_contents(self, top_level_dir: str, plugin_name: str, targe
124124
if self.debug:
125125
print(f"Cleaned up '{output_dir}'")
126126

127-
smithy_build_json = os.path.join(top_level_dir, "smithy-build.json")
127+
smithy_build_json = os.path.join(top_level_dir, "cpp-pagination-codegen", "smithy-build.json")
128128
if os.path.exists(smithy_build_json):
129129
os.remove(smithy_build_json)
130130
if self.debug:

0 commit comments

Comments
 (0)