From b8fd71aa2af110372841a1724471b8bffa4ab254 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 20 Sep 2018 06:37:59 +0200 Subject: Initial commit, works to create ninja file --- include/ninja/Ninja.hpp | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 include/ninja/Ninja.hpp (limited to 'include/ninja') diff --git a/include/ninja/Ninja.hpp b/include/ninja/Ninja.hpp new file mode 100644 index 0000000..cd9be0a --- /dev/null +++ b/include/ninja/Ninja.hpp @@ -0,0 +1,100 @@ +#pragma once + +#include +#include +#include +#include + +namespace ninja +{ + enum class NinjaError + { + NONE, + VARIABLE_ALREADY_DEFINED, + RULE_ALREADY_DEFINED, + RULE_AREADY_BUILT + }; + + class NinjaException : public std::runtime_error + { + public: + NinjaException(const NinjaError _errorCode, const std::string &errMsg = "") : + std::runtime_error(errMsg), + errorCode(_errorCode) + { + + } + + const NinjaError errorCode; + }; + + struct NinjaVariable + { + const std::string name; + }; + + class NinjaBuildFile; + + class NinjaArg + { + public: + enum class Type + { + NONE, + VALUE, + VARIABLE + }; + + NinjaArg() : type(Type::NONE) {} + NinjaArg(const std::string &value) : type(Type::VALUE), arg(value) {} + NinjaArg(const NinjaVariable &var) : type(Type::VARIABLE), arg(var.name) {} + + Type type; + std::string arg; + }; + + struct NinjaArgValue + { + const NinjaVariable arg; + const std::string value; + }; + + // Functions throw NinjaException on failure + class NinjaRule + { + public: + NinjaRule(NinjaBuildFile *buildFile, const std::string &name, const std::string &command); + void build(const std::string &in, const std::string &out, const std::vector &additionalArgs); + + const std::string name; + const std::string command; + std::string depFile; + private: + NinjaBuildFile *buildFile; + }; + + struct NinjaBuild + { + const NinjaRule *rule; + const std::string in; + const std::string out; + const std::vector additionalArgs; + }; + + // Functions throw NinjaException on failure + class NinjaBuildFile + { + public: + ~NinjaBuildFile(); + + void defineGlobalVariable(const std::string &name, const std::string &value); + NinjaRule* createRule(const std::string &name, const std::vector &commandArgs); + void build(const NinjaRule *rule, const std::string &in, const std::string &out, const std::vector &additionalArgs); + + std::string generate() const; + private: + std::unordered_map globalVariables; + std::unordered_map rules; + std::vector builds; + }; +} \ No newline at end of file -- cgit v1.2.3