From 87490489f419588b0f8f2d5c9316c2a496b1bb90 Mon Sep 17 00:00:00 2001 From: sameeul Date: Wed, 25 Oct 2023 18:38:08 -0400 Subject: [PATCH 01/14] Try building libfilepattern --- CMakeLists.txt | 82 +++---------------- src/filepattern/cpp/CMakeLists.txt | 78 ++++++++++++++++++ src/filepattern/cpp/bindings.cpp | 9 +- src/filepattern/cpp/include/filepattern.h | 77 ++++++++++++++++- src/filepattern/cpp/interface/filepattern.cpp | 1 - .../filepattern/cpp/packaging}/CMakeLists.txt | 2 +- .../cpp/packaging}/filepatternConfig.cmake | 2 + src/filepattern/cpp/pattern_object.hpp | 24 +++++- 8 files changed, 198 insertions(+), 77 deletions(-) create mode 100644 src/filepattern/cpp/CMakeLists.txt rename {packaging => src/filepattern/cpp/packaging}/CMakeLists.txt (92%) rename {packaging => src/filepattern/cpp/packaging}/filepatternConfig.cmake (97%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ec5443b..f42e92c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,90 +1,34 @@ cmake_minimum_required(VERSION 3.20) project(filepattern) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) -# this is a workaround for GitHub Action for wheelbuiling if(DEFINED ENV{FILEPATTERN_DEP_DIR}) set(CMAKE_PREFIX_PATH $ENV{FILEPATTERN_DEP_DIR}) link_directories($ENV{FILEPATTERN_DEP_DIR}/lib) endif() -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - - -file(READ src/filepattern/cpp/version.h VER_FILE ) -string(REGEX MATCH "#define PROJECT_VER \"([0-9]+)\.([0-9]+)\.([0-9+])\"" _ "${VER_FILE}") -set (filepattern_VERSION_MAJOR ${CMAKE_MATCH_1}) -set (filepattern_VERSION_MINOR ${CMAKE_MATCH_2}) -set (filepattern_VERSION_PATCH ${CMAKE_MATCH_3}) -set(filepattern_VERSION "${filepattern_VERSION_MAJOR}.${filepattern_VERSION_MINOR}.${filepattern_VERSION_PATCH}") -message(STATUS "Building filepattern ${filepattern_VERSION}" ) - option(RUN_GTEST "Downloads google unit test API and runs google test scripts to test Filepattern" OFF) -if(JAVA_BINDING) - add_compile_definitions(JAVA_BINDING) -endif() - -#==== Source files -set(SOURCE src/filepattern/cpp/pattern.cpp - src/filepattern/cpp/interface/filepattern.cpp - src/filepattern/cpp/internal/internal_pattern.cpp - src/filepattern/cpp/internal/filepattern.cpp - src/filepattern/cpp/internal/stringpattern.cpp - src/filepattern/cpp/internal/vectorpattern.cpp - src/filepattern/cpp/external/external_pattern.cpp - src/filepattern/cpp/external/external_filepattern.cpp - src/filepattern/cpp/external/external_stringpattern.cpp - src/filepattern/cpp/external/external_vectorpattern.cpp - src/filepattern/cpp/util/fs_stream.cpp - src/filepattern/cpp/util/sort.cpp - src/filepattern/cpp/util/vector_parser.cpp -) -if (NOT BUILD_PYTHON_LIB) # Not taking the setup.py route, just building libs - if (NOT MSVC) - if (NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET AND - NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN) - set(CMAKE_CXX_VISIBILITY_PRESET hidden) - set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) - endif () - endif() - - - if(DEFINED filepattern_SHARED_LIB) - set(BUILD_SHARED_LIBS ${filepattern_SHARED_LIB}) - endif() - add_library(filepattern ${SOURCE}) - add_library(filepattern::filepattern ALIAS filepattern) - set_target_properties(filepattern PROPERTIES - VERSION ${filepattern_VERSION} - SOVERSION ${filepattern_VERSION_MAJOR}) - target_include_directories( - filepattern PUBLIC "$") - include(GenerateExportHeader) - generate_export_header(filepattern EXPORT_FILE_NAME include/filepattern_export.h) - target_compile_definitions( - filepattern PUBLIC "$<$>:FILEPATTERN_STATIC_DEFINE>") - target_compile_definitions(filepattern PUBLIC FP_CPP_LIB_EXPORT) - target_include_directories( - filepattern PUBLIC "$") - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_link_libraries(filepattern PRIVATE stdc++fs) - endif() - string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" is_top_level) - option(filepattern_INCLUDE_PACKAGING "Include packaging rules for FilePattern" "${is_top_level}") - if (filepattern_INCLUDE_PACKAGING) - add_subdirectory(packaging) - endif () -endif() if(BUILD_PYTHON_LIB) find_package(pybind11 CONFIG REQUIRED) + set(filepattern_SHARED_LIB ON) pybind11_add_module(backend - ${SOURCE} src/filepattern/cpp/bindings.cpp ) + find_package(filepattern) + if (NOT filepattern_FOUND) + message(STATUS "libfilePattern not found. Building from source...") + add_subdirectory(src/filepattern/cpp ${CMAKE_BINARY_DIR}/third-party) + add_dependencies(backend filepattern) + target_include_directories(backend PRIVATE ${CMAKE_BINARY_DIR}/third-party/include) + else() + target_compile_definitions(backend PRIVATE WITH_LIBFILEPATTERN) + endif() + target_link_libraries(backend PRIVATE filepattern::filepattern) target_compile_definitions(backend PRIVATE WITH_PYTHON_H) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_link_libraries(backend PRIVATE stdc++fs) diff --git a/src/filepattern/cpp/CMakeLists.txt b/src/filepattern/cpp/CMakeLists.txt new file mode 100644 index 00000000..f8e76c20 --- /dev/null +++ b/src/filepattern/cpp/CMakeLists.txt @@ -0,0 +1,78 @@ +cmake_minimum_required(VERSION 3.20) +project(libfilepattern) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(DEFINED ENV{FILEPATTERN_DEP_DIR}) + set(CMAKE_PREFIX_PATH $ENV{FILEPATTERN_DEP_DIR}) + link_directories($ENV{FILEPATTERN_DEP_DIR}/lib) +endif() + +file(READ version.h VER_FILE ) +string(REGEX MATCH "#define PROJECT_VER \"([0-9]+)\.([0-9]+)\.([0-9+])\"" _ "${VER_FILE}") +set (filepattern_VERSION_MAJOR ${CMAKE_MATCH_1}) +set (filepattern_VERSION_MINOR ${CMAKE_MATCH_2}) +set (filepattern_VERSION_PATCH ${CMAKE_MATCH_3}) +set(filepattern_VERSION "${filepattern_VERSION_MAJOR}.${filepattern_VERSION_MINOR}.${filepattern_VERSION_PATCH}") +message(STATUS "Building libfilepattern ${filepattern_VERSION}" ) + +if(JAVA_BINDING) + add_compile_definitions(JAVA_BINDING) +endif() + +#==== Source files +set(SOURCE pattern.cpp + interface/filepattern.cpp + internal/internal_pattern.cpp + internal/filepattern.cpp + internal/stringpattern.cpp + internal/vectorpattern.cpp + external/external_pattern.cpp + external/external_filepattern.cpp + external/external_stringpattern.cpp + external/external_vectorpattern.cpp + util/fs_stream.cpp + util/sort.cpp + util/vector_parser.cpp +) + +if (NOT MSVC) + if (NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET AND + NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN) + set(CMAKE_CXX_VISIBILITY_PRESET hidden) + set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) + endif () +endif() + + +if(DEFINED filepattern_SHARED_LIB) + set(BUILD_SHARED_LIBS ${filepattern_SHARED_LIB}) +endif() +add_library(filepattern ${SOURCE}) +add_library(filepattern::filepattern ALIAS filepattern) +set_target_properties(filepattern PROPERTIES + VERSION ${filepattern_VERSION} + SOVERSION ${filepattern_VERSION_MAJOR}) +target_include_directories( + filepattern PUBLIC "$") +include(GenerateExportHeader) +generate_export_header(filepattern EXPORT_FILE_NAME include/filepattern_export.h) +target_compile_definitions( + filepattern PUBLIC "$<$>:FILEPATTERN_STATIC_DEFINE>") +target_compile_definitions(filepattern PUBLIC FP_CPP_LIB_EXPORT) +target_include_directories( + filepattern PUBLIC "$") +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_link_libraries(filepattern PRIVATE stdc++fs) +endif() + +string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" is_top_level) +option(filepattern_INCLUDE_PACKAGING "Include packaging rules for FilePattern" "${is_top_level}") +if (filepattern_INCLUDE_PACKAGING) + add_subdirectory(packaging) +endif () + + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + diff --git a/src/filepattern/cpp/bindings.cpp b/src/filepattern/cpp/bindings.cpp index 769e9c84..f3dc5164 100644 --- a/src/filepattern/cpp/bindings.cpp +++ b/src/filepattern/cpp/bindings.cpp @@ -3,15 +3,16 @@ #include #include #include -#include +//#include +#ifdef WITH_LIBFILEPATTERN +#include "filepattern/filepattern.h" +#else #include "include/filepattern.h" -#include "pattern_object.hpp" +#endif namespace py = pybind11; -//PYBIND11_MAKE_OPAQUE(std::vector>); - PYBIND11_MODULE(backend, m){ py::class_(m, "FilePattern") diff --git a/src/filepattern/cpp/include/filepattern.h b/src/filepattern/cpp/include/filepattern.h index 5feb940b..19ee3330 100644 --- a/src/filepattern/cpp/include/filepattern.h +++ b/src/filepattern/cpp/include/filepattern.h @@ -31,8 +31,83 @@ using Tuple = std::tuple>; #else using Tuple = std::tuple>; #endif +#ifndef _PATTERNOBJECT +#define _PATTERNOBJECT + +class PatternObject { + public: + bool external = false; + + std::vector valid_files_; // Store files that match given regex + + std::string path_; + std::string file_pattern_; + + std::vector> , std::vector>> valid_grouped_files_; // 2D vector to store grouped files + std::vector group_; // current groupBy variable + + std::vector variables_; // Store the names of variables from the pattern + std::map> variable_occurrences_; // store the number of times a variable value occurs + std::map> unique_values_; // store each unique value for every variable + + std::vector named_groups_; + std::vector tmp_directories_; // store paths to all temporary directories used + + std::vector current_block_; // Store current block of files + //std::vector, std::vector>> currentGroup; //Store current block of grouped files + std::vector> , std::vector>> current_group_; + + virtual ~PatternObject() {} + + virtual std::vector getMatching(const std::vector>>& variables) = 0; + + virtual void groupBy(std::vector& groups) = 0; + + virtual std::map> getOccurrences(const std::vector>>& mapping) = 0; + + virtual std::map> getUniqueValues(const std::vector& mapping) = 0; + + virtual std::string outputName(std::vector& vec) = 0; + + virtual std::vector getVariables() = 0; + + //virtual void getNewNaming(std::string& pattern, bool suppressWarnings) = 0; + + virtual void next() = 0; + + virtual void nextGroup() = 0; + + virtual int currentBlockLength() = 0; + + virtual void setGroup(const std::vector& groups) = 0; + + virtual std::vector getSlice(std::vector& key) = 0; + + virtual std::string inferPattern(const std::string& path, std::string& variables, const std::string& block_size) = 0; + + virtual std::string inferPattern(std::vector& vec, std::string& variables) = 0; + + virtual std::vector getMatchingBlock() = 0; + + virtual Tuple getItem(int key) = 0; + + virtual std::vector getItemList(std::vector& key) = 0; + + size_t length() const {return valid_files_.size();}; + + const std::pair> , std::vector>& get_grouped_file_by_idx(int idx) { + + if (idx < 0 || idx >= this->valid_grouped_files_.size()) { + + throw std::out_of_range("Invalid index " + std::to_string(idx) + " for file vector size of " + std::to_string(valid_grouped_files_.size())); + + } + + return valid_grouped_files_[idx]; + } +}; +#endif -class PatternObject; // forward declaration class FILEPATTERN_EXPORT FilePattern { public: diff --git a/src/filepattern/cpp/interface/filepattern.cpp b/src/filepattern/cpp/interface/filepattern.cpp index 4e5989d9..70781358 100644 --- a/src/filepattern/cpp/interface/filepattern.cpp +++ b/src/filepattern/cpp/interface/filepattern.cpp @@ -1,6 +1,5 @@ #include "../include/filepattern.h" #include "filepattern_factory.h" -#include "../pattern_object.hpp" FilePattern::FilePattern(const std::string& path, const std::string& filePattern, const std::string& block_size, bool recursive, bool suppressWarnings) { diff --git a/packaging/CMakeLists.txt b/src/filepattern/cpp/packaging/CMakeLists.txt similarity index 92% rename from packaging/CMakeLists.txt rename to src/filepattern/cpp/packaging/CMakeLists.txt index 43b78bdd..721cdf69 100644 --- a/packaging/CMakeLists.txt +++ b/src/filepattern/cpp/packaging/CMakeLists.txt @@ -14,7 +14,7 @@ install(TARGETS filepattern EXPORT filepattern_Targets INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) -install(DIRECTORY "${filepattern_SOURCE_DIR}/src/filepattern/cpp/include/" "${filepattern_BINARY_DIR}/include/" +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../include/" "${CMAKE_CURRENT_BINARY_DIR}/../include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/filepattern/" COMPONENT filepattern_Development) diff --git a/packaging/filepatternConfig.cmake b/src/filepattern/cpp/packaging/filepatternConfig.cmake similarity index 97% rename from packaging/filepatternConfig.cmake rename to src/filepattern/cpp/packaging/filepatternConfig.cmake index f2b9b0de..574dc49c 100644 --- a/packaging/filepatternConfig.cmake +++ b/src/filepattern/cpp/packaging/filepatternConfig.cmake @@ -55,3 +55,5 @@ else () filepattern_load_targets(shared) endif () endif () + +message(STATUS "Found libfilepattern: ${filepattern_VERSION}") \ No newline at end of file diff --git a/src/filepattern/cpp/pattern_object.hpp b/src/filepattern/cpp/pattern_object.hpp index 59cb8b84..5d0deb9f 100644 --- a/src/filepattern/cpp/pattern_object.hpp +++ b/src/filepattern/cpp/pattern_object.hpp @@ -1,3 +1,6 @@ +#ifndef _PATTERNOBJECT +#define _PATTERNOBJECT + #pragma once #include @@ -7,7 +10,25 @@ #include #include -#include "util/util.hpp" + +#if __has_include() + #include + namespace fs = std::filesystem; +#elif __has_include() + #include + namespace fs = std::experimental::filesystem; +#else + error "Missing the header." +#endif + +using Types = std::variant; +using Map = std::map; +#ifdef JAVA_BINDING +using Tuple = std::tuple>; +#else +using Tuple = std::tuple>; +#endif + class PatternObject { public: @@ -84,3 +105,4 @@ class PatternObject { }; +#endif \ No newline at end of file From 59aea7f32976f138545bbee2762b2f600fad890d Mon Sep 17 00:00:00 2001 From: Sameeul B Samee Date: Wed, 25 Oct 2023 21:24:36 -0400 Subject: [PATCH 02/14] Rearrage headers --- CMakeLists.txt | 2 +- src/filepattern/cpp/bindings.cpp | 3 +- src/filepattern/cpp/include/filepattern.h | 76 +---------------------- 3 files changed, 4 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f42e92c2..ca15a056 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ if(BUILD_PYTHON_LIB) pybind11_add_module(backend src/filepattern/cpp/bindings.cpp ) - find_package(filepattern) + find_package(filepattern QUIET) if (NOT filepattern_FOUND) message(STATUS "libfilePattern not found. Building from source...") add_subdirectory(src/filepattern/cpp ${CMAKE_BINARY_DIR}/third-party) diff --git a/src/filepattern/cpp/bindings.cpp b/src/filepattern/cpp/bindings.cpp index f3dc5164..1d5c3c30 100644 --- a/src/filepattern/cpp/bindings.cpp +++ b/src/filepattern/cpp/bindings.cpp @@ -3,7 +3,8 @@ #include #include #include -//#include + +#include "pattern_object.hpp" #ifdef WITH_LIBFILEPATTERN #include "filepattern/filepattern.h" diff --git a/src/filepattern/cpp/include/filepattern.h b/src/filepattern/cpp/include/filepattern.h index 19ee3330..b73691d5 100644 --- a/src/filepattern/cpp/include/filepattern.h +++ b/src/filepattern/cpp/include/filepattern.h @@ -31,82 +31,8 @@ using Tuple = std::tuple>; #else using Tuple = std::tuple>; #endif -#ifndef _PATTERNOBJECT -#define _PATTERNOBJECT -class PatternObject { - public: - bool external = false; - - std::vector valid_files_; // Store files that match given regex - - std::string path_; - std::string file_pattern_; - - std::vector> , std::vector>> valid_grouped_files_; // 2D vector to store grouped files - std::vector group_; // current groupBy variable - - std::vector variables_; // Store the names of variables from the pattern - std::map> variable_occurrences_; // store the number of times a variable value occurs - std::map> unique_values_; // store each unique value for every variable - - std::vector named_groups_; - std::vector tmp_directories_; // store paths to all temporary directories used - - std::vector current_block_; // Store current block of files - //std::vector, std::vector>> currentGroup; //Store current block of grouped files - std::vector> , std::vector>> current_group_; - - virtual ~PatternObject() {} - - virtual std::vector getMatching(const std::vector>>& variables) = 0; - - virtual void groupBy(std::vector& groups) = 0; - - virtual std::map> getOccurrences(const std::vector>>& mapping) = 0; - - virtual std::map> getUniqueValues(const std::vector& mapping) = 0; - - virtual std::string outputName(std::vector& vec) = 0; - - virtual std::vector getVariables() = 0; - - //virtual void getNewNaming(std::string& pattern, bool suppressWarnings) = 0; - - virtual void next() = 0; - - virtual void nextGroup() = 0; - - virtual int currentBlockLength() = 0; - - virtual void setGroup(const std::vector& groups) = 0; - - virtual std::vector getSlice(std::vector& key) = 0; - - virtual std::string inferPattern(const std::string& path, std::string& variables, const std::string& block_size) = 0; - - virtual std::string inferPattern(std::vector& vec, std::string& variables) = 0; - - virtual std::vector getMatchingBlock() = 0; - - virtual Tuple getItem(int key) = 0; - - virtual std::vector getItemList(std::vector& key) = 0; - - size_t length() const {return valid_files_.size();}; - - const std::pair> , std::vector>& get_grouped_file_by_idx(int idx) { - - if (idx < 0 || idx >= this->valid_grouped_files_.size()) { - - throw std::out_of_range("Invalid index " + std::to_string(idx) + " for file vector size of " + std::to_string(valid_grouped_files_.size())); - - } - - return valid_grouped_files_[idx]; - } -}; -#endif +class PatternObject; // forward declaration class FILEPATTERN_EXPORT FilePattern { From c62c8ab97149e003dd51de2db71cbf8909a7daf1 Mon Sep 17 00:00:00 2001 From: Sameeul B Samee Date: Wed, 25 Oct 2023 22:22:48 -0400 Subject: [PATCH 03/14] Rearrage headers --- CMakeLists.txt | 6 ++++-- src/filepattern/cpp/include/filepattern.h | 1 - src/filepattern/cpp/pattern_object.hpp | 6 +----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca15a056..458c7276 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,15 @@ cmake_minimum_required(VERSION 3.20) project(filepattern) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +# this is a workaround for GitHub Action for wheelbuiling if(DEFINED ENV{FILEPATTERN_DEP_DIR}) set(CMAKE_PREFIX_PATH $ENV{FILEPATTERN_DEP_DIR}) link_directories($ENV{FILEPATTERN_DEP_DIR}/lib) endif() +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + option(RUN_GTEST "Downloads google unit test API and runs google test scripts to test Filepattern" OFF) diff --git a/src/filepattern/cpp/include/filepattern.h b/src/filepattern/cpp/include/filepattern.h index b73691d5..5feb940b 100644 --- a/src/filepattern/cpp/include/filepattern.h +++ b/src/filepattern/cpp/include/filepattern.h @@ -33,7 +33,6 @@ using Tuple = std::tuple>; #endif class PatternObject; // forward declaration - class FILEPATTERN_EXPORT FilePattern { public: diff --git a/src/filepattern/cpp/pattern_object.hpp b/src/filepattern/cpp/pattern_object.hpp index 5d0deb9f..d6973b15 100644 --- a/src/filepattern/cpp/pattern_object.hpp +++ b/src/filepattern/cpp/pattern_object.hpp @@ -1,6 +1,3 @@ -#ifndef _PATTERNOBJECT -#define _PATTERNOBJECT - #pragma once #include @@ -104,5 +101,4 @@ class PatternObject { -}; -#endif \ No newline at end of file +}; \ No newline at end of file From 3eae74072c9a09b04e7738220874a1df7a642380 Mon Sep 17 00:00:00 2001 From: Sameeul B Samee Date: Wed, 25 Oct 2023 22:33:11 -0400 Subject: [PATCH 04/14] update cmake --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 458c7276..49d9f6ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ if(BUILD_PYTHON_LIB) ) find_package(filepattern QUIET) if (NOT filepattern_FOUND) - message(STATUS "libfilePattern not found. Building from source...") + message(STATUS "libfilepattern not found. It will be build from source.") add_subdirectory(src/filepattern/cpp ${CMAKE_BINARY_DIR}/third-party) add_dependencies(backend filepattern) target_include_directories(backend PRIVATE ${CMAKE_BINARY_DIR}/third-party/include) From 285649ae73064e13bcaa2dffc15b02ba5895099e Mon Sep 17 00:00:00 2001 From: Sameeul B Samee Date: Thu, 26 Oct 2023 04:55:09 -0400 Subject: [PATCH 05/14] Fix compile def --- CMakeLists.txt | 5 +---- src/filepattern/cpp/util/fs_stream.cpp | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49d9f6ea..e2a26efb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,16 +14,14 @@ option(RUN_GTEST "Downloads google unit test API and runs google test scripts to if(BUILD_PYTHON_LIB) - find_package(pybind11 CONFIG REQUIRED) - set(filepattern_SHARED_LIB ON) - pybind11_add_module(backend src/filepattern/cpp/bindings.cpp ) find_package(filepattern QUIET) if (NOT filepattern_FOUND) message(STATUS "libfilepattern not found. It will be build from source.") + set(filepattern_SHARED_LIB ON) add_subdirectory(src/filepattern/cpp ${CMAKE_BINARY_DIR}/third-party) add_dependencies(backend filepattern) target_include_directories(backend PRIVATE ${CMAKE_BINARY_DIR}/third-party/include) @@ -31,7 +29,6 @@ if(BUILD_PYTHON_LIB) target_compile_definitions(backend PRIVATE WITH_LIBFILEPATTERN) endif() target_link_libraries(backend PRIVATE filepattern::filepattern) - target_compile_definitions(backend PRIVATE WITH_PYTHON_H) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_link_libraries(backend PRIVATE stdc++fs) endif() diff --git a/src/filepattern/cpp/util/fs_stream.cpp b/src/filepattern/cpp/util/fs_stream.cpp index fcc36310..892bb6ee 100644 --- a/src/filepattern/cpp/util/fs_stream.cpp +++ b/src/filepattern/cpp/util/fs_stream.cpp @@ -192,10 +192,10 @@ void FilesystemStream::writeValidFiles(const Tuple& mapping){ } for(const auto& element: get<1>(mapping)){ - #ifdef WITH_PYTHON_H - file << element.string() << "," << '\n'; - #else + #ifdef JAVA_BINDING file << element << "," << '\n'; + #else + file << element.string() << "," << '\n'; #endif } From 4b58268eaa333385c30dedbd3376b1fb42775ee3 Mon Sep 17 00:00:00 2001 From: Sameeul B Samee Date: Thu, 26 Oct 2023 05:09:38 -0400 Subject: [PATCH 06/14] Add CIBW_BUILD_VERBOSITY --- .github/workflows/build_wheels.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index a16246d2..58ce8189 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -37,6 +37,7 @@ jobs: python -m cibuildwheel --output-dir dist env: CIBW_BUILD: ${{ matrix.cibw_build }} + CIBW_BUILD_VERBOSITY: 3 CIBW_SKIP: "*musllinux*" CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014 CIBW_BEFORE_ALL_MACOS: brew install llvm && From 8c7a67d77824fa3972131fce5a00b1fd14c93a0a Mon Sep 17 00:00:00 2001 From: Sameeul B Samee Date: Thu, 26 Oct 2023 05:20:29 -0400 Subject: [PATCH 07/14] Add path to try --- .github/workflows/build_wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 58ce8189..a9984f69 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -54,7 +54,7 @@ jobs: CIBW_ENVIRONMENT_LINUX: LD_LIBRARY_PATH="/tmp/filepattern_bld/local_install/lib:/tmp/filepattern_bld/local_install/lib64:$LD_LIBRARY_PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="/tmp/filepattern_bld/local_install" CIBW_ENVIRONMENT_WINDOWS: PATH="$TEMP\\filepattern\\bin;$PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="C:\\TEMP\\filepattern_bld\\local_install" CIBW_REPAIR_WHEEL_COMMAND_MACOS: DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} && DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel} - CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel}" + CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel} --add-path D:/a/filepattern/filepattern/build/temp.win-amd64-cpython-39/Release/third-party\Release" CIBW_ARCHS: ${{ matrix.cibw_archs }} CIBW_TEST_REQUIRES: pytest pydantic CIBW_TEST_COMMAND: pytest {project}/tests/ From 68ef3cb1b29cde56b566fc5a02ce2930f6dc7440 Mon Sep 17 00:00:00 2001 From: Sameeul B Samee Date: Thu, 26 Oct 2023 05:27:56 -0400 Subject: [PATCH 08/14] Add path to try --- .github/workflows/build_wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index a9984f69..85fc34dd 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -54,7 +54,7 @@ jobs: CIBW_ENVIRONMENT_LINUX: LD_LIBRARY_PATH="/tmp/filepattern_bld/local_install/lib:/tmp/filepattern_bld/local_install/lib64:$LD_LIBRARY_PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="/tmp/filepattern_bld/local_install" CIBW_ENVIRONMENT_WINDOWS: PATH="$TEMP\\filepattern\\bin;$PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="C:\\TEMP\\filepattern_bld\\local_install" CIBW_REPAIR_WHEEL_COMMAND_MACOS: DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} && DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel} - CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel} --add-path D:/a/filepattern/filepattern/build/temp.win-amd64-cpython-39/Release/third-party\Release" + CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel} --add-path D:/a/filepattern/filepattern/build/temp.win-amd64-cpython-39/Release/third-party/Release" CIBW_ARCHS: ${{ matrix.cibw_archs }} CIBW_TEST_REQUIRES: pytest pydantic CIBW_TEST_COMMAND: pytest {project}/tests/ From 422315c287427ce5e3a01a4c8fb3dbf97bad8b91 Mon Sep 17 00:00:00 2001 From: Sameeul B Samee Date: Thu, 26 Oct 2023 05:41:28 -0400 Subject: [PATCH 09/14] Add path to try --- .github/workflows/build_wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 85fc34dd..c20da6b9 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -54,7 +54,7 @@ jobs: CIBW_ENVIRONMENT_LINUX: LD_LIBRARY_PATH="/tmp/filepattern_bld/local_install/lib:/tmp/filepattern_bld/local_install/lib64:$LD_LIBRARY_PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="/tmp/filepattern_bld/local_install" CIBW_ENVIRONMENT_WINDOWS: PATH="$TEMP\\filepattern\\bin;$PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="C:\\TEMP\\filepattern_bld\\local_install" CIBW_REPAIR_WHEEL_COMMAND_MACOS: DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} && DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel} - CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel} --add-path D:/a/filepattern/filepattern/build/temp.win-amd64-cpython-39/Release/third-party/Release" + CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "xcopy /E /I /y D:/a/filepattern/filepattern/build/temp.win-amd64-cpython-39/Release/third-party/Release C:/TEMP/filepattern_bld/local_install && delvewheel repair -w {dest_dir} {wheel}" CIBW_ARCHS: ${{ matrix.cibw_archs }} CIBW_TEST_REQUIRES: pytest pydantic CIBW_TEST_COMMAND: pytest {project}/tests/ From 0db4d5f2d859a576412d75b922d7910e28557d7e Mon Sep 17 00:00:00 2001 From: Sameeul B Samee Date: Thu, 26 Oct 2023 05:48:31 -0400 Subject: [PATCH 10/14] Add path to try --- .github/workflows/build_wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index c20da6b9..2549907b 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -54,7 +54,7 @@ jobs: CIBW_ENVIRONMENT_LINUX: LD_LIBRARY_PATH="/tmp/filepattern_bld/local_install/lib:/tmp/filepattern_bld/local_install/lib64:$LD_LIBRARY_PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="/tmp/filepattern_bld/local_install" CIBW_ENVIRONMENT_WINDOWS: PATH="$TEMP\\filepattern\\bin;$PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="C:\\TEMP\\filepattern_bld\\local_install" CIBW_REPAIR_WHEEL_COMMAND_MACOS: DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} && DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel} - CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "xcopy /E /I /y D:/a/filepattern/filepattern/build/temp.win-amd64-cpython-39/Release/third-party/Release C:/TEMP/filepattern_bld/local_install && delvewheel repair -w {dest_dir} {wheel}" + CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: xcopy /E /I /y D:/a/filepattern/filepattern/build/temp.win-amd64-cpython-39/Release/third-party/Release C:/TEMP/filepattern_bld/local_install && delvewheel repair -w {dest_dir} {wheel} CIBW_ARCHS: ${{ matrix.cibw_archs }} CIBW_TEST_REQUIRES: pytest pydantic CIBW_TEST_COMMAND: pytest {project}/tests/ From 61af9552aa26042a7e72c7b70a6f42397465f9cb Mon Sep 17 00:00:00 2001 From: Sameeul B Samee Date: Thu, 26 Oct 2023 06:02:22 -0400 Subject: [PATCH 11/14] add verbose --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index b41dbd3d..1a700626 100644 --- a/setup.py +++ b/setup.py @@ -66,6 +66,7 @@ def build_extension(self, ext): self.distribution.get_version()) if not os.path.exists(self.build_temp): os.makedirs(self.build_temp) + print(f"Build directory: {self.build_temp} ") subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) subprocess.check_call(['cmake', '--build', '.'] + build_args, From 2c3d329556131cf234204f3015040efcf916aef7 Mon Sep 17 00:00:00 2001 From: sameeul Date: Thu, 26 Oct 2023 17:59:40 -0400 Subject: [PATCH 12/14] Update setup.py --- setup.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 1a700626..7f1762f4 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,16 @@ # -*- coding: utf-8 -*- +from distutils.version import LooseVersion +from pathlib import Path +from setuptools import find_packages, Extension +from setuptools.command.build_ext import build_ext import os +import platform import re +import setuptools +import shutil +import subprocess import sys import versioneer -import platform -import subprocess -import setuptools - -from distutils.version import LooseVersion -from setuptools import find_packages, Extension -from setuptools.command.build_ext import build_ext with open("README.md", "r") as fh: long_description = fh.read() @@ -66,11 +67,17 @@ def build_extension(self, ext): self.distribution.get_version()) if not os.path.exists(self.build_temp): os.makedirs(self.build_temp) - print(f"Build directory: {self.build_temp} ") subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp) + if platform.system() == "Windows": + dll_files = list(Path(os.path.abspath(self.build_temp)).rglob("filepattern.dll")) + if len(dll_files) > 0: + for file in dll_files: + print(f"Copying ${file.as_posix()} -> {extdir}") + shutil.copy(file.as_posix(), extdir) + print() # Add an empty line for cleaner output\ From a9f7424b69569824f0bb5b73bb3fb27f5a1a4c00 Mon Sep 17 00:00:00 2001 From: sameeul Date: Thu, 26 Oct 2023 18:02:34 -0400 Subject: [PATCH 13/14] restore workflow --- .github/workflows/build_wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 2549907b..58ce8189 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -54,7 +54,7 @@ jobs: CIBW_ENVIRONMENT_LINUX: LD_LIBRARY_PATH="/tmp/filepattern_bld/local_install/lib:/tmp/filepattern_bld/local_install/lib64:$LD_LIBRARY_PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="/tmp/filepattern_bld/local_install" CIBW_ENVIRONMENT_WINDOWS: PATH="$TEMP\\filepattern\\bin;$PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="C:\\TEMP\\filepattern_bld\\local_install" CIBW_REPAIR_WHEEL_COMMAND_MACOS: DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} && DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel} - CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: xcopy /E /I /y D:/a/filepattern/filepattern/build/temp.win-amd64-cpython-39/Release/third-party/Release C:/TEMP/filepattern_bld/local_install && delvewheel repair -w {dest_dir} {wheel} + CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel}" CIBW_ARCHS: ${{ matrix.cibw_archs }} CIBW_TEST_REQUIRES: pytest pydantic CIBW_TEST_COMMAND: pytest {project}/tests/ From 5229bf7411b07a1f0d5a78bd96271dda87900d17 Mon Sep 17 00:00:00 2001 From: sameeul Date: Thu, 26 Oct 2023 18:12:47 -0400 Subject: [PATCH 14/14] update workflow --- .github/workflows/build_wheels.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 58ce8189..ab254844 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -54,7 +54,6 @@ jobs: CIBW_ENVIRONMENT_LINUX: LD_LIBRARY_PATH="/tmp/filepattern_bld/local_install/lib:/tmp/filepattern_bld/local_install/lib64:$LD_LIBRARY_PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="/tmp/filepattern_bld/local_install" CIBW_ENVIRONMENT_WINDOWS: PATH="$TEMP\\filepattern\\bin;$PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="C:\\TEMP\\filepattern_bld\\local_install" CIBW_REPAIR_WHEEL_COMMAND_MACOS: DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} && DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel} - CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel}" CIBW_ARCHS: ${{ matrix.cibw_archs }} CIBW_TEST_REQUIRES: pytest pydantic CIBW_TEST_COMMAND: pytest {project}/tests/