Skip to content

Commit

Permalink
Merge branch 'main' into davidpz/error-log-server-response-rejections
Browse files Browse the repository at this point in the history
  • Loading branch information
david-perez authored Apr 4, 2023
2 parents 799e75e + c901c0b commit d9d9efe
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
5 changes: 2 additions & 3 deletions aws/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import aws.sdk.AwsServices
import aws.sdk.Membership
import aws.sdk.RootTest
import aws.sdk.discoverServices
import aws.sdk.docsLandingPage
import aws.sdk.parseMembership
Expand Down Expand Up @@ -302,9 +301,9 @@ tasks.register<Copy>("relocateChangelog") {
fun generateCargoWorkspace(services: AwsServices): String {
return """
|[workspace]
|exclude = [${"\n"}${services.rootTests.map(RootTest::manifestName).joinToString(",\n") { "| \"$it\"" }}
|exclude = [${"\n"}${services.excludedFromWorkspace().joinToString(",\n") { "| \"$it\"" }}
|]
|members = [${"\n"}${services.allModules.joinToString(",\n") { "| \"$it\"" }}
|members = [${"\n"}${services.includedInWorkspace().joinToString(",\n") { "| \"$it\"" }}
|]
""".trimMargin()
}
Expand Down
16 changes: 13 additions & 3 deletions buildSrc/src/main/kotlin/aws/sdk/ServiceLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class AwsServices(
(
services.map(AwsService::module).map { "sdk/$it" } +
CrateSet.AWS_SDK_SMITHY_RUNTIME.map { "sdk/$it" } +
CrateSet.AWS_SDK_RUNTIME.map { "sdk/$it" } +
examples
CrateSet.AWS_SDK_RUNTIME.map { "sdk/$it" }
// Root tests should not be included since they can't be part of the root Cargo workspace
// in order to test differences in Cargo features.
// in order to test differences in Cargo features. Examples should not be included either
// because each example itself is a workspace.
).toSortedSet()
}

Expand Down Expand Up @@ -78,6 +78,16 @@ class AwsServices(
false
}
}

/**
* Returns a sorted set of members included in the workspace.
*/
fun includedInWorkspace() = allModules

/**
* Returns a list of crates excluded from the workspace.
*/
fun excludedFromWorkspace() = examples + rootTests.map(RootTest::manifestName)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1133,17 +1133,13 @@ class ServerHttpBoundProtocolTraitImplGenerator(
check(target is NumberShape || target is BooleanShape)
rustTemplate(
"""
let value = std::str::FromStr::from_str(value)?;
let value = <_ as #{PrimitiveParse}>::parse_smithy_primitive(value)?;
""",
*codegenScope,
"PrimitiveParse" to RuntimeType.smithyTypes(runtimeConfig).resolve("primitive::Parse"),
)
}
}
rust(
"""
Ok(${symbolProvider.wrapOptional(binding.member, "value")})
""",
)
rust("Ok(${symbolProvider.wrapOptional(binding.member, "value")})")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,6 @@ pub enum RequestRejection {
/// into "primitive" types.
PrimitiveParse(crate::Error),

// The following three variants are used when failing to deserialize strings from a URL query
// string and URI path labels into "primitive" types.
// TODO(https://github.com/awslabs/smithy-rs/issues/1232): They should be removed and
// conflated into the `PrimitiveParse` variant above after this issue is resolved.
IntParse(crate::Error),
FloatParse(crate::Error),
BoolParse(crate::Error),

/// Used when consuming the input struct builder, and constraint violations occur.
// Unlike the rejections above, this does not take in `crate::Error`, since it is constructed
// directly in the code-generated SDK instead of in this crate.
Expand Down Expand Up @@ -192,9 +184,6 @@ convert_to_request_rejection!(aws_smithy_json::deserialize::error::DeserializeEr
convert_to_request_rejection!(aws_smithy_http::header::ParseError, HeaderParse);
convert_to_request_rejection!(aws_smithy_types::date_time::DateTimeParseError, DateTimeParse);
convert_to_request_rejection!(aws_smithy_types::primitive::PrimitiveParseError, PrimitiveParse);
convert_to_request_rejection!(std::str::ParseBoolError, BoolParse);
convert_to_request_rejection!(std::num::ParseFloatError, FloatParse);
convert_to_request_rejection!(std::num::ParseIntError, IntParse);
convert_to_request_rejection!(serde_urlencoded::de::Error, InvalidUtf8);

impl From<nom::Err<nom::error::Error<&str>>> for RequestRejection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ pub enum RequestRejection {

PrimitiveParse(crate::Error),

IntParse(crate::Error),
FloatParse(crate::Error),
BoolParse(crate::Error),

ConstraintViolation(String),
}

Expand Down Expand Up @@ -81,9 +77,6 @@ convert_to_request_rejection!(aws_smithy_xml::decode::XmlDecodeError, XmlDeseria
convert_to_request_rejection!(aws_smithy_http::header::ParseError, HeaderParse);
convert_to_request_rejection!(aws_smithy_types::date_time::DateTimeParseError, DateTimeParse);
convert_to_request_rejection!(aws_smithy_types::primitive::PrimitiveParseError, PrimitiveParse);
convert_to_request_rejection!(std::str::ParseBoolError, BoolParse);
convert_to_request_rejection!(std::num::ParseFloatError, FloatParse);
convert_to_request_rejection!(std::num::ParseIntError, IntParse);
convert_to_request_rejection!(serde_urlencoded::de::Error, InvalidUtf8);

impl From<nom::Err<nom::error::Error<&str>>> for RequestRejection {
Expand Down
5 changes: 5 additions & 0 deletions tools/ci-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ ARG cargo_wasi_version=0.1.27
ARG rust_nightly_version
RUN cargo +${rust_nightly_version} -Z sparse-registry install cargo-wasi --locked --version ${cargo_wasi_version}

FROM install_rust AS cargo_semver_checks
ARG cargo_semver_checks_version=0.19.0
ARG rust_nightly_version
RUN cargo +${rust_nightly_version} -Z sparse-registry install cargo-semver-checks --locked --version ${cargo_semver_checks_version}
#
# Final image
#
Expand Down Expand Up @@ -174,6 +178,7 @@ COPY --chown=build:build --from=wasm_pack /opt/cargo/bin/wasm-pack /opt/cargo/bi
COPY --chown=build:build --from=wasmtime /opt/wasmtime /opt/cargo/bin/wasmtime
COPY --chown=build:build --from=cargo_wasi /opt/cargo/bin/cargo-wasi /opt/cargo/bin/cargo-wasi
COPY --chown=build:build --from=install_rust /opt/rustup /opt/rustup
COPY --chown=build:build --from=cargo_semver_checks /opt/cargo/bin/cargo-semver-checks /opt/cargo/bin/cargo-semver-checks
COPY --chown=build:build --from=musl_toolchain /usr/local/musl/ /usr/local/musl/
ENV PATH=$PATH:/usr/local/musl/bin/
ENV PATH=/opt/cargo/bin:$PATH \
Expand Down
1 change: 1 addition & 0 deletions tools/ci-build/sanity-test
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ python3 --version
rustc +"${RUST_NIGHTLY_VERSION}" --version
rustc --version
sdk-versioner --version
cargo semver-checks --version
27 changes: 17 additions & 10 deletions tools/ci-scripts/codegen-diff/diff_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,37 @@

CDN_URL = "https://d2luzm2xt3nokh.cloudfront.net"

target_codegen_client = 'codegen-client-test'
target_codegen_server = 'codegen-server-test'
target_aws_sdk = 'aws:sdk'


def generate_and_commit_generated_code(revision_sha, targets=None):
targets = targets or ['codegen-client-test', 'codegen-server-test', 'aws:sdk']
targets = targets or [target_codegen_client, target_codegen_server, target_aws_sdk]
# Clean the build artifacts before continuing
get_cmd_output("rm -rf aws/sdk/build")
if 'codegen-server-test' in targets:
if target_codegen_server in targets:
get_cmd_output("cd rust-runtime/aws-smithy-http-server-python/examples && make distclean", shell=True)
get_cmd_output("./gradlew codegen-core:clean codegen-client:clean codegen-server:clean aws:sdk-codegen:clean")

# Generate code
tasks = ' '.join([f'{t}:assemble' for t in targets])
get_cmd_output(f"./gradlew --rerun-tasks {tasks}")
if 'codegen-server-test' in targets:
if target_codegen_server in targets:
get_cmd_output("cd rust-runtime/aws-smithy-http-server-python/examples && make build", shell=True, check=False)

# Move generated code into codegen-diff/ directory
get_cmd_output(f"rm -rf {OUTPUT_PATH}")
get_cmd_output(f"mkdir {OUTPUT_PATH}")
if 'aws:sdk' in targets:
if target_aws_sdk in targets:
get_cmd_output(f"mv aws/sdk/build/aws-sdk {OUTPUT_PATH}/")
for target in ['codegen-client', 'codegen-server']:
for target in [target_codegen_client, target_codegen_server]:
if target in targets:
get_cmd_output(f"mv {target}/build/smithyprojections/{target} {OUTPUT_PATH}/")
if target == 'codegen-server-test':
get_cmd_output(f"mv rust-runtime/aws-smithy-http-server-python/examples/pokemon-service-server-sdk/ {OUTPUT_PATH}/codegen-server-test-python/", check=False)
if target == target_codegen_server:
get_cmd_output(
f"mv rust-runtime/aws-smithy-http-server-python/examples/pokemon-service-server-sdk/ {OUTPUT_PATH}/codegen-server-test-python/",
check=False)

# Clean up the SDK directory
get_cmd_output(f"rm -f {OUTPUT_PATH}/aws-sdk/versions.toml")
Expand All @@ -58,9 +64,9 @@ def generate_and_commit_generated_code(revision_sha, targets=None):

get_cmd_output(f"git add -f {OUTPUT_PATH}")
get_cmd_output(f"git -c 'user.name=GitHub Action (generated code preview)' "
f"-c 'user.name={COMMIT_AUTHOR_NAME}' "
f"-c 'user.email={COMMIT_AUTHOR_EMAIL}' "
f"commit --no-verify -m 'Generated code for {revision_sha}' --allow-empty")
f"-c 'user.name={COMMIT_AUTHOR_NAME}' "
f"-c 'user.email={COMMIT_AUTHOR_EMAIL}' "
f"commit --no-verify -m 'Generated code for {revision_sha}' --allow-empty")


def make_diff(title, path_to_diff, base_commit_sha, head_commit_sha, suffix, whitespace):
Expand Down Expand Up @@ -167,6 +173,7 @@ def get_cmd_output(command, cwd=None, check=True, **kwargs):

return result.returncode, stdout, stderr


# Runs a shell command and returns its exit status
def get_cmd_status(command):
return subprocess.run(command, capture_output=True, shell=True).returncode

0 comments on commit d9d9efe

Please sign in to comment.