diff options
-rw-r--r-- | include/Conf.hpp | 16 | ||||
-rw-r--r-- | include/Package.hpp | 13 | ||||
-rw-r--r-- | src/Conf.cpp | 39 | ||||
-rw-r--r-- | src/GlobalLib.cpp | 8 |
4 files changed, 65 insertions, 11 deletions
diff --git a/include/Conf.hpp b/include/Conf.hpp index 3634f4c..c792075 100644 --- a/include/Conf.hpp +++ b/include/Conf.hpp @@ -5,6 +5,7 @@ #include "StringView.hpp" #include "utils.hpp" #include "Dependency.hpp" +#include "Package.hpp" #include <vector> #include <cassert> #include <stdexcept> @@ -84,7 +85,7 @@ namespace sibs class SibsConfig : public ConfigCallback { public: - SibsConfig() : finishedProcessing(false) {} + SibsConfig() : finishedProcessing(false), packageType((PackageType)-1) {} const std::string& getPackageName() const { @@ -92,6 +93,12 @@ namespace sibs return packageName; } + PackageType getPackageType() const + { + assert(finishedProcessing); + return packageType; + } + const std::vector<Dependency>& getDependencies() const { return dependencies; @@ -99,14 +106,11 @@ namespace sibs protected: void processObject(StringView name) override; void processField(StringView name, const ConfigValue &value) override; - - void finished() override - { - finishedProcessing = true; - } + void finished() override; private: StringView currentObject; std::string packageName; + PackageType packageType; std::vector<Dependency> dependencies; bool finishedProcessing; }; diff --git a/include/Package.hpp b/include/Package.hpp new file mode 100644 index 0000000..130e987 --- /dev/null +++ b/include/Package.hpp @@ -0,0 +1,13 @@ +#ifndef SIBS_PACKAGE_HPP +#define SIBS_PACKAGE_HPP + +namespace sibs +{ + enum class PackageType : int + { + EXECUTABLE, + LIBRARY + }; +} + +#endif //SIBS_PACKAGE_HPP diff --git a/src/Conf.cpp b/src/Conf.cpp index 107ad0a..8dd7608 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -362,12 +362,34 @@ namespace sibs printf("\n"); */ - if(currentObject.equals("package") && name.equals("name")) + if(currentObject.equals("package")) { - if(value.isSingle()) - packageName = string(value.asSingle().data, value.asSingle().size); - else - throw ParserException("Expected package.name to be a single value, was a list"); + if(name.equals("name")) + { + if (value.isSingle()) + packageName = string(value.asSingle().data, value.asSingle().size); + else + throw ParserException("Expected package.name to be a single value, was a list"); + } + else if(name.equals("type")) + { + if (value.isSingle()) + { + const StringView &packageTypeStr = value.asSingle(); + if(packageTypeStr.equals("executable")) + packageType = PackageType::EXECUTABLE; + else if(packageTypeStr.equals("library")) + packageType = PackageType::LIBRARY; + else + { + string errMsg = "Expected package.type to be either 'executable' or 'library', was: "; + errMsg += string(packageTypeStr.data, packageTypeStr.size); + throw ParserException(errMsg); + } + } + else + throw ParserException("Expected package.type to be a single value, was a list"); + } } else if(currentObject.equals("dependencies")) { @@ -383,4 +405,11 @@ namespace sibs throw ParserException("Expected field under dependencies to be a single value, was a list"); } } + + void SibsConfig::finished() + { + if((int)packageType == -1) + throw ParserException("Missing required config package.type. Expected to be one either 'executable' or 'library'"); + finishedProcessing = true; + } }
\ No newline at end of file diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index cbd822e..7503a7a 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -111,6 +111,14 @@ namespace sibs if(sibsConfig.getPackageName().empty()) return Result<string>::Err("project.conf is missing required field package.name"); + if(sibsConfig.getPackageType() == PackageType::EXECUTABLE) + { + string errMsg = "The dependency "; + errMsg += name; + errMsg += " is an executable. Only libraries can be dependencies"; + return Result<string>::Err(errMsg); + } + backend::Ninja ninja(backend::Ninja::LibraryType::STATIC); walkDirFilesRecursive(packageDir.c_str(), [&ninja, &packageDir](tinydir_file *file) { |