diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CmakeModule.cpp | 8 | ||||
-rw-r--r-- | src/FileUtil.cpp | 31 |
2 files changed, 35 insertions, 4 deletions
diff --git a/src/CmakeModule.cpp b/src/CmakeModule.cpp index 9e399ac..8c97b6e 100644 --- a/src/CmakeModule.cpp +++ b/src/CmakeModule.cpp @@ -276,13 +276,13 @@ namespace sibs string buildPathUtf8 = toUtf8(buildPath); nprintf("Searching for libraries generate by cmake in build path: %s\n", buildPathUtf8.c_str()); - walkDirFilesRecursive(buildPath.c_str(), - [&config, &parentProjStaticLinkerFlagCallbackFunc, &parentProjDynamicLinkerFlagCallbackFunc, dynamicLibExtension](tinydir_file *file) + walkDirFilesRecursiveSortTimestamp(buildPath.c_str(), + [&config, &parentProjStaticLinkerFlagCallbackFunc, &parentProjDynamicLinkerFlagCallbackFunc, dynamicLibExtension](const FileWithTimestamp &filedata) { bool isStatic = config.getPackageType() == PackageType::STATIC; - if((!isStatic && _tinydir_strcmp(file->extension, dynamicLibExtension) == 0) || (isStatic && _tinydir_strcmp(file->extension, CONFIG_STATIC_LIB_FILE_EXTENSION) == 0)) + if((!isStatic && _tinydir_strcmp(filedata.extension.c_str(), dynamicLibExtension) == 0) || (isStatic && _tinydir_strcmp(filedata.extension.c_str(), CONFIG_STATIC_LIB_FILE_EXTENSION) == 0)) { - string libFileUtf8 = toUtf8(file->path); + string libFileUtf8 = toUtf8(filedata.filepath); nprintf("Library generated by cmake: %s\n", libFileUtf8.c_str()); switch(config.getPackageType()) diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp index 2a0b290..b78e257 100644 --- a/src/FileUtil.cpp +++ b/src/FileUtil.cpp @@ -1,5 +1,7 @@ #include "../include/FileUtil.hpp" #include <cstdio> +#include <vector> +#include <algorithm> #if OS_FAMILY == OS_FAMILY_POSIX #include <unistd.h> @@ -249,6 +251,35 @@ namespace sibs return true; } + bool walkDirFilesRecursiveSortTimestamp(const _tinydir_char_t *directory, SortedFileWalkCallbackFunc callbackFunc) + { + std::vector<FileWithTimestamp> files; + walkDirFilesRecursive(directory, [&files](tinydir_file *file) { + FileWithTimestamp filedata; + filedata.filepath = file->path; + filedata.extension = file->extension; + filedata.last_modified = file->_s.st_mtim; + files.push_back(std::move(filedata)); + return true; + }); + + std::sort(files.begin(), files.end(), [](const FileWithTimestamp &filedata_a, const FileWithTimestamp &filedata_b) { + if(filedata_a.last_modified.tv_sec < filedata_b.last_modified.tv_sec) + return true; + else if(filedata_a.last_modified.tv_sec == filedata_b.last_modified.tv_sec && filedata_a.last_modified.tv_nsec <= filedata_b.last_modified.tv_nsec) + return true; + else + return false; + }); + + for(const FileWithTimestamp &filedata : files) { + if(!callbackFunc(filedata)) + return false; + } + + return true; + } + Result<StringView> getFileContent(const _tinydir_char_t *filepath) { #if OS_FAMILY == OS_FAMILY_POSIX |