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

First cut at SPI / AWS Customizations (#101)

* Add SPI capability to codegen

* Logging improvements

* Wire up aws-sdk-codegen for AWS-specific customizations

* Add AWS SDK codegen sources

* Drop dokka from aws-sdk-codegen
parent 25deed8d
Loading
Loading
Loading
Loading
+92 −0
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */
plugins {
    kotlin("jvm")
    jacoco
    maven
    `maven-publish`
}

description = "AWS Specific Customizations for Smithy code generation"
extra["displayName"] = "Smithy :: Rust :: AWS Codegen"
extra["moduleName"] = "software.amazon.smithy.rustsdk"

group = "software.amazon.software.amazon.smithy.rust.codegen.smithy"
version = "0.1.0"

val smithyVersion: String by project

dependencies {
    implementation(project(":codegen"))
    implementation("software.amazon.smithy:smithy-aws-protocol-tests:$smithyVersion")
    implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
    implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
}

tasks.compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

tasks.compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

// Reusable license copySpec
val licenseSpec = copySpec {
    from("${project.rootDir}/LICENSE")
    from("${project.rootDir}/NOTICE")
}

// Configure jars to include license related info
tasks.jar {
    metaInf.with(licenseSpec)
    inputs.property("moduleName", project.name)
    manifest {
        attributes["Automatic-Module-Name"] = project.name
    }
}

val sourcesJar by tasks.creating(Jar::class) {
    group = "publishing"
    description = "Assembles Kotlin sources jar"
    classifier = "sources"
    from(sourceSets.getByName("main").allSource)
}

tasks.test {
    useJUnitPlatform()
    testLogging {
        events("passed", "skipped", "failed")
        showStandardStreams = true
    }
}


// Configure jacoco (code coverage) to generate an HTML report
tasks.jacocoTestReport {
    reports {
        xml.isEnabled = false
        csv.isEnabled = false
        html.destination = file("$buildDir/reports/jacoco")
    }
}

// Always run the jacoco test report after testing.
tasks["test"].finalizedBy(tasks["jacocoTestReport"])


publishing {
    publications {
        create<MavenPublication>("default") {
            from(components["java"])
            artifact(sourcesJar)
        }
    }
    repositories {
        maven {
            url = uri("$buildDir/repository")
        }
    }
}
+21 −0
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

package software.amazon.smithy.rustsdk

import software.amazon.smithy.rust.codegen.smithy.RustCodegenDecorator
import software.amazon.smithy.rust.codegen.smithy.generators.ProtocolConfig
import software.amazon.smithy.rust.codegen.smithy.generators.config.ConfigCustomization

class AwsCodegenDecorator : RustCodegenDecorator {
    override val name: String = "AwsSdkCodgenDecorator"
    override val order: Byte = -1
    override fun configCustomizations(
        protocolConfig: ProtocolConfig,
        baseCustomizations: List<ConfigCustomization>
    ): List<ConfigCustomization> {
        return listOf(BaseAwsConfig()) + baseCustomizations
    }
}
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

package software.amazon.smithy.rustsdk

import software.amazon.smithy.rust.codegen.rustlang.Attribute
import software.amazon.smithy.rust.codegen.rustlang.rust
import software.amazon.smithy.rust.codegen.rustlang.writable
import software.amazon.smithy.rust.codegen.smithy.generators.config.ConfigCustomization
import software.amazon.smithy.rust.codegen.smithy.generators.config.ServiceConfig

/**
 * Just a Stub
 *
 * Augment the config object with the AWS-specific fields like service and region
 */
class BaseAwsConfig : ConfigCustomization() {
    override fun section(section: ServiceConfig) = writable {
        when (section) {
            ServiceConfig.ConfigStruct -> {
                Attribute.AllowUnused.render(this)
                rust("pub(crate) region: String,")
            }
            ServiceConfig.BuilderBuild -> rust("region: \"todo\".to_owned(),")
            else -> {}
            /*ServiceConfig.ConfigImpl -> TODO()
            ServiceConfig.BuilderStruct -> TODO()
            ServiceConfig.BuilderImpl -> TODO()
            ServiceConfig.BuilderBuild -> TODO()*/
        }
    }
}
+1 −0
Original line number Diff line number Diff line
software.amazon.smithy.rustsdk.AwsCodegenDecorator

aws-sdk/README.md

0 → 100644
+13 −0
Original line number Diff line number Diff line
# AWS SDK Generator

This directory contains a gradle project to generate an AWS SDK. It uses the Smithy Build Plugin combined with the customizations specified in `aws-sdk-codegen` to generate an AWS SDK from Smithy models.

`build.gradle.kts` will generate a `smithy-build.json` dynamically from all models in the `models` directory.

## Usage

Generate an SDK:
`./gradlew :aws-sdk:assemble`

Generate, compile, and test an SDK:
`./gradlew :aws-sdk:build`
Loading