aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--examples/hello_world_c_zig/project.conf5
-rw-r--r--examples/hello_world_cpp/project.conf1
-rw-r--r--include/Conf.hpp12
-rw-r--r--project.conf1
-rw-r--r--src/Conf.cpp72
-rw-r--r--src/main.cpp4
7 files changed, 50 insertions, 51 deletions
diff --git a/README.md b/README.md
index beb2260..59560d7 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,8 @@ Dependencies that are required to build sibs from source are:
# IDE support
Sibs generates a compile_commands.json in the project root directory when executing `sibs build` and tools that support clang completion can be used, such as YouCompleteMe.
There are several editors that support YouCompleteMe, including Vim, Emacs and Visual Studio Code.
+# Tests
+If your project contains a sub directory called "tests" then that directory will be used a test project. The test directory may contain a project.conf file which can contain \[dependencies] block for specifying test only dependencies. The test automatically includes the parent project as a dependency.
# Project configuration template
```toml
[package]
@@ -43,7 +45,6 @@ type = "library"
version = "0.1.0"
platforms = ["linux32", "linux64", "win32", "win64"]
authors = ["DEC05EBA <0xdec05eba@gmail.com>"]
-tests = "tests"
include_dirs = ["include"]
ignore_dirs = ["examples"]
@@ -106,9 +107,6 @@ If platforms contains "any", then other there is no need to specify other platfo
### authors
Optional. A list of authors
-### tests
-Optional. Path which contains tests. The test directory may contain a project.conf file which can contain \[dependencies] block for specifying test only dependencies. The test automatically includes the parent project as a dependency.
-
### include_dirs
Optional. A list of directories which should be specified as global include directories when compiling. This means that instead of using relative paths to header files, you can include the directory with headers and then you only have to specify the header name when using #include
diff --git a/examples/hello_world_c_zig/project.conf b/examples/hello_world_c_zig/project.conf
index fa006cd..da589b2 100644
--- a/examples/hello_world_c_zig/project.conf
+++ b/examples/hello_world_c_zig/project.conf
@@ -2,7 +2,4 @@
name = "hello_world_c_zig"
type = "executable"
version = "0.1.0"
-platforms = ["linux64"]
-tests = "tests"
-
-[dependencies]
+platforms = ["any"]
diff --git a/examples/hello_world_cpp/project.conf b/examples/hello_world_cpp/project.conf
index 4c05ce5..78ed870 100644
--- a/examples/hello_world_cpp/project.conf
+++ b/examples/hello_world_cpp/project.conf
@@ -3,4 +3,3 @@ name = "hello_world"
type = "executable"
version = "0.1.0"
platforms = ["any"]
-tests = "tests"
diff --git a/include/Conf.hpp b/include/Conf.hpp
index dd8b003..35dab86 100644
--- a/include/Conf.hpp
+++ b/include/Conf.hpp
@@ -96,12 +96,6 @@ namespace sibs
virtual void finished() = 0;
};
- class Config
- {
- public:
- static Result<bool> readFromFile(const _tinydir_char_t *filepath, ConfigCallback &callback);
- };
-
enum OptimizationLevel
{
OPT_LEV_NONE,
@@ -497,6 +491,12 @@ namespace sibs
void processField(StringView name, const ConfigValue &value) override;
void finished() override;
};
+
+ class Config
+ {
+ public:
+ static Result<bool> readFromFile(const _tinydir_char_t *filepath, SibsConfig &config);
+ };
void readSibsConfig(const FileString &projectPath, const FileString &projectConfFilePath, SibsConfig &sibsConfig, FileString &buildPath);
}
diff --git a/project.conf b/project.conf
index c02ba9b..968c8af 100644
--- a/project.conf
+++ b/project.conf
@@ -3,7 +3,6 @@ name = "sibs"
type = "executable"
version = "0.1.5"
authors = ["DEC05EBA <0xdec05eba@gmail.com>"]
-tests = "tests"
platforms = ["linux32", "linux64", "win64"]
ignore_dirs = ["cmake", "cmake-build-debug", "build", "distribute", "examples", "msvc", "cmake_msvc"]
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);
}