From ca406dd3498b70e6b49954b75f0728b094eac879 Mon Sep 17 00:00:00 2001 From: Maxim Samsonov Date: Sat, 23 Oct 2021 12:16:27 +0300 Subject: [PATCH] Finished integration into Ruby build Closed #31 Closed #39 Temporary fix for https://github.com/tamatebako/libdwarfs/issues/43 --- .github/workflows/ubuntu-build.yml | 51 +++-- CMakeLists.txt | 298 ++++++++++++++++------------- CMakeSettings.json | 17 +- README.md | 11 ++ include/tebako-common.h | 2 + include/tebako-io.h | 21 +- include/tebako-pch.h | 1 - patches/2.patch/version.cpp | 12 -- patches/2.patch/version.h | 16 -- src/tebako-io-helpers.cpp | 14 +- 10 files changed, 253 insertions(+), 190 deletions(-) delete mode 100644 patches/2.patch/version.cpp delete mode 100644 patches/2.patch/version.h diff --git a/.github/workflows/ubuntu-build.yml b/.github/workflows/ubuntu-build.yml index 9fa07353..8a3244a2 100644 --- a/.github/workflows/ubuntu-build.yml +++ b/.github/workflows/ubuntu-build.yml @@ -2,7 +2,7 @@ name: Ubuntu build on: push: - branches: [ master, issue-1 ] + branches: [ master ] paths-ignore: - 'docs/**' - '**.adoc' @@ -19,12 +19,12 @@ on: env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - BUILD_TYPE: Debug + BUILD_TYPE: Release # The folder for dwarfs and other dependenies DEPS: deps # GitHub dependencies' - INCBIN_TAG: 348e36b - DWARFS_TAG: 78401c3 + INCBIN_TAG: "348e36b" + DWARFS_TAG: "78fd324" jobs: Ubuntu-build: @@ -45,7 +45,7 @@ jobs: uses: actions/cache@v2 with: path: ${{github.workspace}}/${{env.DEPS}} - key: ${{ github.workflow }}-${{ hashFiles('key.txt') }}-v1 + key: ${{ github.workflow }}-${{ hashFiles('key.txt') }}-v2 - name: Install packages Ubuntu # Already installed: bison flex pkg-config @@ -59,7 +59,7 @@ jobs: libunwind-dev libdwarf-dev libelf-dev libfmt-dev libgoogle-glog-dev libgtest-dev - name: Configure - run: cmake -B ${{github.workspace}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + run: cmake -B ${{github.workspace}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - name: Build run: cmake --build ${{github.workspace}} --config ${{env.BUILD_TYPE}} @@ -67,18 +67,33 @@ jobs: - name: Unit tests run: make test - - name: Running pure "C" program, calling all C API redefines - run: ./wr-bin + - name: Check "C" interface bindings in statically linked program, check that tmp directory is cleaned upon shutdown + run: | + mkdir ${{github.workspace}}/t_dir + ls /tmp >> ${{github.workspace}}/t_dir/before + ./wr-bin + ls /tmp >> ${{github.workspace}}/t_dir/after + diff ${{github.workspace}}/t_dir/before ${{github.workspace}}/t_dir/after - - name: Running ldd to check that wr-bin has been linked statically + - name: Run ldd to check that wr-bin has been linked statically run: ldd wr-bin 2>&1 >/dev/null | grep -i 'not a dynamic executable' -# [TODO] -# - name: Checking that tmp dir has been cleaned -# run: | -# shopt -s nullglob -# numfiles=(/tmp/*) -# numfiles=${#numfiles[@]} -# echo $numfiles - - + - name: Install and verify installation folders + run: | + sudo cmake --install ${{github.workspace}} --prefix ${{github.workspace}}/install + test -f ${{github.workspace}}/install/bin/dwarfs || (echo "File ${{github.workspace}}/install/bin/dwarfs does not exist" && false) + test -f ${{github.workspace}}/install/bin/dwarfsck || (echo "File ${{github.workspace}}/install/bin/dwarfsck does not exist" && false) + test -f ${{github.workspace}}/install/bin/dwarfsextract || (echo "File ${{github.workspace}}/install/bin/dwarfsextract does not exist" && false) + test -f ${{github.workspace}}/install/bin/mkdwarfs || (echo "File ${{github.workspace}}/install/bin/mkdwarfs does not exist" && false) + test -f ${{github.workspace}}/install/lib/libdwarfs-wr.a || (echo "File ${{github.workspace}}/install/lib/libdwarfs-wr.a does not exist" && false) + test -f ${{github.workspace}}/install/lib/libdwarfs.a || (echo "File ${{github.workspace}}/install/lib/libdwarfs.a does not exist" && false) + test -f ${{github.workspace}}/install/lib/libfsst.a || (echo "File ${{github.workspace}}/install/lib/libfsst.a does not exist" && false) + test -f ${{github.workspace}}/install/lib/libfolly.a || (echo "File ${{github.workspace}}/install/lib/libfolly.a does not exist" && false) + test -f ${{github.workspace}}/install/lib/libmetadata_thrift.a || (echo "File ${{github.workspace}}/install/lib/libmetadata_thrift.a does not exist" && false) + test -f ${{github.workspace}}/install/lib/libthrift_light.a || (echo "File ${{github.workspace}}/install/lib/libthrift_light.a does not exist" && false) + test -f ${{github.workspace}}/install/lib/libxxhash.a || (echo "File ${{github.workspace}}/install/lib/libxxhash.a does not exist" && false) + test -f ${{github.workspace}}/install/lib/libzstd.a || (echo "File ${{github.workspace}}/install/lib/libzstd.a does not exist" && false) + test -f ${{github.workspace}}/install/lib/libarchive.a || (echo "File ${{github.workspace}}/install/lib/libarchive.a does not exist" && false) + test -f ${{github.workspace}}/install/include/tebako/tebako-defines.h || (echo "File ${{github.workspace}}/install/include/tebako/tebako-defines.h does not exist" && false) + test -f ${{github.workspace}}/install/include/tebako/tebako-io.h || (echo "File ${{github.workspace}}/install/include/tebako/tebako-io.h does not exist" && false) + diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a8667a8..9756ae3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,20 +30,32 @@ cmake_policy(SET CMP0048 NEW) project(libdwarfs-wr VERSION 0.1.0) +option(WITH_TESTS "Find Google test, install INCBIN, build test applications" ON) +# Visual Studio/Windows Subsystem for Linux (WSL) environment requires +# source tree to be placed to native Windows partiotion +# Native Windows partition does not support links +# So, two options are privided below: +# -- disable links tests: set WITH_LINK_TEST to OFF +# -- place test data to WSL native partition + +option(WITH_LINK_TESTS "Include tests for hard and symbolic links" ON) +option(USE_TEMP_FS "Place test data to WSL native partition" OFF) + include(ExternalProject) -include(FetchContent) -include(GoogleTest) -include(CTest) +include(GNUInstallDirs) include(${CMAKE_SOURCE_DIR}/cmake/def_ext_prj.cmake) -enable_testing() +if(${WITH_TESTS}) + include(GoogleTest) + include(CTest) + enable_testing() +endif(${WITH_TESTS}) set(Boost_USE_STATIC_LIBS ON) -set(BOOST_LINK_STATIC ON) +set(Boost_LINK_STATIC ON) set(USE_STATIC_DEPS_ON_UNIX ON) set(GFLAGS_SHARED OFF) - # Various locations for external projects set(DEPS ${CMAKE_CURRENT_SOURCE_DIR}/deps CACHE STRING "Dependencies' folder'") set(DEPS_INCLUDE_DIR ${DEPS}/include) @@ -54,20 +66,22 @@ set(DEPS_SBIN_DIR ${DEPS}/sbin) # ................................................................... # External projects -def_ext_prj_g(DWARFS "78401c3") -def_ext_prj_g(INCBIN "348e36b") +def_ext_prj_g(DWARFS "78fd324") +if(${WITH_TESTS}) + def_ext_prj_g(INCBIN "348e36b") +endif(${WITH_TESTS}) message("Collecting packages:") -message("incbin - " @${INCBIN_TAG} " at " ${INCBIN_SOURCE_DIR}) +if(${WITH_TESTS}) + message("incbin - " @${INCBIN_TAG} " at " ${INCBIN_SOURCE_DIR}) +endif(${WITH_TESTS}) message("dwarfs - " @${DWARFS_TAG} " at " ${DWARFS_SOURCE_DIR}) # ................................................................... # incbin -# ExternalProject_Add is used for incbin project since we do not need -# anything at configure step. We want to fetch some files before the -# build, that's it. -ExternalProject_Add(${INCBIN_PRJ} +if(${WITH_TESTS}) + ExternalProject_Add(${INCBIN_PRJ} PREFIX ${DEPS} GIT_REPOSITORY https://github.com/graphitemaster/incbin.git GIT_TAG ${INCBIN_TAG} @@ -75,46 +89,36 @@ ExternalProject_Add(${INCBIN_PRJ} CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" -) + ) # ................................................................... # Filesystem locations -# Visual Studio/Windows Subsystem for Linux (WSL) environment requires -# source tree to be placed to native Windows partiotion -# Native Windows partition does not support links -# So, two options are privided below: -# -- disable links tests: set WITH_LINK_TEST to OFF -# -- place test data to WSL native partition - -option(WITH_LINK_TESTS "Include tests for hard and symbolic links" ON) -option(USE_TEMP_FS "Place test data to WSL native partition" OFF) - # DATA_TEST_DIR folder contains raw data for filesystem tests + if(${USE_TEMP_FS}) + string(RANDOM LENGTH 10 TMPNM) + set(DATA_TEST_DIR "/tmp/${TMPNM}") + set(DATA_TEST_DIR_MSG "at '${DATA_TEST_DIR}'") + else() + set(DATA_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_filesystem) + set(DATA_TEST_DIR_MSG "") + endif() + + if (${WITH_LINK_TESTS}) + set(WLT "with link tests") + add_compile_definitions("WITH_LINK_TESTS") + else() + set(WLT "without link tests") + endif() -if(${USE_TEMP_FS}) - string(RANDOM LENGTH 10 TMPNM) - set(DATA_TEST_DIR "/tmp/${TMPNM}") - set(DATA_TEST_DIR_MSG "at '${DATA_TEST_DIR}'") -else() - set(DATA_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_filesystem) - set(DATA_TEST_DIR_MSG "") -endif() - - -if (${WITH_LINK_TESTS}) - set(WLT "with link tests") - add_compile_definitions("WITH_LINK_TESTS") -else() - set(WLT "without link tests") -endif() - -message("Using test data set ${WLT} from '${CMAKE_CURRENT_SOURCE_DIR}/tests/test_filesystem' ${DATA_TEST_DIR_MSG}") + message("Using test data set ${WLT} from '${CMAKE_CURRENT_SOURCE_DIR}/tests/test_filesystem' ${DATA_TEST_DIR_MSG}") # DATA_BIN_DIR folder is used to create packaged filesystem -set(DATA_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}) + set(DATA_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}) # DATA_BIN_FILE is packaged filesystem itself -set(DATA_BIN_FILE ${DATA_BIN_DIR}/fs.bin) + set(DATA_BIN_FILE ${DATA_BIN_DIR}/fs.bin) + +endif(${WITH_TESTS}) # ................................................................... @@ -136,17 +140,17 @@ set(__LIBZSTD "${DWARFS_BINARY_DIR}/zstd/build/cmake/lib/libzstd.a") set(__LIBARCHIVE "${DWARFS_BINARY_DIR}/libarchive/lib/libarchive.a") ExternalProject_Add(${DWARFS_PRJ} - PREFIX ${DEPS} - GIT_REPOSITORY https://github.com/tamatebako/dwarfs.git - GIT_TAG ${DWARFS_TAG} - PATCH_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/patches/2.patch/version.cpp ${DEPS}/src/_dwarfs/src/dwarfs - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/patches/2.patch/version.h ${DEPS}/src/_dwarfs/include/dwarfs - UPDATE_COMMAND "" - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${DEPS} -DSTATIC_BUILD_DO_NOT_USE:BOOL=ON - SOURCE_DIR ${DWARFS_SOURCE_DIR} - BINARY_DIR ${DWARFS_BINARY_DIR} - BUILD_BYPRODUCTS ${__LIBDWARFS} ${__LIBFSST} ${__LIBFOLLY} ${__LIBT_METADATA} - ${__LIBT_LIGHT} ${__LIBXXHASH} ${__LIBZSTD} ${__LIBARCHIVE} + PREFIX ${DEPS} + GIT_REPOSITORY https://github.com/tamatebako/dwarfs.git + GIT_TAG ${DWARFS_TAG} +# This patch fixes version.cmake logic so that it works correctly not only for topmost project but for embedded project as well + PATCH_COMMAND sed -i "s/COMMAND git/COMMAND \${CMAKE_COMMAND} -E chdir \${CMAKE_CURRENT_SOURCE_DIR} git/g" ${DWARFS_SOURCE_DIR}/cmake/version.cmake || echo "Never mind" + UPDATE_COMMAND "" + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${DEPS} -DSTATIC_BUILD_DO_NOT_USE:BOOL=ON + SOURCE_DIR ${DWARFS_SOURCE_DIR} + BINARY_DIR ${DWARFS_BINARY_DIR} + BUILD_BYPRODUCTS ${__LIBDWARFS} ${__LIBFSST} ${__LIBFOLLY} ${__LIBT_METADATA} + ${__LIBT_LIGHT} ${__LIBXXHASH} ${__LIBZSTD} ${__LIBARCHIVE} ) # ................................................................... @@ -158,9 +162,6 @@ configure_file( @ONLY ) -add_compile_options(-fdiagnostics-color=always) -#[TODO] -#add_link_options(-static -static-libgcc) add_link_options(-static) set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2 -g") set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O2 -g") @@ -203,15 +204,18 @@ add_dependencies(dwarfs-wr ${DWARFS_PRJ}) # ................................................................... # Tests -find_package(PkgConfig REQUIRED) -pkg_search_module(GTEST gtest_main) +if(${WITH_TESTS}) + find_package(PkgConfig REQUIRED) + pkg_search_module(GTEST gtest_main) +# This code may be adopted if we want to build gtest locally. No need so far. +#include(FetchContent) #FetchContent_Declare( # googletest # Specify the commit you depend on and update it regularly. # URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip #) -# For Windows: Prevent overriding the parent project's compiler/linker settings +# For Windows: Prevent overwriting the parent project's compiler/linker settings #set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) #FetchContent_MakeAvailable(googletest) @@ -219,59 +223,62 @@ pkg_search_module(GTEST gtest_main) # Packaged filesystem # links for testing are created here to avoid interoperatibility problems Linux/Windows -if (${WITH_LINK_TESTS}) - if (${USE_TEMP_FS}) - add_custom_target(PACKAGED_FILESYSTEM ALL - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_filesystem ${DATA_TEST_DIR} - COMMAND ${CMAKE_COMMAND} -E chdir ${DATA_TEST_DIR} ln directory-2/file-in-directory-2.txt h-link-to-dir-2 - COMMAND ${CMAKE_COMMAND} -E chdir ${DATA_TEST_DIR} ln -s directory-1/file-in-directory-1.txt s-link-to-dir-1 - COMMAND ${DEPS_BIN_DIR}/mkdwarfs -o ${DATA_BIN_FILE} -i ${DATA_TEST_DIR} - COMMAND ${CMAKE_COMMAND} -E rm -rf ${DATA_TEST_DIR} - DEPENDS ${DWARFS_PRJ} - BYPRODUCTS ${DATA_BIN_FILE} - ) - else() - add_custom_target(PACKAGED_FILESYSTEM ALL - COMMAND ${CMAKE_COMMAND} -E chdir ${DATA_TEST_DIR} ln directory-2/file-in-directory-2.txt h-link-to-dir-2 - COMMAND ${CMAKE_COMMAND} -E chdir ${DATA_TEST_DIR} ln -s directory-1/file-in-directory-1.txt s-link-to-dir-1 - COMMAND ${DEPS_BIN_DIR}/mkdwarfs -o ${DATA_BIN_FILE} -i ${DATA_TEST_DIR} - COMMAND ${CMAKE_COMMAND} -E rm ${DATA_TEST_DIR}/h-link-to-dir-2 - COMMAND ${CMAKE_COMMAND} -E rm ${DATA_TEST_DIR}/s-link-to-dir-1 - DEPENDS ${DWARFS_PRJ} - BYPRODUCTS ${DATA_BIN_FILE} - ) - endif() -else() - if (${USE_TEMP_FS}) - add_custom_target(PACKAGED_FILESYSTEM ALL - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_filesystem ${DATA_TEST_DIR} - COMMAND ${DEPS_BIN_DIR}/mkdwarfs -o ${DATA_BIN_FILE} -i ${DATA_TEST_DIR} - COMMAND ${CMAKE_COMMAND} -E rm -rf ${DATA_TEST_DIR} - DEPENDS ${DWARFS_PRJ} - BYPRODUCTS ${DATA_BIN_FILE} - ) - else() - add_custom_target(PACKAGED_FILESYSTEM ALL - COMMAND ${DEPS_BIN_DIR}/mkdwarfs -o ${DATA_BIN_FILE} -i ${DATA_TEST_DIR} - DEPENDS ${DWARFS_PRJ} - BYPRODUCTS ${DATA_BIN_FILE} - ) - endif() -endif() - -configure_file( + if (${WITH_LINK_TESTS}) + if (${USE_TEMP_FS}) + add_custom_target(PACKAGED_FILESYSTEM ALL + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_filesystem ${DATA_TEST_DIR} + COMMAND ${CMAKE_COMMAND} -E chdir ${DATA_TEST_DIR} ln directory-2/file-in-directory-2.txt h-link-to-dir-2 + COMMAND ${CMAKE_COMMAND} -E chdir ${DATA_TEST_DIR} ln -s directory-1/file-in-directory-1.txt s-link-to-dir-1 + COMMAND ${DEPS_BIN_DIR}/mkdwarfs -o ${DATA_BIN_FILE} -i ${DATA_TEST_DIR} + COMMAND ${CMAKE_COMMAND} -E rm -rf ${DATA_TEST_DIR} + DEPENDS ${DWARFS_PRJ} + BYPRODUCTS ${DATA_BIN_FILE} + ) + else(${USE_TEMP_FS}) + add_custom_target(PACKAGED_FILESYSTEM ALL + COMMAND ${CMAKE_COMMAND} -E chdir ${DATA_TEST_DIR} ln directory-2/file-in-directory-2.txt h-link-to-dir-2 + COMMAND ${CMAKE_COMMAND} -E chdir ${DATA_TEST_DIR} ln -s directory-1/file-in-directory-1.txt s-link-to-dir-1 + COMMAND ${DEPS_BIN_DIR}/mkdwarfs -o ${DATA_BIN_FILE} -i ${DATA_TEST_DIR} + COMMAND ${CMAKE_COMMAND} -E rm ${DATA_TEST_DIR}/h-link-to-dir-2 + COMMAND ${CMAKE_COMMAND} -E rm ${DATA_TEST_DIR}/s-link-to-dir-1 + DEPENDS ${DWARFS_PRJ} + BYPRODUCTS ${DATA_BIN_FILE} + ) + endif(${USE_TEMP_FS}) + else(${WITH_LINK_TESTS}) + if (${USE_TEMP_FS}) + add_custom_target(PACKAGED_FILESYSTEM ALL + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_filesystem ${DATA_TEST_DIR} + COMMAND ${DEPS_BIN_DIR}/mkdwarfs -o ${DATA_BIN_FILE} -i ${DATA_TEST_DIR} + COMMAND ${CMAKE_COMMAND} -E rm -rf ${DATA_TEST_DIR} + DEPENDS ${DWARFS_PRJ} + BYPRODUCTS ${DATA_BIN_FILE} + ) + else(${USE_TEMP_FS}) + add_custom_target(PACKAGED_FILESYSTEM ALL + COMMAND ${DEPS_BIN_DIR}/mkdwarfs -o ${DATA_BIN_FILE} -i ${DATA_TEST_DIR} + DEPENDS ${DWARFS_PRJ} + BYPRODUCTS ${DATA_BIN_FILE} + ) + endif(${USE_TEMP_FS}) + endif(${WITH_LINK_TESTS}) + + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/tebako-fs.cpp.in ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs.cpp @ONLY -) + ) -function(ADD_DWARFS_LIBRARY NAME PRJ APP_NM) + function(ADD_DWARFS_LIBRARY NAME PRJ APP_NM) add_library(${NAME} STATIC IMPORTED) set_target_properties(${NAME} PROPERTIES IMPORTED_LOCATION ${_${NAME}}) add_dependencies(${NAME} ${PRJ}) target_link_libraries(${APP_NM} ${NAME}) -endfunction() + install(FILES ${_${NAME}} + DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + endfunction() # ................................................................... # System libraries @@ -310,28 +317,31 @@ endfunction() # We check that (1) it is possible to compile, build and run program with pure C startup # (2) it is statically linked -add_executable(wr-bin + add_executable(wr-bin + "include/tebako-pch.h" + "include/tebako-defines.h" + "include/tebako-io.h" "tests/tests-defines-static.c" "tests/tebako-fs.cpp" "tests/tebako-fs.h" "tests/tests.h" -) + ) -target_link_libraries(wr-bin dwarfs-wr) -add_dependencies(wr-bin ${INCBIN_PRJ} PACKAGED_FILESYSTEM) + target_link_libraries(wr-bin dwarfs-wr) + add_dependencies(wr-bin ${INCBIN_PRJ} PACKAGED_FILESYSTEM) # ................................................................... # The libraries that are build by dwarfs project # libdwarfs libfolly libfsst libxxhash libmetadata_thrift libthrift_light libarchive -add_dwarfs_library(_LIBDWARFS ${DWARFS_PRJ} wr-bin) -add_dwarfs_library(_LIBFSST ${DWARFS_PRJ} wr-bin) -add_dwarfs_library(_LIBFOLLY ${DWARFS_PRJ} wr-bin) -add_dwarfs_library(_LIBT_METADATA ${DWARFS_PRJ} wr-bin) -add_dwarfs_library(_LIBT_LIGHT ${DWARFS_PRJ} wr-bin) -add_dwarfs_library(_LIBXXHASH ${DWARFS_PRJ} wr-bin) -add_dwarfs_library(_LIBZSTD ${DWARFS_PRJ} wr-bin) -add_dwarfs_library(_LIBARCHIVE ${DWARFS_PRJ} wr-bin) + add_dwarfs_library(_LIBDWARFS ${DWARFS_PRJ} wr-bin) + add_dwarfs_library(_LIBFSST ${DWARFS_PRJ} wr-bin) + add_dwarfs_library(_LIBFOLLY ${DWARFS_PRJ} wr-bin) + add_dwarfs_library(_LIBT_METADATA ${DWARFS_PRJ} wr-bin) + add_dwarfs_library(_LIBT_LIGHT ${DWARFS_PRJ} wr-bin) + add_dwarfs_library(_LIBXXHASH ${DWARFS_PRJ} wr-bin) + add_dwarfs_library(_LIBZSTD ${DWARFS_PRJ} wr-bin) + add_dwarfs_library(_LIBARCHIVE ${DWARFS_PRJ} wr-bin) # ................................................................... # IMPORTANT !!! @@ -347,11 +357,12 @@ add_dwarfs_library(_LIBARCHIVE ${DWARFS_PRJ} wr-bin) ${_LIBUNWIND} ${_LIBLZMA} ) - # ................................................................... # Google test -add_executable(wr-tests + add_executable(wr-tests + "include/tebako-pch.h" + "include/tebako-io.h" "tests/tests-fs-load.cpp" "tests/tests-file-ctl.cpp" "tests/tests-file-io.cpp" @@ -364,29 +375,24 @@ add_executable(wr-tests "tests/tests.h" ) -target_compile_options(wr-tests PUBLIC ${GTEST_CFLAGS}) -target_link_libraries(wr-tests + target_compile_options(wr-tests PUBLIC ${GTEST_CFLAGS}) + target_link_libraries(wr-tests dwarfs-wr ${GTEST_LDFLAGS} -) + ) -add_dependencies(wr-tests ${INCBIN_PRJ} PACKAGED_FILESYSTEM wr-bin) + add_dependencies(wr-tests ${INCBIN_PRJ} PACKAGED_FILESYSTEM wr-bin) -gtest_add_tests(TARGET wr-tests) + gtest_add_tests(TARGET wr-tests) -target_link_libraries(wr-tests _LIBDWARFS) -target_link_libraries(wr-tests _LIBFSST) -target_link_libraries(wr-tests _LIBFOLLY) -target_link_libraries(wr-tests _LIBT_METADATA) -target_link_libraries(wr-tests _LIBT_LIGHT) -target_link_libraries(wr-tests _LIBXXHASH) -target_link_libraries(wr-tests _LIBZSTD) -target_link_libraries(wr-tests _LIBARCHIVE) + target_link_libraries(wr-tests _LIBDWARFS _LIBFSST _LIBFOLLY _LIBT_METADATA + _LIBT_LIGHT _LIBXXHASH _LIBZSTD _LIBARCHIVE) # ................................................................... # IMPORTANT !!! # MUST be in this order otherwise link may fail # -static-libgcc and gcc_eh below is all together an ugly trick to enforce static linking +# [??? this also looked like a requirement but all tests pass without libc ] ${_LIBC} target_link_libraries(wr-tests ${_LIBFMT} ${Boost_LIBRARIES} ${_LIBDC} @@ -397,5 +403,31 @@ target_link_libraries(wr-tests _LIBARCHIVE) ${_LIBUNWIND} ${_LIBLZMA} ) -# ${_LIBC} +endif(${WITH_TESTS}) + + install(TARGETS + dwarfs-wr + DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + + install(FILES + ${__LIBDWARFS} ${__LIBFSST} ${__LIBFOLLY} ${__LIBT_METADATA} + ${__LIBT_LIGHT} ${__LIBXXHASH} ${__LIBZSTD} ${__LIBARCHIVE} + DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + +install(FILES + "include/tebako-defines.h" + "include/tebako-io.h" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tebako +) + +install(FILES + ${DEPS_BIN_DIR}/dwarfs + ${DEPS_BIN_DIR}/dwarfsck + ${DEPS_BIN_DIR}/dwarfsextract + ${DEPS_BIN_DIR}/mkdwarfs + DESTINATION ${CMAKE_INSTALL_BINDIR} +) + diff --git a/CMakeSettings.json b/CMakeSettings.json index 3098d518..a42a2899 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -7,11 +7,24 @@ "buildRoot": "${projectDir}\\out\\build\\${name}", "installRoot": "${projectDir}\\out\\install\\${name}", "cmakeExecutable": "cmake", - "cmakeCommandArgs": "-DWITH_LINK_TESTS:BOOL=OFF -DUSE_TEMP_FS:BOOL=OFF", + "cmakeCommandArgs": "-DWITH_TESTS:BOOL=ON -DWITH_LINK_TESTS:BOOL=ON -DUSE_TEMP_FS:BOOL=OFF", "buildCommandArgs": "", "ctestCommandArgs": "", "inheritEnvironments": [ "linux_x64" ], - "wslPath": "C:\\Users\\maxirmx\\AppData\\Local\\Microsoft\\WindowsApps\\ubuntu2004.exe" + "wslPath": "C:\\Users\\Maxim\\AppData\\Local\\Microsoft\\WindowsApps\\ubuntu2004.exe" + }, + { + "name": "WSL-GCC-Release", + "generator": "Ninja", + "configurationType": "Release", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeExecutable": "cmake", + "cmakeCommandArgs": "-DWITH_TESTS:BOOL=ON -DWITH_LINK_TESTS:BOOL=ON -DUSE_TEMP_FS:BOOL=ON", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "linux_x64" ], + "wslPath": "${defaultWSLPath}" } ] } \ No newline at end of file diff --git a/README.md b/README.md index 1de60c75..d1ee07ab 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,15 @@ This is libdwarfs-wr - a wrapper for https://github.com/mhx/dwarfs core library * fd (file descriptor) addressing above dwarfs inode implementation +### CMake project options + +* **WITH_TESTS**, default:ON -- If this option is ON, build script looks for Google test, installs INCBIN, and build google tests and static test application. +* **WITH_LINK_TEST**, default:ON -- If this option is ON, symbolik/ hard link tests are enabled. +* **USE_TEMP_FS**, default:OFF -- If this option is ON, the data for test file system is created under /tmp. Otherwise in-source location is used. + + + + + + diff --git a/include/tebako-common.h b/include/tebako-common.h index 41a24c52..c8ca2a95 100644 --- a/include/tebako-common.h +++ b/include/tebako-common.h @@ -82,6 +82,8 @@ #endif #define TEBAKO_PATH_LENGTH ((size_t) PATH_MAX) + +/* This shall match tebako TEBAKO_MOUNT_POINT definition at CMakeLists.txt */ #define TEBAKO_MOINT_POINT "__tebako_memfs__" #define TEBAKO_MOUNT_POINT_LENGTH 16 diff --git a/include/tebako-io.h b/include/tebako-io.h index 8ad91aa5..c0964bec 100644 --- a/include/tebako-io.h +++ b/include/tebako-io.h @@ -53,20 +53,38 @@ extern "C" { char* tebako_getcwd(char* buf, size_t size); char* tebako_getwd(char* buf); int tebako_chdir(const char* path); + +#ifdef __mode_t_defined int tebako_mkdir(const char* path, mode_t mode); - int tebako_stat(const char* path, struct stat* buf); +#endif + int tebako_access(const char* path, int amode); int tebako_open(int nargs, const char* path, int flags, ...); int tebako_openat(int nargs, int fd, const char* path, int flags, ...); ssize_t tebako_read(int vfd, void* buf, size_t nbyte); + +/* struct iovec will be defined only if dirent.h has been included */ +#ifdef _SYS_UIO_H ssize_t tebako_readv(int vfd, const struct iovec* iov, int iovcnt); +#endif + +#ifdef __off_t_defined ssize_t tebako_pread(int vfd, void* buf, size_t nbyte, off_t offset); off_t tebako_lseek(int vfd, off_t offset, int whence); +#endif + +/* struct stat will be defined only if dirent.h has been included */ +#ifdef _SYS_STAT_H + int tebako_stat(const char* path, struct stat* buf); int tebako_fstat(int vfd, struct stat* buf); int tebako_lstat(const char* path, struct stat* buf); +#endif + int tebako_close(int vfd); ssize_t tebako_readlink(const char* path, char* buf, size_t bufsiz); +/* DIR and struct dirent will be defined only if dirent.h has been included */ +#ifdef _DIRENT_H DIR* tebako_opendir(const char* dirname); DIR* tebako_fdopendir(int fd); struct dirent* tebako_readdir(DIR* dirp); @@ -78,6 +96,7 @@ extern "C" { int tebako_scandir(const char* dir, struct dirent*** namelist, int (*sel)(const struct dirent*), int (*compar)(const struct dirent**, const struct dirent**)); +#endif void* tebako_dlopen(const char* path, int flags); diff --git a/include/tebako-pch.h b/include/tebako-pch.h index 89b617a7..e9291228 100644 --- a/include/tebako-pch.h +++ b/include/tebako-pch.h @@ -42,7 +42,6 @@ #include #include #include -#include #ifdef _WIN32 #include diff --git a/patches/2.patch/version.cpp b/patches/2.patch/version.cpp deleted file mode 100644 index ce144a5e..00000000 --- a/patches/2.patch/version.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// autogenerated code, do not modify - -#include "dwarfs/version.h" - -namespace dwarfs { - -char const* PRJ_GIT_REV = "78fd324"; -char const* PRJ_GIT_DESC = "v0.5.6"; -char const* PRJ_GIT_BRANCH = "metanorma/main"; -char const* PRJ_GIT_ID = "v0.5.6"; - -} // namespace dwarfs \ No newline at end of file diff --git a/patches/2.patch/version.h b/patches/2.patch/version.h deleted file mode 100644 index a11b08f5..00000000 --- a/patches/2.patch/version.h +++ /dev/null @@ -1,16 +0,0 @@ -// autogenerated code, do not modify - -#pragma once - -#define PRJ_VERSION_MAJOR 0 -#define PRJ_VERSION_MINOR 5 -#define PRJ_VERSION_PATCH 6 - -namespace dwarfs { - -extern char const* PRJ_GIT_REV; -extern char const* PRJ_GIT_DESC; -extern char const* PRJ_GIT_BRANCH; -extern char const* PRJ_GIT_ID; - -} // namespace dwarfs \ No newline at end of file diff --git a/src/tebako-io-helpers.cpp b/src/tebako-io-helpers.cpp index b9a80d69..7eba39cd 100644 --- a/src/tebako-io-helpers.cpp +++ b/src/tebako-io-helpers.cpp @@ -72,14 +72,14 @@ static folly::Synchronized tebako_cwd{ new tebako_path_s }; return (path != NULL && (strncmp((path), "/" TEBAKO_MOINT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 1) == 0 #ifdef _WIN32 - || strncmp(path, "\\" TEBAKO_MOINT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 1) == 0 - || strncmp(path + 1, ":/" TEBAKO_MOINT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 2) == 0 - || strncmp(path + 1, ":\\" TEBAKO_MOINT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 2) == 0 - || strncmp(path, "//?/" TEBAKO_MOINT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 3) == 0 - || strncmp(path, "\\\\?\\" TEBAKO_MOINT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 3) == 0 + || strncmp(path, "\\" TEBAKO_MOUNT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 1) == 0 + || strncmp(path + 1, ":/" TEBAKO_MOUNT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 2) == 0 + || strncmp(path + 1, ":\\" TEBAKO_MOUNT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 2) == 0 + || strncmp(path, "//?/" TEBAKO_MOUNT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 3) == 0 + || strncmp(path, "\\\\?\\" TEBAKO_MOUNT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 3) == 0 || ((strncmp(path, "\\\\?\\", 4) == 0 || strncmp(path, "//?/", 4) == 0) && - (strncmp(path + 5, ":/" TEBAKO_MOINT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 2) == 0 || - strncmp(path + 5, ":\\" TEBAKO_MOINT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 2) == 0 + (strncmp(path + 5, ":/" TEBAKO_MOUNT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 2) == 0 || + strncmp(path + 5, ":\\" TEBAKO_MOUNT_POINT, TEBAKO_MOUNT_POINT_LENGTH + 2) == 0 ) #endif )) ? -1 : 0;