From 2698cbc14f8a2a108a3252f03e053cb47b8b5101 Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Sun, 23 Sep 2018 12:21:06 +0200 Subject: Add build depends --- include/ninja/Ninja.hpp | 9 ++++++--- src/Ninja.cpp | 30 +++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/include/ninja/Ninja.hpp b/include/ninja/Ninja.hpp index e2b4ab5..d0e3d50 100644 --- a/include/ninja/Ninja.hpp +++ b/include/ninja/Ninja.hpp @@ -69,12 +69,14 @@ namespace ninja const std::string value; }; + class NinjaBuild; + // 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); + NinjaBuild* build(const std::string &in, const std::string &out, const std::vector &additionalArgs, const std::vector &dependsOnBuilds = {}); const std::string name; const std::string command; @@ -89,6 +91,7 @@ namespace ninja const std::string in; const std::string out; const std::vector additionalArgs; + const std::vector dependsOnBuilds; }; // Functions throw NinjaException on failure @@ -99,12 +102,12 @@ namespace ninja 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); + NinjaBuild* build(const NinjaRule *rule, const std::string &in, const std::string &out, const std::vector &additionalArgs, const std::vector &dependsOnBuilds = {}); std::string generate() const; private: std::unordered_map globalVariables; std::unordered_map rules; - std::vector builds; + std::vector builds; }; } \ No newline at end of file diff --git a/src/Ninja.cpp b/src/Ninja.cpp index f74ab04..9b9e177 100644 --- a/src/Ninja.cpp +++ b/src/Ninja.cpp @@ -95,9 +95,9 @@ namespace ninja } } - void NinjaRule::build(const std::string &in, const std::string &out, const std::vector &additionalArgs) + NinjaBuild* NinjaRule::build(const std::string &in, const std::string &out, const std::vector &additionalArgs, const std::vector &dependsOnBuilds) { - buildFile->build(this, in, out, additionalArgs); + return buildFile->build(this, in, out, additionalArgs, dependsOnBuilds); } void NinjaBuildFile::defineGlobalVariable(const std::string &name, const std::string &value) @@ -125,9 +125,11 @@ namespace ninja return rule; } - void NinjaBuildFile::build(const NinjaRule *rule, const std::string &in, const std::string &out, const std::vector &additionalArgs) + NinjaBuild* NinjaBuildFile::build(const NinjaRule *rule, const std::string &in, const std::string &out, const std::vector &additionalArgs, const std::vector &dependsOnBuilds) { - builds.push_back({ rule, in, out, additionalArgs }); + NinjaBuild *build = new NinjaBuild { rule, in, out, additionalArgs, dependsOnBuilds }; + builds.push_back(build); + return build; } std::string NinjaBuildFile::generate() const @@ -159,15 +161,25 @@ namespace ninja } // TODO: enclose all names with quotes to escape whitespace? - for(const NinjaBuild &build : builds) + for(const NinjaBuild *build : builds) { result += "build "; - result += build.out; + result += build->out; result += ": "; - result += build.rule->name; + result += build->rule->name; result += ' '; - result += build.in; - for(const NinjaArgValue &additionalArg : build.additionalArgs) + result += build->in; + + if(!build->dependsOnBuilds.empty()) + { + result += " ||"; + for(const NinjaBuild *dependsOnBuild : build->dependsOnBuilds) + { + result += ' ' + dependsOnBuild->out; + } + } + + for(const NinjaArgValue &additionalArg : build->additionalArgs) { result += "\n "; result += additionalArg.arg.name; -- cgit v1.2.3