From 1d77bfa3867f98cf59beca149026a013668c06b7 Mon Sep 17 00:00:00 2001 From: "Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com)" Date: Tue, 2 Feb 2021 11:47:39 +0000 Subject: [PATCH] Add LLFIO_ENABLE_DEPENDENCY_SMOKE_TEST option for vcpkg. --- CMakeLists.txt | 27 ++++++++++++++-- cmake/QuickCppLibBootstrap.cmake | 4 ++- include/llfio/revision.hpp | 6 ++-- test-packaging/example.cpp | 53 +++++++++++++++----------------- 4 files changed, 55 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab59a446c..a83a4dd91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,8 @@ include(QuickCppLibUtils) include(QuickCppLibPolicies) option(LLFIO_USE_EXPERIMENTAL_SG14_STATUS_CODE "Whether to use SG14 status_code for failure handling" OFF) +option(LLFIO_ENABLE_DEPENDENCY_SMOKE_TEST "Whether to build executables which are smoke tests that LLFIO is fully working. Used by various package managers such as vcpkg." OFF) +set(UNIT_TESTS_CXX_VERSION "latest" CACHE STRING "The version of C++ to use in the header-only unit tests") ensure_git_subrepo("${CMAKE_CURRENT_SOURCE_DIR}/include/llfio/ntkernel-error-category/include" "https://github.com/ned14/ntkernel-error-category.git") @@ -66,8 +68,6 @@ if(WIN32) endif() endif() -set(UNIT_TESTS_CXX_VERSION "latest" CACHE STRING "The version of C++ to use in the header-only unit tests") - # Make the standard static and shared libraries, and if supported by this compiler, C++ modules # for both static and shared libraries as well. For the non-C++ module variants, makes the # interface headers into precompiled headers. Only builds all of them if this is the topmost @@ -161,7 +161,13 @@ if((MSVC AND MSVC_VERSION VERSION_GREATER_EQUAL 1923) OR APPLE) endif() endif() # Set the library dependencies this library has -all_link_libraries(PUBLIC quickcpplib::hl outcome::hl Threads::Threads $<$:rt>) +all_link_libraries(PUBLIC Threads::Threads $<$:rt>) +if(TARGET outcome::hl) + all_link_libraries(PUBLIC outcome::hl) +endif() +if(TARGET quickcpplib::hl) + all_link_libraries(PUBLIC quickcpplib::hl) +endif() # Set the system dependencies this library has include(CheckCXXSourceCompiles) @@ -390,6 +396,21 @@ if(NOT PROJECT_IS_DEPENDENCY) endif() endif() +if(LLFIO_ENABLE_DEPENDENCY_SMOKE_TEST) + set(LLFIO_SMOKE_TESTS) + add_executable(llfio-dependency-smoke-test "test-packaging/example.cpp") + list(APPEND LLFIO_SMOKE_TESTS llfio-dependency-smoke-test) + foreach(target ${LLFIO_SMOKE_TESTS}) + target_link_libraries(${target} PRIVATE llfio::dl) + set_target_properties(${target} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + ) + add_test(NAME ${target} CONFIGURATIONS Debug Release RelWithDebInfo MinSizeRel + COMMAND $ --reporter junit --out $.junit.xml + ) + endforeach() +endif() + # Cache this library's auto scanned sources for later reuse include(QuickCppLibCacheLibrarySources) diff --git a/cmake/QuickCppLibBootstrap.cmake b/cmake/QuickCppLibBootstrap.cmake index 0094ad4fd..359c0eb7b 100644 --- a/cmake/QuickCppLibBootstrap.cmake +++ b/cmake/QuickCppLibBootstrap.cmake @@ -28,7 +28,7 @@ foreach(item ${CMAKE_MODULE_PATH}) set(quickcpplib_done ON) endif() endforeach() -if(DEFINED quickcpplib_DIR) +if(NOT quickcpplib_done AND quickcpplib_DIR) find_package(quickcpplib QUIET CONFIG) if(quickcpplib_FOUND) if(EXISTS "${quickcpplib_DIR}/share/cmakelib") @@ -53,6 +53,8 @@ if(NOT quickcpplib_done) set(CTEST_QUICKCPPLIB_SCRIPTS "${CMAKE_SOURCE_DIR}/../quickcpplib/scripts") # Copy latest version of myself into end user file(COPY "${CTEST_QUICKCPPLIB_SCRIPTS}/../cmake/QuickCppLibBootstrap.cmake" DESTINATION "${CMAKE_SOURCE_DIR}/cmake/") + elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/quickcpplib/repo/cmakelib") + set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/quickcpplib") elseif(CMAKE_BINARY_DIR) # Place into root binary directory, same place as where find_quickcpplib_library() puts dependencies. set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_BINARY_DIR}/quickcpplib") diff --git a/include/llfio/revision.hpp b/include/llfio/revision.hpp index c823736dc..b43c48587 100644 --- a/include/llfio/revision.hpp +++ b/include/llfio/revision.hpp @@ -1,4 +1,4 @@ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define LLFIO_PREVIOUS_COMMIT_REF 48ee8bae656cb5d53f38feb462caa53e1128b76d -#define LLFIO_PREVIOUS_COMMIT_DATE "2021-01-27 20:37:58 +00:00" -#define LLFIO_PREVIOUS_COMMIT_UNIQUE 48ee8bae +#define LLFIO_PREVIOUS_COMMIT_REF 669e0b45bbc60cf4d46a72559710d428f2863740 +#define LLFIO_PREVIOUS_COMMIT_DATE "2021-02-02 11:20:42 +00:00" +#define LLFIO_PREVIOUS_COMMIT_UNIQUE 669e0b45 diff --git a/test-packaging/example.cpp b/test-packaging/example.cpp index 5840d4df8..b64a98d21 100644 --- a/test-packaging/example.cpp +++ b/test-packaging/example.cpp @@ -24,37 +24,34 @@ Distributed under the Boost Software License, Version 1.0. #include -#include +#include int main() { - //! [file_entire_file1] namespace llfio = LLFIO_V2_NAMESPACE; - // Open the file for read - llfio::file_handle fh = llfio::file( // - {}, // path_handle to base directory - "foo" // path_view to path fragment relative to base directory - // default mode is read only - // default creation is open existing - // default caching is all - // default flags is none - ).value(); // If failed, throw a filesystem_error exception - - // Make a vector sized the current maximum extent of the file - std::vector buffer(fh.maximum_extent().value()); - - // Synchronous scatter read from file - llfio::file_handle::size_type bytesread = llfio::read( - fh, // handle to read from - 0, // offset - {{ buffer.data(), buffer.size() }} // Single scatter buffer of the vector - // default deadline is infinite - ).value(); // If failed, throw a filesystem_error exception - - // In case of racy truncation of file by third party to new length, adjust buffer to - // bytes actually read - buffer.resize(bytesread); - //! [file_entire_file1] - return 0; + auto r = []() -> llfio::result { + OUTCOME_TRY(auto fh, llfio::file_handle::temp_file()); + static const char *buffers[] = { "He", "llo", " world" }; + OUTCOME_TRY(fh.write(0, { { (const llfio::byte *) buffers[0], 2 }, { (const llfio::byte *) buffers[1], 3 }, { (const llfio::byte *) buffers[2], 6 } } )); + llfio::byte buffer[64]; + OUTCOME_TRY(auto read, fh.read(0, { {buffer, sizeof(buffer)} })); + if(read != 11) + { + std::cerr << "FAILURE: Did not read 11 bytes!" << std::endl; + return 1; + } + if(0 != memcmp(buffer, "Hello world", 11)) + { + std::cerr << "FAILURE: Did not read what was written!" << std::endl; + return 1; + } + return 0; + }(); + if(!r) + { + std::cerr << "ERROR: " << r.error().message().c_str() << std::endl; + return 1; + } + return r.value(); }