diff options
author | dec05eba <dec05eba@protonmail.com> | 2017-12-16 04:21:33 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2017-12-16 04:21:44 +0100 |
commit | 94caff5f66cacdd21e5a93cd3de9150a22eeaa3a (patch) | |
tree | b3b7689e5a25c908369bb5fad5a59e085253b76e /src/GlobalLib.cpp | |
parent | 28d6b571139998915bce147abb58617884431192 (diff) |
Add support for sub project (unit tests)
Diffstat (limited to 'src/GlobalLib.cpp')
-rw-r--r-- | src/GlobalLib.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index a07e23d..c38e22f 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -55,6 +55,11 @@ namespace sibs return false; } + bool isPathSubPathOf(const char *path, const string &subPathOf) + { + return _tinydir_strncmp(path, subPathOf.c_str(), subPathOf.size()) == 0; + } + Result<string> GlobalLib::getLibsLinkerFlags(const string &globalLibRootDir, const string &name, const string &version, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc) { Result<bool> packageExistsResult = validatePackageExists(globalLibRootDir, name); @@ -105,7 +110,7 @@ namespace sibs } } - SibsConfig sibsConfig; + SibsConfig sibsConfig(packageDir); Result<bool> result = Config::readFromFile(projectConfFilePath.c_str(), sibsConfig); if(result.isErr()) return Result<string>::Err(result.getErrMsg()); @@ -137,18 +142,33 @@ namespace sibs } backend::Ninja ninja(libraryType); - walkDirFilesRecursive(packageDir.c_str(), [&ninja, &packageDir](tinydir_file *file) + FileWalkCallbackFunc collectSourceFiles = [&ninja, &sibsConfig, &collectSourceFiles](tinydir_file *file) { - if (isSourceFile(file)) + if(file->is_reg) { - printf("Adding source file: %s\n", file->path + packageDir.size() + 1); - ninja.addSourceFile(file->path + packageDir.size() + 1); - } else + if (isSourceFile(file)) + { + ninja.addSourceFile(file->path + sibsConfig.getProjectPath().size() + 1); + } + else + { + //printf("Ignoring non-source file: %s\n", file->path + projectPath.size()); + } + } + else { - //printf("Ignoring non-source file: %s\n", file->path + packageDir.size() + 1); + // TODO: If compiling without "test" option, do not add test source dir to ninja. Ninja logic will then not build tests... + // OR I believe there is no reason to run tests in dependencies. The main projects tests should cover that? + // But you might want to know exactly which dependency is causing issue and which part of it... + if(!sibsConfig.getTestPath().empty() && isPathSubPathOf(file->path, sibsConfig.getTestPath())) + ninja.addTestSourceDir(file->path); + else + walkDir(file->path, collectSourceFiles); } - }); + }; + walkDir(packageDir.c_str(), collectSourceFiles); + // TODO: Dont do this. Unit tests wont be built. Need to call the below ninja.createBuildFile if(ninja.getSourceFiles().empty()) { return Result<string>::Ok("No source files in dependency (header only library?)"); @@ -183,7 +203,7 @@ namespace sibs if(createBuildDirResult.isErr()) return Result<string>::Err(createBuildDirResult); - Result<bool> buildFileResult = ninja.createBuildFile(sibsConfig.getPackageName(), sibsConfig.getDependencies(), debugBuildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc); + Result<bool> buildFileResult = ninja.createBuildFile(sibsConfig, debugBuildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc); if (buildFileResult.isErr()) return Result<string>::Err(buildFileResult.getErrMsg()); |