aboutsummaryrefslogtreecommitdiff
path: root/src/Conf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Conf.cpp')
-rw-r--r--src/Conf.cpp72
1 files changed, 39 insertions, 33 deletions
diff --git a/src/Conf.cpp b/src/Conf.cpp
index 695bc9e..40ff018 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -445,7 +445,7 @@ namespace sibs
bool objectDefined;
};
- Result<bool> Config::readFromFile(const _tinydir_char_t *filepath, ConfigCallback &callback)
+ Result<bool> Config::readFromFile(const _tinydir_char_t *filepath, SibsConfig &config)
{
Result<StringView> fileContentResult = getFileContent(filepath);
if(fileContentResult.isErr())
@@ -459,7 +459,37 @@ namespace sibs
code += 3;
// Do not free file content (fileContentResult) on purpose, since we are using the data and sibs is short lived
- return Parser::parse(code, callback);
+ Result<bool> parseResult = Parser::parse(code, config);
+ if(!parseResult)
+ return Result<bool>::Err("Failed to read config for: " + parseResult.getErrMsg());
+
+ if(!config.isTest())
+ {
+ if(config.getPackageName().empty())
+ return Result<bool>::Err("project.conf is missing required field package.name");
+
+ if (!containsPlatform(config.getPlatforms(), SYSTEM_PLATFORM))
+ {
+ string errMsg = "The project ";
+ errMsg += config.getPackageName();
+ errMsg += " does not support your platform (";
+ errMsg += asString(SYSTEM_PLATFORM);
+ errMsg += ")";
+ return Result<bool>::Err(errMsg);
+ }
+
+ FileString testsDir = config.getProjectPath() + TINYDIR_STRING("/tests");
+ if(getFileType(testsDir.c_str()) == FileType::DIRECTORY)
+ {
+ Result<FileString> testRealPathResult = getRealPath(testsDir.c_str());
+ if(testRealPathResult)
+ config.setTestPath(testRealPathResult.unwrap());
+ else
+ fprintf(stderr, "Warning: Project contains tests directory but we got an error while retrieving the full path to it\n");
+ }
+ }
+
+ return parseResult;
}
bool containsPlatform(const vector<Platform> &platforms, Platform platform)
@@ -475,29 +505,12 @@ namespace sibs
void readSibsConfig(const FileString &projectPath, const FileString &projectConfFilePath, SibsConfig &sibsConfig, FileString &buildPath)
{
Result<bool> result = Config::readFromFile(projectConfFilePath.c_str(), sibsConfig);
- if(result.isErr())
+ if(!result)
{
ferr << "Failed to read config: " << toFileString(result.getErrMsg()) << endl;
exit(6);
}
- if(sibsConfig.getPackageName().empty())
- {
- ferr << "project.conf is missing required field package.name" << endl;
- exit(10);
- }
-
- if (!containsPlatform(sibsConfig.getPlatforms(), SYSTEM_PLATFORM))
- {
- string errMsg = "The project ";
- errMsg += sibsConfig.getPackageName();
- errMsg += " does not support your platform (";
- errMsg += asString(SYSTEM_PLATFORM);
- errMsg += ")";
- cerr << errMsg << endl;
- exit(11);
- }
-
buildPath = projectPath + TINYDIR_STRING("/sibs-build/");
switch(sibsConfig.getOptimizationLevel())
{
@@ -729,21 +742,14 @@ namespace sibs
{
if (value.isSingle())
{
- testPath = projectPath;
- testPath += TINYDIR_STRING("/");
-#if OS_FAMILY == OS_FAMILY_POSIX
- testPath += FileString(value.asSingle().data, value.asSingle().size);
-#else
- testPath += utf8To16(value.asSingle());
-#endif
- Result<FileString> testRealPathResult = getRealPath(testPath.c_str());
- if(!testRealPathResult)
+ if(value.asSingle().equals("tests"))
{
- string errMsg = "Failed to resolve package.tests path: ";
- errMsg += testRealPathResult.getErrMsg();
- throw ParserException(errMsg);
+ fprintf(stderr, "Warning: package.tests is deprecated, a subdirectory called tests is now automatically chosen as the tests directory\n");
+ }
+ else
+ {
+ throw ParserException("package.tests is a deprecated field and can only be defined as \"tests\" if it's defined");
}
- testPath = testRealPathResult.unwrap();
}
else
throw ParserException("Expected package.tests to be a single value, was a list");