diff --git a/ci_config.json b/ci_config.json index 41892cade..de9cf7468 100644 --- a/ci_config.json +++ b/ci_config.json @@ -93,6 +93,11 @@ "numactl-dev" ] }, + "aws-c-sdkutils": { + "build_options": [ + "aws-c-sdkutils:tests=enabled" + ] + }, "argtable3": { "build_options": [ "argtable3:examples=true", diff --git a/releases.json b/releases.json index eb568253b..21526acee 100644 --- a/releases.json +++ b/releases.json @@ -293,6 +293,14 @@ "0.3.1-1" ] }, + "aws-c-sdkutils": { + "dependency_names": [ + "aws-c-sdkutils" + ], + "versions": [ + "0.2.4-1" + ] + }, "backward-cpp": { "dependency_names": [ "backward-cpp", diff --git a/subprojects/aws-c-sdkutils.wrap b/subprojects/aws-c-sdkutils.wrap new file mode 100644 index 000000000..2bdd13e36 --- /dev/null +++ b/subprojects/aws-c-sdkutils.wrap @@ -0,0 +1,9 @@ +[wrap-file] +directory = aws-c-sdkutils-0.2.4 +source_url = https://github.com/awslabs/aws-c-sdkutils/archive/refs/tags/v0.2.4.tar.gz +source_filename = aws-c-sdkutils-0.2.4.tar.gz +source_hash = 493cbed4fa57e0d4622fcff044e11305eb4fc12445f32c8861025597939175fc +patch_directory = aws-c-sdkutils + +[provide] +dependency_names = aws-c-sdkutils diff --git a/subprojects/packagefiles/aws-c-sdkutils/generate_tests.py b/subprojects/packagefiles/aws-c-sdkutils/generate_tests.py new file mode 100644 index 000000000..b6816209f --- /dev/null +++ b/subprojects/packagefiles/aws-c-sdkutils/generate_tests.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +import sys + +# Usage: generate_tests.py +if __name__ == '__main__': + with open(sys.argv[1], 'r') as test_names: + tests = [line.strip() for line in test_names if line.strip()] + with open(sys.argv[2], 'w') as out: + out.write('/* Auto-generated file, do not edit */\n\n#include \n\n') + for name in tests: + out.write(f'extern int {name}(int argc, char **argv);\n') + out.write('\n') + out.write('int main(int argc, char **argv) {\n') + for name in tests: + out.write(f' if (strcmp(argv[1], "{name}") == 0) return {name}(argc, argv);\n') + out.write(' return 0;\n') + out.write('}\n') diff --git a/subprojects/packagefiles/aws-c-sdkutils/include/meson.build b/subprojects/packagefiles/aws-c-sdkutils/include/meson.build new file mode 100644 index 000000000..c5fe4b754 --- /dev/null +++ b/subprojects/packagefiles/aws-c-sdkutils/include/meson.build @@ -0,0 +1,9 @@ +install_headers( + 'aws/sdkutils/aws_profile.h', + 'aws/sdkutils/endpoints_rule_engine.h', + 'aws/sdkutils/exports.h', + 'aws/sdkutils/partitions.h', + 'aws/sdkutils/resource_name.h', + 'aws/sdkutils/sdkutils.h', + preserve_path: true, +) diff --git a/subprojects/packagefiles/aws-c-sdkutils/meson.build b/subprojects/packagefiles/aws-c-sdkutils/meson.build new file mode 100644 index 000000000..d55fb17a2 --- /dev/null +++ b/subprojects/packagefiles/aws-c-sdkutils/meson.build @@ -0,0 +1,92 @@ +project( + 'aws-c-sdkutils', + 'c', + version: '0.2.4', + license: 'Apache-2.0', + meson_version: '>=0.64.0', +) + +tests_opt = get_option('tests').disable_auto_if(meson.is_subproject()) + +pkg = import('pkgconfig') +fs = import('fs') + +aws_c_common_dep = dependency('aws-c-common') + +deps = [aws_c_common_dep] + +src = files( + 'source/aws_profile.c', + 'source/endpoints_regex.c', + 'source/endpoints_rule_engine.c', + 'source/endpoints_ruleset.c', + 'source/endpoints_standard_lib.c', + 'source/endpoints_types_impl.c', + 'source/endpoints_util.c', + 'source/partitions.c', + 'source/resource_name.c', + 'source/sdkutils.c', +) + +subdir('include') + +inc = include_directories('include') + +c_args = ['-DAWS_SDKUTILS_EXPORTS=1'] +public_c_args = [] +if ( + get_option('default_library') == 'shared' + and host_machine.system() == 'windows' +) or host_machine.system() != 'windows' + public_c_args += ['-DAWS_SDKUTILS_USE_IMPORT_EXPORT=1'] +endif + +libaws_c_sdkutils = library( + 'aws-c-sdkutils', + src, + c_args: c_args + public_c_args, + include_directories: inc, + dependencies: deps, + install: true, + version: meson.project_version(), + gnu_symbol_visibility: 'hidden', +) + +aws_c_sdkutils_dep = declare_dependency( + include_directories: inc, + link_with: libaws_c_sdkutils, + dependencies: deps, + compile_args: public_c_args, +) + +meson.override_dependency('aws-c-sdkutils', aws_c_sdkutils_dep) + +pkg.generate( + libaws_c_sdkutils, + extra_cflags: public_c_args, + description: 'C99 library implementing AWS SDK specific utilities. Includes utilities for ARN parsing, reading AWS profiles, etc...', +) + +generate_tests = find_program( + 'generate_tests.py', + required: tests_opt, +) +run_test = find_program( + 'run_test.py', + required: tests_opt, +) + +if generate_tests.found() and run_test.found() + # aws-c-sdkutils uses an obscure cmake feature `create_test_sourcelist` to generate test harnesses + # this is a best effort approximation of that behavior + test_harness_src = custom_target( + 'generate_test_harness', + input: 'tests.txt', + output: 'test_harness.c', + command: [generate_tests, '@INPUT@', '@OUTPUT@'], + ) + + names = fs.read('tests.txt').split('\n') + + subdir('tests') +endif diff --git a/subprojects/packagefiles/aws-c-sdkutils/meson_options.txt b/subprojects/packagefiles/aws-c-sdkutils/meson_options.txt new file mode 100644 index 000000000..ab7eff4fb --- /dev/null +++ b/subprojects/packagefiles/aws-c-sdkutils/meson_options.txt @@ -0,0 +1,5 @@ +option( + 'tests', + type: 'feature', + description: 'Build unit tests', +) diff --git a/subprojects/packagefiles/aws-c-sdkutils/run_test.py b/subprojects/packagefiles/aws-c-sdkutils/run_test.py new file mode 100644 index 000000000..1246f7446 --- /dev/null +++ b/subprojects/packagefiles/aws-c-sdkutils/run_test.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import sys +import os + +# Usage: run_test.py [args...] +if __name__ == '__main__': + test_exe = sys.argv[1] + test_args = sys.argv[2:] + import subprocess + result = subprocess.run([test_exe] + test_args, cwd = os.getcwd()) + if result.returncode == 103: + result.returncode = 77 # Skip code for meson + sys.exit(result.returncode) diff --git a/subprojects/packagefiles/aws-c-sdkutils/tests.txt b/subprojects/packagefiles/aws-c-sdkutils/tests.txt new file mode 100644 index 000000000..0255a716d --- /dev/null +++ b/subprojects/packagefiles/aws-c-sdkutils/tests.txt @@ -0,0 +1,87 @@ +sdkutils_library_test +aws_profile_early_property_parse_failure_test +aws_profile_missing_bracket_parse_failure_test +aws_profile_missing_assignment_parse_failure_test +aws_profile_missing_property_key_parse_failure_test +aws_profile_early_continuation_parse_failure_test +aws_profile_illegal_continuation1_parse_failure_test +aws_profile_illegal_continuation2_parse_failure_test +aws_profile_illegal_continuation3_parse_failure_test +aws_profile_continuation_reset_on_new_profile_parse_failure_test +aws_profile_empty_test +aws_profile_empty_profile_test +aws_profile_whitespace_empty_profile_test +aws_profile_tab_empty_profile_test +aws_profile_single_simple_property_profile_test +aws_profile_equal_containing_property_profile_test +aws_profile_unicode_containing_property_profile_test +aws_profile_multiple_property_profile_test +aws_profile_trimmable_property_profile_test +aws_profile_empty_property_profile_test +aws_profile_multiple_empty_profile_test +aws_profile_multiple_profile_test +aws_profile_multiple_sections +aws_profile_sections_in_credentials_test +aws_profile_sso_session_without_name_test +aws_profile_services_invalid_prefix_test +aws_profile_blank_lines_ignored_test +aws_profile_pound_comments_ignored_test +aws_profile_semicolon_comments_ignored_test +aws_profile_mixed_comments_ignored_test +aws_profile_empty_comments_ignored_test +aws_profile_profile_adjacent_comment_test +aws_profile_value_adjacent_comment_test +aws_profile_continued_property_value_test +aws_profile_multiline_continued_property_value_test +aws_profile_continued_property_value_trim_test +aws_profile_continued_property_value_pound_comment_test +aws_profile_continued_property_value_semicolon_comment_test +aws_profile_duplicate_profiles_merge_test +aws_profile_duplicate_properties_last_property_value_test +aws_profile_duplicate_profiles_last_property_value_test +aws_profile_duplicate_default_profiles_property_resolution1_test +aws_profile_duplicate_default_profiles_property_resolution2_test +aws_profile_invalid_profile_names_merge_test +aws_profile_invalid_property_names_ignored_test +aws_profile_all_valid_profile_characters_test +aws_profile_all_valid_property_characters_test +aws_profile_basic_sub_property_test +aws_profile_empty_sub_property_test +aws_profile_invalid_sub_property_name_test +aws_profile_sub_property_blank_line_test +aws_profile_basic_duplicate_merge_test +aws_profile_mixed_prefix_default_test +aws_profile_override_duplicate_merge_test +aws_profile_no_prefix_nondefault_test +aws_profile_prefix_credentials_test +parse_resource_name_test +parse_resource_name_failures_test +resource_name_tostring_test +resource_name_tostring_failure_test +resource_name_length_test +parse_ruleset_from_string +test_endpoints_aws_region +test_endpoints_default_values +test_endpoints_eventbridge +test_endpoints_fns +test_endpoints_get_attr_type_inference +test_endpoints_headers +test_endpoints_is_virtual_hostable_s3_bucket +test_endpoints_region_override +test_endpoints_minimal_ruleset +test_endpoints_parse_arn +test_endpoints_parse_url +test_endpoints_partition_fn +test_endpoints_substring +test_endpoints_uri_encode +test_endpoints_valid_hostlabel +test_endpoints_condition_mem_clean_up +test_endpoints_custom +test_endpoints_string_array +test_endpoints_malformed_no_required_default +test_endpoints_malformed_regex +endpoints_uri_normalize_path +endpoints_byte_buf_init_from_resolved_templated_string +endpoints_regex_aws_region_matches +endpoints_regex_iso_region_matches +endpoints_regex_misc_validation \ No newline at end of file diff --git a/subprojects/packagefiles/aws-c-sdkutils/tests/meson.build b/subprojects/packagefiles/aws-c-sdkutils/tests/meson.build new file mode 100644 index 000000000..bc077d901 --- /dev/null +++ b/subprojects/packagefiles/aws-c-sdkutils/tests/meson.build @@ -0,0 +1,50 @@ +test_src = files( + 'aws_profile_parser_tests.c', + 'aws_profile_tests.c', + 'endpoints_regex_tests.c', + 'endpoints_rule_engine_tests.c', + 'endpoints_util_tests.c', + 'resource_name_tests.c', + 'sdkutils_test.c', +) + +libtestcases = static_library( + 'aws_c_sdkutils_testcases', + test_src, + dependencies: [aws_c_sdkutils_dep], + c_args: ['-DAWS_UNSTABLE_TESTING_API=1'], + include_directories: inc, + build_by_default: false, +) + +test_harness = executable( + 'aws-c-sdkutils-tests', + test_harness_src, + dependencies: [aws_c_sdkutils_dep], + link_with: [libtestcases], + c_args: ['-DAWS_UNSTABLE_TESTING_API=1'], + include_directories: inc, + build_by_default: false, +) + +# aws-c-commons test harness has some very unfortunate behaviour on windows +# where it changes the working directory to the test executable's directory before running the test, +# so we need to copy all the test resources to the build directory or the tests cant find them. +# see https://github.com/awslabs/aws-c-common/blob/main/include/aws/testing/aws_test_harness.h#L407-L416 +copied = [] + +subdir('resources/malformed-rules') +subdir('resources/test-cases') +subdir('resources/valid-rules') +subdir('resources') + +foreach name : names + test( + name, + run_test, + args: [test_harness.full_path(), name], + workdir: meson.current_build_dir() / 'resources', + timeout: 600, + depends: [test_harness, copied], + ) +endforeach diff --git a/subprojects/packagefiles/aws-c-sdkutils/tests/resources/malformed-rules/meson.build b/subprojects/packagefiles/aws-c-sdkutils/tests/resources/malformed-rules/meson.build new file mode 100644 index 000000000..3cc086156 --- /dev/null +++ b/subprojects/packagefiles/aws-c-sdkutils/tests/resources/malformed-rules/meson.build @@ -0,0 +1,7 @@ +resources = files( + 'no_default_on_required.json', +) + +foreach name : resources + copied += fs.copyfile(name) +endforeach diff --git a/subprojects/packagefiles/aws-c-sdkutils/tests/resources/meson.build b/subprojects/packagefiles/aws-c-sdkutils/tests/resources/meson.build new file mode 100644 index 000000000..c84cad82a --- /dev/null +++ b/subprojects/packagefiles/aws-c-sdkutils/tests/resources/meson.build @@ -0,0 +1,20 @@ +resources = files( + 'partitions.json', + 'sample_partitions.json', + 'sample_partitions_bad_regex.json', + 'sample_ruleset.json', +) + +foreach name : resources + copied += fs.copyfile(name) +endforeach + +test_harness = executable( + 'aws-c-sdkutils-tests', + test_harness_src, + dependencies: [aws_c_sdkutils_dep], + link_with: [libtestcases], + c_args: ['-DAWS_UNSTABLE_TESTING_API=1'], + include_directories: inc, + build_by_default: false, +) diff --git a/subprojects/packagefiles/aws-c-sdkutils/tests/resources/test-cases/meson.build b/subprojects/packagefiles/aws-c-sdkutils/tests/resources/test-cases/meson.build new file mode 100644 index 000000000..3d9376fb2 --- /dev/null +++ b/subprojects/packagefiles/aws-c-sdkutils/tests/resources/test-cases/meson.build @@ -0,0 +1,22 @@ +resources = files( + 'aws-region.json', + 'custom_object_condition.json', + 'custom_partition.json', + 'default-values.json', + 'eventbridge.json', + 'fns.json', + 'headers.json', + 'is-virtual-hostable-s3-bucket.json', + 'local-region-override.json', + 'parse-arn.json', + 'parse-url.json', + 'partition-fn.json', + 'string_array.json', + 'substring.json', + 'uri-encode.json', + 'valid-hostlabel.json', +) + +foreach name : resources + copied += fs.copyfile(name) +endforeach diff --git a/subprojects/packagefiles/aws-c-sdkutils/tests/resources/valid-rules/meson.build b/subprojects/packagefiles/aws-c-sdkutils/tests/resources/valid-rules/meson.build new file mode 100644 index 000000000..b71ed0cca --- /dev/null +++ b/subprojects/packagefiles/aws-c-sdkutils/tests/resources/valid-rules/meson.build @@ -0,0 +1,25 @@ +resources = files( + 'aws-region.json', + 'custom_object_condition.json', + 'custom_partition.json', + 'default-values.json', + 'deprecated-param.json', + 'eventbridge.json', + 'fns.json', + 'get-attr-type-inference.json', + 'headers.json', + 'is-virtual-hostable-s3-bucket.json', + 'minimal-ruleset.json', + 'parse-arn.json', + 'parse-url.json', + 'partition-fn.json', + 'region-override.json', + 'string_array.json', + 'substring.json', + 'uri-encode.json', + 'valid-hostlabel.json', +) + +foreach name : resources + copied += fs.copyfile(name) +endforeach diff --git a/tools/sanity_checks.py b/tools/sanity_checks.py index 066cbfc2d..c3006883a 100755 --- a/tools/sanity_checks.py +++ b/tools/sanity_checks.py @@ -52,6 +52,11 @@ 'generate_tests.py', 'run_test.py', }, + 'aws-c-sdkutils': { + 'tests.txt', + 'generate_tests.py', + 'run_test.py', + }, 'box2d': { 'doctest.h' },