From 9f3f366deec411675cc21c2fceaa7ac090d03a4c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 29 Sep 2018 14:24:03 +0200 Subject: Remove project.tests, always use tests subdir --- src/Conf.cpp | 72 ++++++++++++++++++++++++++++++++---------------------------- src/main.cpp | 4 ++-- 2 files changed, 41 insertions(+), 35 deletions(-) (limited to 'src') 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 Config::readFromFile(const _tinydir_char_t *filepath, ConfigCallback &callback) + Result Config::readFromFile(const _tinydir_char_t *filepath, SibsConfig &config) { Result 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 parseResult = Parser::parse(code, config); + if(!parseResult) + return Result::Err("Failed to read config for: " + parseResult.getErrMsg()); + + if(!config.isTest()) + { + if(config.getPackageName().empty()) + return Result::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::Err(errMsg); + } + + FileString testsDir = config.getProjectPath() + TINYDIR_STRING("/tests"); + if(getFileType(testsDir.c_str()) == FileType::DIRECTORY) + { + Result 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 &platforms, Platform platform) @@ -475,29 +505,12 @@ namespace sibs void readSibsConfig(const FileString &projectPath, const FileString &projectConfFilePath, SibsConfig &sibsConfig, FileString &buildPath) { Result 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 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); } -- cgit v1.2.3