aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/ninja/Ninja.cpp3
-rw-r--r--include/FileUtil.hpp9
-rw-r--r--src/CmakeModule.cpp8
-rw-r--r--src/FileUtil.cpp31
4 files changed, 47 insertions, 4 deletions
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index 69b480e..87370cf 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -1295,6 +1295,8 @@ namespace backend
projectGeneratedBinary += "/";
string noUndefinedFlag;
+// TODO: This causes issues with -ldl in bgfx example, where dlclose symbol is not found even though it's linked with -ldl
+#if 0
if(!onlyZigFiles)
{
bool isCompilerClangLike = (compilerType == RuntimeCompilerType::CLANG) || (compilerType == RuntimeCompilerType::EMSCRIPTEN);
@@ -1303,6 +1305,7 @@ namespace backend
else
noUndefinedFlag = isCompilerClangLike ? "-Wl,-undefined,error" : "-Wl,--no-undefined,--as-needed";
}
+#endif
ninja::NinjaVariable zigObjectArgs("object_args");
string objectZigArgs;
diff --git a/include/FileUtil.hpp b/include/FileUtil.hpp
index d740fff..b88d58a 100644
--- a/include/FileUtil.hpp
+++ b/include/FileUtil.hpp
@@ -41,6 +41,14 @@ namespace sibs
// Return true if you want to continue iterating the remaining files, return false if you want to stop
using FileWalkCallbackFunc = std::function<bool(tinydir_file*)>;
+ struct FileWithTimestamp {
+ FileString filepath;
+ FileString extension;
+ struct timespec last_modified;
+ };
+
+ using SortedFileWalkCallbackFunc = std::function<bool(const FileWithTimestamp&)>;
+
enum class FileType
{
FILE_NOT_FOUND,
@@ -52,6 +60,7 @@ namespace sibs
void walkDir(const _tinydir_char_t *directory, FileWalkCallbackFunc callbackFunc);
void walkDirFiles(const _tinydir_char_t *directory, FileWalkCallbackFunc callbackFunc);
bool walkDirFilesRecursive(const _tinydir_char_t *directory, FileWalkCallbackFunc callbackFunc);
+ bool walkDirFilesRecursiveSortTimestamp(const _tinydir_char_t *directory, SortedFileWalkCallbackFunc callbackFunc);
Result<StringView> getFileContent(const _tinydir_char_t *filepath);
Result<bool> fileWrite(const _tinydir_char_t *filepath, StringView data);
Result<bool> fileOverwrite(const _tinydir_char_t *filepath, StringView data);
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