From 94caff5f66cacdd21e5a93cd3de9150a22eeaa3a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 16 Dec 2017 04:21:33 +0100 Subject: Add support for sub project (unit tests) --- src/GlobalLib.cpp | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'src/GlobalLib.cpp') 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 GlobalLib::getLibsLinkerFlags(const string &globalLibRootDir, const string &name, const string &version, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc) { Result packageExistsResult = validatePackageExists(globalLibRootDir, name); @@ -105,7 +110,7 @@ namespace sibs } } - SibsConfig sibsConfig; + SibsConfig sibsConfig(packageDir); Result result = Config::readFromFile(projectConfFilePath.c_str(), sibsConfig); if(result.isErr()) return Result::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::Ok("No source files in dependency (header only library?)"); @@ -183,7 +203,7 @@ namespace sibs if(createBuildDirResult.isErr()) return Result::Err(createBuildDirResult); - Result buildFileResult = ninja.createBuildFile(sibsConfig.getPackageName(), sibsConfig.getDependencies(), debugBuildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc); + Result buildFileResult = ninja.createBuildFile(sibsConfig, debugBuildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc); if (buildFileResult.isErr()) return Result::Err(buildFileResult.getErrMsg()); -- cgit v1.2.3