aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Conf.cpp72
-rw-r--r--src/main.cpp4
2 files changed, 41 insertions, 35 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");
diff --git a/src/main.cpp b/src/main.cpp
index 1da5202..334f972 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -29,7 +29,7 @@ using namespace std::chrono;
// TODO: Remove install.sh when sibs supports installation of packages (so it can install itself)
-// TODO: Move package tests, include_dirs and ignore_dirs under config in project.conf.
+// TODO: Move package include_dirs and ignore_dirs under config in project.conf.
// Package object should only contain metadata for the package, which is used for finding dependencies
// and when building a list of installed packages / available packages.
@@ -396,7 +396,7 @@ static int buildProject(const FileString &projectPath, const FileString &project
if(sibsConfig.shouldBuildTests() && sibsConfig.getTestPath().empty() && !sibsConfig.zigTestAllFiles && sibsConfig.zigTestFiles.empty())
{
- printf("Project is missing package.tests config. No tests to build\n");
+ printf("Project is missing tests subdirectory. No tests to build\n");
exit(50);
}