diff --git a/cpp/.gitignore b/cpp/.gitignore index 21c144c5685..52f25f0968e 100644 --- a/cpp/.gitignore +++ b/cpp/.gitignore @@ -1,4 +1,5 @@ build/ cmake-build*/ .vs/ -build_tests \ No newline at end of file +build_tests +CMakeSettings.json \ No newline at end of file diff --git a/cpp/example_code/aurora/getting_started_with_db_clusters.cpp b/cpp/example_code/aurora/getting_started_with_db_clusters.cpp index a5f57fde003..7aee4246cb5 100644 --- a/cpp/example_code/aurora/getting_started_with_db_clusters.cpp +++ b/cpp/example_code/aurora/getting_started_with_db_clusters.cpp @@ -767,8 +767,6 @@ bool AwsDoc::Aurora::describeDBCluster(const Aws::String &dbClusterIdentifier, if (outcome.IsSuccess()) { clusterResult = outcome.GetResult().GetDBClusters()[0]; } - // This example does not log an error if the DB cluster does not exist. - // Instead, it returns false. else if (outcome.GetError().GetErrorType() != Aws::RDS::RDSErrors::D_B_CLUSTER_NOT_FOUND_FAULT) { result = false; @@ -776,6 +774,11 @@ bool AwsDoc::Aurora::describeDBCluster(const Aws::String &dbClusterIdentifier, << outcome.GetError().GetMessage() << std::endl; } + // This example does not log an error if the DB cluster does not exist. + // Instead, clusterResult is set to empty. + else { + clusterResult = Aws::RDS::Model::DBCluster(); + } return result; @@ -902,8 +905,6 @@ bool AwsDoc::Aurora::describeDBInstance(const Aws::String &dbInstanceIdentifier, if (outcome.IsSuccess()) { instanceResult = outcome.GetResult().GetDBInstances()[0]; } - // This example does not log an error if the DB instance does not exist. - // Instead, it returns false. else if (outcome.GetError().GetErrorType() != Aws::RDS::RDSErrors::D_B_INSTANCE_NOT_FOUND_FAULT) { result = false; @@ -911,6 +912,11 @@ bool AwsDoc::Aurora::describeDBInstance(const Aws::String &dbInstanceIdentifier, << outcome.GetError().GetMessage() << std::endl; } + // This example does not log an error if the DB instance does not exist. + // Instead, instanceResult is set to empty. + else { + instanceResult = Aws::RDS::Model::DBInstance(); + } return result; } diff --git a/cpp/example_code/iam/CMakeLists.txt b/cpp/example_code/iam/CMakeLists.txt index fc21bd2a540..26c5585146b 100644 --- a/cpp/example_code/iam/CMakeLists.txt +++ b/cpp/example_code/iam/CMakeLists.txt @@ -10,41 +10,33 @@ set(SERVICE_COMPONENTS iam s3 sts) # Set this project's name. project("${SERVICE_NAME}-examples") -# Set the location of where Windows can find the installed libraries of the SDK. -if(MSVC) - string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") - list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() - # Set the C++ standard to use to build this target. set(CMAKE_CXX_STANDARD 11) -# Enable CTest for testing these code examples. -if(BUILD_TESTS) - include(CTest) -endif() - # Build shared libraries by default. -if(NOT DEFINED BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON) +set(BUILD_SHARED_LIBS ON) + +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + +# Set the location of where Windows can find the installed libraries of the SDK. +if(WINDOWS_BUILD) + string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") + list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) endif() # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in windows to copy dlls. - list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS}) +if(WINDOWS_BUILD) + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) -endif() + # set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this + # and set the proper subdirectory to the executables' location. + AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR}) + endif() # AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example, # you can limit files to one action. @@ -79,6 +71,6 @@ endforeach() if(BUILD_TESTS) - add_subdirectory(gtests) + add_subdirectory(tests) endif() diff --git a/cpp/example_code/iam/iam_create_user_assume_role_scenario.cpp b/cpp/example_code/iam/iam_create_user_assume_role_scenario.cpp index 11bfb909259..2742e400ab2 100644 --- a/cpp/example_code/iam/iam_create_user_assume_role_scenario.cpp +++ b/cpp/example_code/iam/iam_create_user_assume_role_scenario.cpp @@ -55,6 +55,7 @@ // snippet-start:[cpp.example_code.iam.Scenario_CreateUserAssumeRole] namespace AwsDoc { namespace IAM { + //! Cleanup by deleting created entities. /*! \sa DeleteCreatedEntities @@ -69,6 +70,8 @@ namespace AwsDoc { const Aws::IAM::Model::Policy &policy); } + static const int LIST_BUCKETS_WAIT_SEC = 20; + static const char ALLOCATION_TAG[] = "example_code"; } @@ -320,7 +323,7 @@ bool AwsDoc::IAM::iamCreateUserAssumeRoleScenario( // 7. List objects in the bucket (this should succeed). // Repeatedly call ListBuckets, because there is often a delay // before the policy with ListBucket permissions has been applied to the role. - // Repeat at most 20 times when access is denied. + // Repeat at most LIST_BUCKETS_WAIT_SEC times when access is denied. while (true) { Aws::S3::S3Client s3Client( Aws::Auth::AWSCredentials(credentials.GetAccessKeyId(), @@ -330,10 +333,10 @@ bool AwsDoc::IAM::iamCreateUserAssumeRoleScenario( clientConfig); Aws::S3::Model::ListBucketsOutcome listBucketsOutcome = s3Client.ListBuckets(); if (!listBucketsOutcome.IsSuccess()) { - if ((count > 20) || + if ((count > LIST_BUCKETS_WAIT_SEC) || listBucketsOutcome.GetError().GetErrorType() != Aws::S3::S3Errors::ACCESS_DENIED) { - std::cerr << "Could not lists buckets after 20 seconds. " << + std::cerr << "Could not lists buckets after " << LIST_BUCKETS_WAIT_SEC << " seconds. " << listBucketsOutcome.GetError().GetMessage() << std::endl; DeleteCreatedEntities(client, role, user, policy); return false; diff --git a/cpp/example_code/iam/gtests/CMakeLists.txt b/cpp/example_code/iam/tests/CMakeLists.txt similarity index 83% rename from cpp/example_code/iam/gtests/CMakeLists.txt rename to cpp/example_code/iam/tests/CMakeLists.txt index 72c25bf682e..fcd57ec0313 100644 --- a/cpp/example_code/iam/gtests/CMakeLists.txt +++ b/cpp/example_code/iam/tests/CMakeLists.txt @@ -17,6 +17,8 @@ set(CMAKE_CXX_STANDARD 14) # Build shared libraries by default. set(BUILD_SHARED_LIBS ON) +enable_testing() + find_package(GTest) if(NOT GTest_FOUND) @@ -32,8 +34,12 @@ if(NOT GTest_FOUND) FetchContent_MakeAvailable(googletest) endif() + +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + # Set the location for Windows to find the installed libraries of the SDK. -if(MSVC) +if(WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) endif() @@ -47,15 +53,15 @@ add_executable( # If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, # and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. +if(WINDOWS_BUILD) + # set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this + # and set the proper subdirectory to the executables' location. # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES + CURRENT_TARGET_AWS_DEPENDENCIES "" - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR} ) add_custom_command( @@ -63,10 +69,11 @@ if(MSVC AND BUILD_SHARED_LIBS) ${CURRENT_TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${CMAKE_BUILD_TYPE}/gtest.dll - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}${BIN_SUB_DIR}/gtest.dll + ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR} ) - endif() +endif() + # GTEST_SOURCE_FILES can be defined in the command line to limit the files in a build. For example, # you can limit files to one action. diff --git a/cpp/example_code/iam/gtests/gtest_access_key_last_used.cpp b/cpp/example_code/iam/tests/gtest_access_key_last_used.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_access_key_last_used.cpp rename to cpp/example_code/iam/tests/gtest_access_key_last_used.cpp diff --git a/cpp/example_code/iam/gtests/gtest_attach_role_policy.cpp b/cpp/example_code/iam/tests/gtest_attach_role_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_attach_role_policy.cpp rename to cpp/example_code/iam/tests/gtest_attach_role_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_create_access_key.cpp b/cpp/example_code/iam/tests/gtest_create_access_key.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_create_access_key.cpp rename to cpp/example_code/iam/tests/gtest_create_access_key.cpp diff --git a/cpp/example_code/iam/gtests/gtest_create_account_alias.cpp b/cpp/example_code/iam/tests/gtest_create_account_alias.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_create_account_alias.cpp rename to cpp/example_code/iam/tests/gtest_create_account_alias.cpp diff --git a/cpp/example_code/iam/gtests/gtest_create_policy.cpp b/cpp/example_code/iam/tests/gtest_create_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_create_policy.cpp rename to cpp/example_code/iam/tests/gtest_create_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_create_role.cpp b/cpp/example_code/iam/tests/gtest_create_role.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_create_role.cpp rename to cpp/example_code/iam/tests/gtest_create_role.cpp diff --git a/cpp/example_code/iam/gtests/gtest_create_user.cpp b/cpp/example_code/iam/tests/gtest_create_user.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_create_user.cpp rename to cpp/example_code/iam/tests/gtest_create_user.cpp diff --git a/cpp/example_code/iam/gtests/gtest_delete_access_key.cpp b/cpp/example_code/iam/tests/gtest_delete_access_key.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_delete_access_key.cpp rename to cpp/example_code/iam/tests/gtest_delete_access_key.cpp diff --git a/cpp/example_code/iam/gtests/gtest_delete_account_alias.cpp b/cpp/example_code/iam/tests/gtest_delete_account_alias.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_delete_account_alias.cpp rename to cpp/example_code/iam/tests/gtest_delete_account_alias.cpp diff --git a/cpp/example_code/iam/gtests/gtest_delete_policy.cpp b/cpp/example_code/iam/tests/gtest_delete_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_delete_policy.cpp rename to cpp/example_code/iam/tests/gtest_delete_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_delete_server_certificate.cpp b/cpp/example_code/iam/tests/gtest_delete_server_certificate.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_delete_server_certificate.cpp rename to cpp/example_code/iam/tests/gtest_delete_server_certificate.cpp diff --git a/cpp/example_code/iam/gtests/gtest_delete_user.cpp b/cpp/example_code/iam/tests/gtest_delete_user.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_delete_user.cpp rename to cpp/example_code/iam/tests/gtest_delete_user.cpp diff --git a/cpp/example_code/iam/gtests/gtest_detach_role_policy.cpp b/cpp/example_code/iam/tests/gtest_detach_role_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_detach_role_policy.cpp rename to cpp/example_code/iam/tests/gtest_detach_role_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_get_policy.cpp b/cpp/example_code/iam/tests/gtest_get_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_get_policy.cpp rename to cpp/example_code/iam/tests/gtest_get_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_get_server_certificate.cpp b/cpp/example_code/iam/tests/gtest_get_server_certificate.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_get_server_certificate.cpp rename to cpp/example_code/iam/tests/gtest_get_server_certificate.cpp diff --git a/cpp/example_code/iam/gtests/gtest_iam_create_user_assume_role_scenario.cpp b/cpp/example_code/iam/tests/gtest_iam_create_user_assume_role_scenario.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_iam_create_user_assume_role_scenario.cpp rename to cpp/example_code/iam/tests/gtest_iam_create_user_assume_role_scenario.cpp diff --git a/cpp/example_code/iam/gtests/gtest_list_access_keys.cpp b/cpp/example_code/iam/tests/gtest_list_access_keys.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_list_access_keys.cpp rename to cpp/example_code/iam/tests/gtest_list_access_keys.cpp diff --git a/cpp/example_code/iam/gtests/gtest_list_account_aliases.cpp b/cpp/example_code/iam/tests/gtest_list_account_aliases.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_list_account_aliases.cpp rename to cpp/example_code/iam/tests/gtest_list_account_aliases.cpp diff --git a/cpp/example_code/iam/gtests/gtest_list_policies.cpp b/cpp/example_code/iam/tests/gtest_list_policies.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_list_policies.cpp rename to cpp/example_code/iam/tests/gtest_list_policies.cpp diff --git a/cpp/example_code/iam/gtests/gtest_list_server_certificates.cpp b/cpp/example_code/iam/tests/gtest_list_server_certificates.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_list_server_certificates.cpp rename to cpp/example_code/iam/tests/gtest_list_server_certificates.cpp diff --git a/cpp/example_code/iam/gtests/gtest_list_users.cpp b/cpp/example_code/iam/tests/gtest_list_users.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_list_users.cpp rename to cpp/example_code/iam/tests/gtest_list_users.cpp diff --git a/cpp/example_code/iam/gtests/gtest_put_role_policy.cpp b/cpp/example_code/iam/tests/gtest_put_role_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_put_role_policy.cpp rename to cpp/example_code/iam/tests/gtest_put_role_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_update_access_key.cpp b/cpp/example_code/iam/tests/gtest_update_access_key.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_update_access_key.cpp rename to cpp/example_code/iam/tests/gtest_update_access_key.cpp diff --git a/cpp/example_code/iam/gtests/gtest_update_server_certificate.cpp b/cpp/example_code/iam/tests/gtest_update_server_certificate.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_update_server_certificate.cpp rename to cpp/example_code/iam/tests/gtest_update_server_certificate.cpp diff --git a/cpp/example_code/iam/gtests/gtest_update_user.cpp b/cpp/example_code/iam/tests/gtest_update_user.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_update_user.cpp rename to cpp/example_code/iam/tests/gtest_update_user.cpp diff --git a/cpp/example_code/iam/gtests/iam_gtests.cpp b/cpp/example_code/iam/tests/iam_gtests.cpp similarity index 100% rename from cpp/example_code/iam/gtests/iam_gtests.cpp rename to cpp/example_code/iam/tests/iam_gtests.cpp diff --git a/cpp/example_code/iam/gtests/iam_gtests.h b/cpp/example_code/iam/tests/iam_gtests.h similarity index 100% rename from cpp/example_code/iam/gtests/iam_gtests.h rename to cpp/example_code/iam/tests/iam_gtests.h diff --git a/cpp/example_code/iam/gtests/test_main.cpp b/cpp/example_code/iam/tests/test_main.cpp similarity index 100% rename from cpp/example_code/iam/gtests/test_main.cpp rename to cpp/example_code/iam/tests/test_main.cpp diff --git a/cpp/example_code/rds/getting_started_with_db_instances.cpp b/cpp/example_code/rds/getting_started_with_db_instances.cpp index 2bd19117521..38ddf17b377 100644 --- a/cpp/example_code/rds/getting_started_with_db_instances.cpp +++ b/cpp/example_code/rds/getting_started_with_db_instances.cpp @@ -758,8 +758,6 @@ bool AwsDoc::RDS::describeDBInstance(const Aws::String &dbInstanceIdentifier, if (outcome.IsSuccess()) { instanceResult = outcome.GetResult().GetDBInstances()[0]; } - // This example does not log an error if the DB instance does not exist. - // Instead, it returns false. else if (outcome.GetError().GetErrorType() != Aws::RDS::RDSErrors::D_B_INSTANCE_NOT_FOUND_FAULT) { result = false; @@ -767,6 +765,11 @@ bool AwsDoc::RDS::describeDBInstance(const Aws::String &dbInstanceIdentifier, << outcome.GetError().GetMessage() << std::endl; } + // This example does not log an error if the DB instance does not exist. + // Instead, instanceResult is set to empty. + else { + instanceResult = Aws::RDS::Model::DBInstance(); + } return result; } diff --git a/cpp/example_code/s3/CMakeLists.txt b/cpp/example_code/s3/CMakeLists.txt index 4c5ee8804a0..a52d9d187f3 100644 --- a/cpp/example_code/s3/CMakeLists.txt +++ b/cpp/example_code/s3/CMakeLists.txt @@ -4,42 +4,39 @@ # Set the minimum required version of CMake for this project. cmake_minimum_required(VERSION 3.8) +set(SERVICE_NAME) +set(SERVICE_COMPONENTS s3 sts iam) + # Set this project's name. -project("s3-examples") +project("${SERVICE_NAME}-examples") -# Set the location of where Windows can find the installed libraries of the SDK. -if(MSVC) - string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") - list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() +# Build shared libraries by default. +set(BUILD_SHARED_LIBS ON) # Set the C++ standard to use to build this target. set(CMAKE_CXX_STANDARD 11) -# Enable CTest for testing these code examples. -if(BUILD_TESTS) - include(CTest) -endif() +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) -# Build shared libraries by default. -if(NOT BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON) +# Set the location of where Windows can find the installed libraries of the SDK. +if(WINDOWS_BUILD) + string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") + list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) endif() # Find the AWS SDK for C++ package. -find_package(AWSSDK REQUIRED COMPONENTS s3 sts iam) +find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) + -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in windows to copy dlls. +if(WINDOWS_BUILD) + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - list(APPEND SERVICE_LIST s3 sts iam) + # set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this + # and set the proper subdirectory to the executables' location. - AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) + AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR}) endif() # Add the code example-specific header files. diff --git a/cpp/example_code/s3/list_objects.cpp b/cpp/example_code/s3/list_objects.cpp index 10a5abe9124..8f72be1d4d8 100644 --- a/cpp/example_code/s3/list_objects.cpp +++ b/cpp/example_code/s3/list_objects.cpp @@ -78,7 +78,7 @@ int main() //TODO(user): Name of a bucket in your account. //The bucket must have at least one object in it. One way to achieve //this is to configure and run put_object.cpp's executable first. - const Aws::String bucket_name = "my-bucket-2f2730dd-0f5d-4dfa-b55d-8d36a3bfea39"; + const Aws::String bucket_name = ""; Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region in which the bucket was created (overrides config file). diff --git a/cpp/example_code/s3/tests/CMakeLists.txt b/cpp/example_code/s3/tests/CMakeLists.txt index de4335de35a..46922aab065 100644 --- a/cpp/example_code/s3/tests/CMakeLists.txt +++ b/cpp/example_code/s3/tests/CMakeLists.txt @@ -17,6 +17,8 @@ set(CMAKE_CXX_STANDARD 14) # Build shared libraries by default. set(BUILD_SHARED_LIBS ON) +enable_testing() + find_package(GTest) if(NOT GTest_FOUND) @@ -33,8 +35,11 @@ if(NOT GTest_FOUND) endif() +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + # Set the location for Windows to find the installed libraries of the SDK. -if(MSVC) +if(WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) endif() @@ -46,28 +51,26 @@ add_executable( ${CURRENT_TARGET} ) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) - - set(CMAKE_BUILD_TYPE Debug) # Explicitly set this to support library copying and test automation. +if(WINDOWS_BUILD) + # set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this + # and set the proper subdirectory to the executables' location. + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES + CURRENT_TARGET_AWS_DEPENDENCIES "" - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - ) + ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR} + ) add_custom_command( TARGET ${CURRENT_TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${CMAKE_BUILD_TYPE}/gtest.dll - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}${BIN_SUB_DIR}/gtest.dll + ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR} ) - endif() +endif() # GTEST_SOURCE_FILES can be defined in the command line to limit the files in a build. For example, # you can limit files to one action. diff --git a/cpp/example_code/sts/gtests/CMakeLists.txt b/cpp/example_code/sts/tests/CMakeLists.txt similarity index 100% rename from cpp/example_code/sts/gtests/CMakeLists.txt rename to cpp/example_code/sts/tests/CMakeLists.txt diff --git a/cpp/example_code/sts/gtests/gtest_assume_role.cpp b/cpp/example_code/sts/tests/gtest_assume_role.cpp similarity index 100% rename from cpp/example_code/sts/gtests/gtest_assume_role.cpp rename to cpp/example_code/sts/tests/gtest_assume_role.cpp diff --git a/cpp/example_code/sts/gtests/sts_gtests.cpp b/cpp/example_code/sts/tests/sts_gtests.cpp similarity index 100% rename from cpp/example_code/sts/gtests/sts_gtests.cpp rename to cpp/example_code/sts/tests/sts_gtests.cpp diff --git a/cpp/example_code/sts/gtests/sts_gtests.h b/cpp/example_code/sts/tests/sts_gtests.h similarity index 100% rename from cpp/example_code/sts/gtests/sts_gtests.h rename to cpp/example_code/sts/tests/sts_gtests.h diff --git a/cpp/example_code/sts/gtests/test_main.cpp b/cpp/example_code/sts/tests/test_main.cpp similarity index 100% rename from cpp/example_code/sts/gtests/test_main.cpp rename to cpp/example_code/sts/tests/test_main.cpp diff --git a/cpp/run_automated_tests.py b/cpp/run_automated_tests.py index 668235b5c44..36096161225 100644 --- a/cpp/run_automated_tests.py +++ b/cpp/run_automated_tests.py @@ -18,6 +18,11 @@ # # 'python3 run_automated_tests.py -23 -s s3' # +# To enable parallel builds, the environment variable PARALLEL_BUILD can be set to a number. +# +# 'export PARALLEL_BUILD=$(nproc)' +# + import os @@ -27,6 +32,7 @@ import glob import re import datetime +import sys build_sub_dir = "build_tests" @@ -45,6 +51,8 @@ def build_cmake_tests(cmake_files, executable_pattern) : cmake_args = os.getenv("EXTRA_CMAKE_ARGS") + parallel_build = os.getenv("PARALLEL_BUILD") + for cmake_file in cmake_files : source_dir = os.path.dirname(cmake_file) module_build_dir = os.path.join(build_dir, source_dir) @@ -56,13 +64,21 @@ def build_cmake_tests(cmake_files, executable_pattern) : cmake_command.append(cmake_args) cmake_command.append(os.path.join(base_dir, source_dir)) + if sys.platform == "win32": + cmake_command.append('-DBIN_SUB_DIR=/Debug') + result_code = subprocess.call(cmake_command, shell=False) if result_code != 0 : print(f"Error with cmake for {source_dir}") has_error = True continue - result_code = subprocess.call(['cmake', '--build', '.'], shell=False) + if parallel_build is not None: + print("building parallel") + result_code = subprocess.call(['cmake', '--build', '.', '--parallel', f'{parallel_build}'], shell=False) + else: + result_code = subprocess.call(['cmake', '--build', '.'], shell=False) + if result_code != 0 : has_error = True continue