aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2017-12-16 04:21:33 +0100
committerdec05eba <dec05eba@protonmail.com>2017-12-16 04:21:44 +0100
commit94caff5f66cacdd21e5a93cd3de9150a22eeaa3a (patch)
treeb3b7689e5a25c908369bb5fad5a59e085253b76e /src/main.cpp
parent28d6b571139998915bce147abb58617884431192 (diff)
Add support for sub project (unit tests)
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 9d6c88e..c1ce277 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -18,6 +18,8 @@ using namespace sibs;
// Either do not follow the symlinks or use a hash map with every searched directory
// to only go inside a directory once
+// TODO: Places that use PATH_MAX should be modified. A path CAN be longer than PATH_MAX... (does this include replacing tinydir.h?)
+
void usage()
{
printf("Usage: sibs COMMAND\n\n");
@@ -91,6 +93,11 @@ bool isSourceFile(tinydir_file *file)
return false;
}
+bool isPathSubPathOf(const char *path, const string &subPathOf)
+{
+ return _tinydir_strncmp(path, subPathOf.c_str(), subPathOf.size()) == 0;
+}
+
int buildProject(int argc, const char **argv)
{
if(argc > 1)
@@ -113,7 +120,7 @@ int buildProject(int argc, const char **argv)
projectConfFilePath += "/project.conf";
validateFilePath(projectConfFilePath.c_str());
- SibsConfig sibsConfig;
+ SibsConfig sibsConfig(projectPath);
Result<bool> result = Config::readFromFile(projectConfFilePath.c_str(), sibsConfig);
if(result.isErr())
{
@@ -147,20 +154,32 @@ int buildProject(int argc, const char **argv)
}
backend::Ninja ninja(libraryType);
- walkDirFilesRecursive(projectPath.c_str(), [&ninja, &projectPath](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 + projectPath.size());
- ninja.addSourceFile(file->path + projectPath.size());
- } else
+ if (isSourceFile(file))
+ {
+ ninja.addSourceFile(file->path + sibsConfig.getProjectPath().size());
+ }
+ else
+ {
+ //printf("Ignoring non-source file: %s\n", file->path + projectPath.size());
+ }
+ }
+ else
{
- //printf("Ignoring non-source file: %s\n", file->path + projectPath.size());
+ // TODO: If compiling without "test" option, do not add test source dir to ninja. Ninja logic will then not build tests
+ if(!sibsConfig.getTestPath().empty() && isPathSubPathOf(file->path, sibsConfig.getTestPath()))
+ ninja.addTestSourceDir(file->path);
+ else
+ walkDir(file->path, collectSourceFiles);
}
- });
+ };
+ walkDir(projectPath.c_str(), collectSourceFiles);
string debugBuildPath = projectPath + "/sibs-build/debug";
- Result<bool> buildFileResult = ninja.createBuildFile(sibsConfig.getPackageName(), sibsConfig.getDependencies(), debugBuildPath.c_str());
+ Result<bool> buildFileResult = ninja.createBuildFile(sibsConfig, debugBuildPath.c_str());
if(buildFileResult.isErr())
{
cerr << "Failed to build ninja file: " << buildFileResult.getErrMsg() << endl;