Unverified Commit b8a3b28a authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

More bugfixes from adding every service (#541)

* Suppress noisy logging from the renamer

* Allow codegen settings model settings

* fix more naming bugs

* Fix ambiguous binding function name

* Attempt to fix gradle script bugs

* Remove double unescape

* Fix service names in tier 1 services list

* Fix ResponseBindingGeneratorTest
parent fff0f473
Loading
Loading
Loading
Loading
+60 −8
Original line number Diff line number Diff line
@@ -43,7 +43,46 @@ dependencies {
    implementation(project(":aws:sdk-codegen"))
    implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
    implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
}
    implementation("software.amazon.smithy:smithy-aws-iam-traits:$smithyVersion")
    implementation("software.amazon.smithy:smithy-aws-cloudformation-traits:$smithyVersion")
}

// Tier 1 Services have examples and tests
val tier1Services = setOf(
    "apigateway",
    "batch",
    "cloudformation",
    "dynamodb",
    "ec2",
    "ecs",
    "iam",
    "kinesis",
    "kms",
    "lambda",
    "cloudwatchlogs",
    "medialive",
    "mediapackage",
    "polly",
    "qldbsession",
    "qldb",
    "rdsdata",
    "rds",
    "route53",
    "runtime",
    "s3",
    "sagemakera2iruntime",
    "sagemakeredge",
    "sagemakerfeaturestoreruntime",
    "sagemaker",
    "secretsmanager",
    "sesv2",
    "sns",
    "sqs",
    "ssm",
    "sts"
)

private val disableServices = setOf("transcribestreaming")

data class AwsService(
    val service: String,
@@ -55,14 +94,19 @@ data class AwsService(
    fun files(): List<File> = listOf(modelFile) + extraFiles
}

val awsServices: Provider<List<AwsService>> = project.providers.provider { discoverServices() }
val generateAllServices = project.providers.environmentVariable("GENERATE_ALL_SERVICES").orElse("")
val awsServices: Provider<List<AwsService>> = generateAllServices.map { v ->
    discoverServices(v.toLowerCase() == "true")
}

val generateOnly: Set<String>? = null

/**
 * Discovers services from the `models` directory
 *
 * Do not invoke this function directly. Use the `awsServices` provider.
 */
fun discoverServices(): List<AwsService> {
fun discoverServices(allServices: Boolean): List<AwsService> {
    val models = project.file("aws-models")
    return fileTree(models).mapNotNull { file ->
        val model = Model.assembler().addImport(file.absolutePath).assemble().result.get()
@@ -84,6 +128,11 @@ fun discoverServices(): List<AwsService> {
            val sdkId = service.expectTrait(ServiceTrait::class.java).sdkId.toLowerCase().replace(" ", "")
            AwsService(service = service.id.toString(), module = sdkId, modelFile = file, extraFiles = extras)
        }
    }.filterNot { disableServices.contains(it.module) }
        .filter {
            allServices || (generateOnly != null && generateOnly.contains(it.module)) || (generateOnly == null && tier1Services.contains(
                it.module
            ))
        }
}

@@ -157,7 +206,8 @@ task("relocateServices") {
            }
        }
    }
    outputs.upToDateWhen { false }
    inputs.dir("$buildDir/smithyprojections/sdk/")
    outputs.dir(sdkOutputDir)
}

task("relocateExamples") {
@@ -171,6 +221,8 @@ task("relocateExamples") {
            filter { line -> line.replace("build/aws-sdk/", "") }
        }
    }
    inputs.dir(projectDir.resolve("examples"))
    outputs.dir(sdkOutputDir)
}

tasks.register<Copy>("relocateAwsRuntime") {
@@ -182,7 +234,6 @@ tasks.register<Copy>("relocateAwsRuntime") {
    exclude("**/Cargo.lock")
    filter { line -> rewritePathDependency(line) }
    into(sdkOutputDir)
    outputs.upToDateWhen { false }
}

/**
@@ -202,12 +253,13 @@ tasks.register<Copy>("relocateRuntime") {
        exclude("**/Cargo.lock")
    }
    into(sdkOutputDir)
    outputs.upToDateWhen { false }
}

fun generateCargoWorkspace(services: List<AwsService>): String {
    val examples = projectDir.resolve("examples").listFiles { file -> !file.name.startsWith(".") }?.toList()
        ?.map { "examples/${it.name}" }.orEmpty()
    val examples = projectDir.resolve("examples")
        .listFiles { file -> !file.name.startsWith(".") }.orEmpty().toList()
        .filter { generateOnly == null || generateOnly.contains(it.name) }
        .map { "examples/${it.name}" }

    val modules = services.map(AwsService::module) + runtimeModules + awsModules + examples.toList()
    return """
+2 −2
Original line number Diff line number Diff line
@@ -15,6 +15,6 @@ for model in os.listdir("aws-models"):
    model_name = model[:-len('.json')]
    source = Path(aws_models) / model_name / 'smithy' / 'model.json'
    if not source.exists():
        print(f'cannout find: {source}')
        sys.exit(1)
        print(f'warning: cannot find: {source}')
        continue
    shutil.copyfile(source, Path('aws-models') / model)
+4 −0
Original line number Diff line number Diff line
@@ -57,6 +57,10 @@ structure ReservedWords {
    send: String
}

structure Type {
    field: String
}

@httpRequestTests([
    {
        id: "structure_punning",
+3 −1
Original line number Diff line number Diff line
@@ -413,7 +413,9 @@ class RustWriter private constructor(
                    t.rustType().render(fullyQualified = true)
                }
                else -> throw CodegenException("Invalid type provided to RustSymbolFormatter: $t")
            }
                // escaping generates `##` sequences for all the common cases where
                // it will be run through templating, but in this context, we won't be escaped
            }.replace("##", "#")
        }
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -7,15 +7,20 @@ package software.amazon.smithy.rust.codegen.smithy

import software.amazon.smithy.build.PluginContext
import software.amazon.smithy.build.SmithyBuildPlugin
import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.rust.codegen.rustlang.RustReservedWordSymbolProvider
import software.amazon.smithy.rust.codegen.smithy.customize.CombinedCodegenDecorator
import java.util.logging.Level
import java.util.logging.Logger

class RustCodegenPlugin : SmithyBuildPlugin {
    override fun getName(): String = "rust-codegen"

    override fun execute(context: PluginContext) {
        // Suppress extremely noisy logs about reserved words
        Logger.getLogger(ReservedWordSymbolProvider::class.java.name).level = Level.OFF
        val codegenDecorator = CombinedCodegenDecorator.fromClasspath(context)
        CodegenVisitor(context, codegenDecorator).execute()
    }
Loading