aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-01-03 21:17:49 +0100
committerdec05eba <dec05eba@protonmail.com>2018-01-03 21:42:51 +0100
commit8b052110d8802eda3d4d76700bde8ecc80dbf79a (patch)
tree13d9248067ba61c159e61f6083e090b26916c22f /src
parent469a67628f3eb18236ee44e948d1ae0f0e6b1a4a (diff)
Add "sibs test" command. Tests are only run when that command is invoked
Diffstat (limited to 'src')
-rw-r--r--src/Conf.cpp8
-rw-r--r--src/GlobalLib.cpp2
-rw-r--r--src/main.cpp208
3 files changed, 140 insertions, 78 deletions
diff --git a/src/Conf.cpp b/src/Conf.cpp
index 1697d9f..0bbbf7b 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -867,24 +867,24 @@ namespace sibs
if(useCmake)
{
- switch(getPackageType())
+ switch(packageType)
{
case PackageType::EXECUTABLE:
{
- if(!getCmakeDir().empty())
+ if(getCmakeDir().empty())
throw ParserException("Missing required config cmake.dir");
break;
}
case PackageType::STATIC:
{
- if(!getCmakeDirStatic().empty())
+ if(getCmakeDirStatic().empty())
throw ParserException("Missing required config cmake.static");
break;
}
case PackageType::DYNAMIC:
case PackageType::LIBRARY:
{
- if(!getCmakeDirDynamic().empty())
+ if(getCmakeDirDynamic().empty())
throw ParserException("Missing required config cmake.dynamic");
break;
}
diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp
index 9083354..d3131a1 100644
--- a/src/GlobalLib.cpp
+++ b/src/GlobalLib.cpp
@@ -123,7 +123,7 @@ namespace sibs
}
}
- SibsConfig sibsConfig(parentConfig.getCompiler(), packageDir, parentConfig.getOptimizationLevel());
+ SibsConfig sibsConfig(parentConfig.getCompiler(), packageDir, parentConfig.getOptimizationLevel(), false);
Result<bool> result = Config::readFromFile(projectConfFilePath.c_str(), sibsConfig);
if (result.isErr())
return result;
diff --git a/src/main.cpp b/src/main.cpp
index e2df0fe..f16bf64 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -56,6 +56,7 @@ void usage()
printf("Commands:\n");
printf(" build\t\tBuild a project that contains a project.conf file\n");
printf(" new\t\tCreate a new project\n");
+ printf(" test\t\tBuild and run tests for a sibs project\n");
exit(1);
}
@@ -88,6 +89,18 @@ void usageNew()
exit(1);
}
+void usageTest()
+{
+ printf("Usage: sibs test [project_path]\n\n");
+ printf("Build and run tests for a sibs project\n\n");
+ printf("Options:\n");
+ printf(" project_path\t\t The directory containing a project.conf file - Optional (default: current working directory)\n");
+ printf("Examples:\n");
+ printf(" sibs test\n");
+ printf(" sibs test dirA/dirB\n");
+ exit(1);
+}
+
void validateDirectoryPath(const _tinydir_char_t *projectPath)
{
FileType projectPathFileType = getFileType(projectPath);
@@ -142,78 +155,8 @@ bool isPathSubPathOf(const FileString &path, const FileString &subPathOf)
return _tinydir_strncmp(path.c_str(), subPathOf.c_str(), subPathOf.size()) == 0;
}
-int buildProject(int argc, const _tinydir_char_t **argv)
+int buildProject(const FileString &projectPath, const FileString &projectConfFilePath, const SibsConfig &sibsConfig)
{
- if(argc > 2)
- usageBuild();
-
- OptimizationLevel optimizationLevel = OPT_LEV_NONE;
- FileString projectPath;
-
- for(int i = 0; i < argc; ++i)
- {
- const _tinydir_char_t *arg = argv[i];
- if(_tinydir_strcmp(arg, TINYDIR_STRING("--debug")) == 0)
- {
- if(optimizationLevel != OPT_LEV_NONE)
- {
- ferr << "Error: Optimization level defined more than once. First defined as " << asString(optimizationLevel) << " then as debug" << endl;
- usageBuild();
- }
- optimizationLevel = OPT_LEV_DEBUG;
- }
- else if(_tinydir_strcmp(arg, TINYDIR_STRING("--release")) == 0)
- {
- if(optimizationLevel != OPT_LEV_NONE)
- {
- ferr << "Error: Optimization level defined more than once. First defined as " << asString(optimizationLevel) << " then as release" << endl;
- usageBuild();
- }
- optimizationLevel = OPT_LEV_RELEASE;
- }
- else
- {
- if(!projectPath.empty())
- {
- ferr << "Error: Project path was defined more than once. First defined as " << projectPath << " then as " << arg << endl;
- usageBuild();
- }
- projectPath = arg;
- }
- }
-
- if(optimizationLevel == OPT_LEV_NONE)
- optimizationLevel = OPT_LEV_DEBUG;
-
- // TODO: If projectPath is not defined and working directory does not contain project.conf, then search every parent directory until one is found
- if(projectPath.empty())
- projectPath = TINYDIR_STRING(".");
-
- validateDirectoryPath(projectPath.c_str());
- if(projectPath.back() != '/')
- projectPath += TINYDIR_STRING("/");
-
- Result<FileString> projectRealPathResult = getRealPath(projectPath.c_str());
- if(!projectRealPathResult)
- {
- ferr << "Failed to get real path for: '" << projectPath.c_str() << "': " << toFileString(projectRealPathResult.getErrMsg()) << endl;
- exit(40);
- }
- projectPath = projectRealPathResult.unwrap();
-
- FileString projectConfFilePath = projectPath;
- projectConfFilePath += TINYDIR_STRING("/project.conf");
- validateFilePath(projectConfFilePath.c_str());
-
- // TODO: Detect compiler to use at runtime. Should also be configurable
- // by passing argument to `sibs build`
-#if OS_FAMILY == OS_FAMILY_POSIX
- Compiler compiler = Compiler::GCC;
-#else
- Compiler compiler = Compiler::MSVC;
-#endif
-
- SibsConfig sibsConfig(compiler, projectPath, optimizationLevel);
Result<bool> result = Config::readFromFile(projectConfFilePath.c_str(), sibsConfig);
if(result.isErr())
{
@@ -285,7 +228,6 @@ int buildProject(int argc, const _tinydir_char_t **argv)
}
else
{
- // 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(pathNative.c_str(), sibsConfig.getTestPath()))
{
string filePathUtf8 = toUtf8(pathNative.c_str());
@@ -305,11 +247,127 @@ int buildProject(int argc, const _tinydir_char_t **argv)
}
}
auto elapsedTime = duration_cast<duration<double>>(high_resolution_clock::now() - startTime);
- printf("Build finished in %fs\n", elapsedTime.count());
+ printf("Finished in %fs\n", elapsedTime.count());
return 0;
}
+int buildProject(int argc, const _tinydir_char_t **argv)
+{
+ if(argc > 2)
+ usageBuild();
+
+ OptimizationLevel optimizationLevel = OPT_LEV_NONE;
+ FileString projectPath;
+
+ for(int i = 0; i < argc; ++i)
+ {
+ const _tinydir_char_t *arg = argv[i];
+ if(_tinydir_strcmp(arg, TINYDIR_STRING("--debug")) == 0)
+ {
+ if(optimizationLevel != OPT_LEV_NONE)
+ {
+ ferr << "Error: Optimization level defined more than once. First defined as " << asString(optimizationLevel) << " then as debug" << endl;
+ usageBuild();
+ }
+ optimizationLevel = OPT_LEV_DEBUG;
+ }
+ else if(_tinydir_strcmp(arg, TINYDIR_STRING("--release")) == 0)
+ {
+ if(optimizationLevel != OPT_LEV_NONE)
+ {
+ ferr << "Error: Optimization level defined more than once. First defined as " << asString(optimizationLevel) << " then as release" << endl;
+ usageBuild();
+ }
+ optimizationLevel = OPT_LEV_RELEASE;
+ }
+ else
+ {
+ if(!projectPath.empty())
+ {
+ ferr << "Error: Project path was defined more than once. First defined as " << projectPath << " then as " << arg << endl;
+ usageBuild();
+ }
+ projectPath = arg;
+ }
+ }
+
+ if(optimizationLevel == OPT_LEV_NONE)
+ optimizationLevel = OPT_LEV_DEBUG;
+
+ // TODO: If projectPath is not defined and working directory does not contain project.conf, then search every parent directory until one is found
+ if(projectPath.empty())
+ projectPath = TINYDIR_STRING(".");
+
+ validateDirectoryPath(projectPath.c_str());
+ if(projectPath.back() != '/')
+ projectPath += TINYDIR_STRING("/");
+
+ Result<FileString> projectRealPathResult = getRealPath(projectPath.c_str());
+ if(!projectRealPathResult)
+ {
+ ferr << "Failed to get real path for: '" << projectPath.c_str() << "': " << toFileString(projectRealPathResult.getErrMsg()) << endl;
+ exit(40);
+ }
+ projectPath = projectRealPathResult.unwrap();
+
+ FileString projectConfFilePath = projectPath;
+ projectConfFilePath += TINYDIR_STRING("/project.conf");
+ validateFilePath(projectConfFilePath.c_str());
+
+ // TODO: Detect compiler to use at runtime. Should also be configurable
+ // by passing argument to `sibs build`
+#if OS_FAMILY == OS_FAMILY_POSIX
+ Compiler compiler = Compiler::GCC;
+#else
+ Compiler compiler = Compiler::MSVC;
+#endif
+
+ SibsConfig sibsConfig(compiler, projectPath, optimizationLevel, false);
+ return buildProject(projectPath, projectConfFilePath, sibsConfig);
+}
+
+int testProject(int argc, const _tinydir_char_t **argv)
+{
+ if(argc > 1)
+ usageTest();
+
+ FileString projectPath;
+ if(argc == 1)
+ projectPath = argv[0];
+
+ // TODO: If projectPath is not defined and working directory does not contain project.conf, then search every parent directory until one is found
+ if(projectPath.empty())
+ projectPath = TINYDIR_STRING(".");
+
+ validateDirectoryPath(projectPath.c_str());
+ if(projectPath.back() != '/')
+ projectPath += TINYDIR_STRING("/");
+
+ Result<FileString> projectRealPathResult = getRealPath(projectPath.c_str());
+ if(!projectRealPathResult)
+ {
+ ferr << "Failed to get real path for: '" << projectPath.c_str() << "': " << toFileString(projectRealPathResult.getErrMsg()) << endl;
+ exit(40);
+ }
+ projectPath = projectRealPathResult.unwrap();
+
+ FileString projectConfFilePath = projectPath;
+ projectConfFilePath += TINYDIR_STRING("/project.conf");
+ validateFilePath(projectConfFilePath.c_str());
+
+ // TODO: Detect compiler to use at runtime. Should also be configurable
+ // by passing argument to `sibs build`
+#if OS_FAMILY == OS_FAMILY_POSIX
+ Compiler compiler = Compiler::GCC;
+#else
+ Compiler compiler = Compiler::MSVC;
+#endif
+
+ SibsConfig sibsConfig(compiler, projectPath, OPT_LEV_DEBUG, true);
+ return buildProject(projectPath, projectConfFilePath, sibsConfig);
+}
+
void newProjectCreateMainDir(const FileString &projectPath)
{
Result<bool> createProjectDirResult = createDirectoryRecursive(projectPath.c_str());
@@ -451,6 +509,10 @@ int wmain(int argc, const _tinydir_char_t **argv)
{
return newProject(subCommandArgCount, subCommandArgPtr);
}
+ else if(_tinydir_strcmp(arg, TINYDIR_STRING("test")) == 0)
+ {
+ return testProject(subCommandArgCount, subCommandArgPtr);
+ }
else
{
ferr << "Expected command to be either 'build' or 'new', was: " << arg << endl << endl;