diff options
| author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-09-28 17:18:59 +0900 |
|---|---|---|
| committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-09-28 17:39:18 +0900 |
| commit | f9869fcb895d9840c779e007a8d618cadf1ca4a6 (patch) | |
| tree | 663e88ef8793eadb495da8ff0e6279e9302e1bdb | |
| parent | 04756699b9a9bcd7eb2b49dd7b20a503cc5ca61a (diff) | |
| download | platform_build_kati-f9869fcb895d9840c779e007a8d618cadf1ca4a6.tar.gz platform_build_kati-f9869fcb895d9840c779e007a8d618cadf1ca4a6.tar.bz2 platform_build_kati-f9869fcb895d9840c779e007a8d618cadf1ca4a6.zip | |
[C++] Use g_flags instead of passing flags to ninja.cc
| -rw-r--r-- | main.cc | 9 | ||||
| -rw-r--r-- | ninja.cc | 99 | ||||
| -rw-r--r-- | ninja.h | 11 |
3 files changed, 39 insertions, 80 deletions
@@ -133,10 +133,7 @@ static int Run(const vector<Symbol>& targets, if (g_flags.generate_ninja && (g_flags.regen || g_flags.dump_kati_stamp)) { ScopedTimeReporter tr("regen check time"); - if (!NeedsRegen(g_flags.ninja_suffix, g_flags.ninja_dir, - g_flags.regen_ignoring_kati_binary, - g_flags.dump_kati_stamp, - start_time, orig_args)) { + if (!NeedsRegen(start_time, orig_args)) { printf("No need to regenerate ninja file\n"); return 0; } @@ -197,9 +194,7 @@ static int Run(const vector<Symbol>& targets, if (g_flags.generate_ninja) { ScopedTimeReporter tr("generate ninja time"); - GenerateNinja(g_flags.ninja_suffix, g_flags.ninja_dir, - nodes, ev, !targets.empty(), - orig_args, start_time); + GenerateNinja(nodes, ev, !targets.empty(), orig_args, start_time); return 0; } @@ -168,21 +168,12 @@ bool GetDepfileFromCommand(string* cmd, string* out) { class NinjaGenerator { public: - NinjaGenerator(const char* ninja_suffix, const char* ninja_dir, Evaluator* ev, - double start_time) + NinjaGenerator(Evaluator* ev, double start_time) : ce_(ev), ev_(ev), fp_(NULL), rule_id_(0), start_time_(start_time) { ev_->set_avoid_io(true); shell_ = ev->EvalVar(kShellSym); if (g_flags.goma_dir) gomacc_ = StringPrintf("%s/gomacc ", g_flags.goma_dir); - if (ninja_suffix) { - ninja_suffix_ = ninja_suffix; - } - if (ninja_dir) { - ninja_dir_ = ninja_dir; - } else { - ninja_dir_ = "."; - } GetExecutablePath(&kati_binary_); } @@ -200,17 +191,12 @@ class NinjaGenerator { GenerateStamp(orig_args); } - static string GetStampFilename(const char* ninja_dir, - const char* ninja_suffix) { - return StringPrintf("%s/.kati_stamp%s", - ninja_dir ? ninja_dir : ".", - ninja_suffix ? ninja_suffix : ""); + static string GetStampFilename() { + return GetFilename(".kati_stamp%s"); } - static string GetStampTempFilename(const char* ninja_dir, - const char* ninja_suffix) { - return StringPrintf( - "%s.tmp", GetStampFilename(ninja_dir, ninja_suffix).c_str()); + static string GetStampTempFilename() { + return GetFilename(".kati_stamp%s.tmp"); } private: @@ -553,21 +539,18 @@ class NinjaGenerator { } string GetNinjaFilename() const { - return StringPrintf("%s/build%s.ninja", - ninja_dir_.c_str(), ninja_suffix_.c_str()); + return GetFilename("build%s.ninja"); } string GetShellScriptFilename() const { - return StringPrintf("%s/ninja%s.sh", - ninja_dir_.c_str(), ninja_suffix_.c_str()); - } - - string GetStampFilename() const { - return GetStampFilename(ninja_dir_.c_str(), ninja_suffix_.c_str()); + return GetFilename("ninja%s.sh"); } - string GetStampTempFilename() const { - return GetStampTempFilename(ninja_dir_.c_str(), ninja_suffix_.c_str()); + static string GetFilename(const char* fmt) { + string r = g_flags.ninja_dir ? g_flags.ninja_dir : "."; + r += '/'; + r += StringPrintf(fmt, g_flags.ninja_suffix ? g_flags.ninja_suffix : ""); + return r; } void GenerateNinja(const vector<DepNode*>& nodes, @@ -588,8 +571,8 @@ class NinjaGenerator { fprintf(fp_, "\n"); } - if (ninja_dir_ != ".") { - fprintf(fp_, "builddir = %s\n\n", ninja_dir_.c_str()); + if (g_flags.ninja_dir) { + fprintf(fp_, "builddir = %s\n\n", g_flags.ninja_dir); } fprintf(fp_, "pool local_pool\n"); @@ -625,8 +608,6 @@ class NinjaGenerator { fprintf(fp, "#!/bin/sh\n"); fprintf(fp, "# Generated by kati %s\n", kGitVersion); fprintf(fp, "\n"); - if (ninja_dir_ == ".") - fprintf(fp, "cd $(dirname \"$0\")\n"); for (const auto& p : ev_->exports()) { if (p.second) { @@ -737,22 +718,18 @@ class NinjaGenerator { unordered_set<Symbol> done_; int rule_id_; string gomacc_; - string ninja_suffix_; - string ninja_dir_; string shell_; map<string, string> used_envs_; string kati_binary_; double start_time_; }; -void GenerateNinja(const char* ninja_suffix, - const char* ninja_dir, - const vector<DepNode*>& nodes, +void GenerateNinja(const vector<DepNode*>& nodes, Evaluator* ev, bool build_all_targets, const string& orig_args, double start_time) { - NinjaGenerator ng(ninja_suffix, ninja_dir, ev, start_time); + NinjaGenerator ng(ev, start_time); ng.Generate(nodes, build_all_targets, orig_args); } @@ -761,15 +738,10 @@ static bool ShouldIgnoreDirty(StringPiece s) { Pattern(g_flags.ignore_dirty_pattern).Match(s)); } -bool NeedsRegen(const char* ninja_suffix, - const char* ninja_dir, - bool ignore_kati_binary, - bool dump_kati_stamp, - double start_time, - const string& orig_args) { +bool NeedsRegen(double start_time, const string& orig_args) { bool retval = false; #define RETURN_TRUE do { \ - if (dump_kati_stamp) \ + if (g_flags.dump_kati_stamp) \ retval = true; \ else \ return true; \ @@ -791,8 +763,7 @@ bool NeedsRegen(const char* ninja_suffix, } \ }) - const string& stamp_filename = - NinjaGenerator::GetStampFilename(ninja_dir, ninja_suffix); + const string& stamp_filename = NinjaGenerator::GetStampFilename(); FILE* fp = fopen(stamp_filename.c_str(), "rb+"); if (!fp) RETURN_TRUE; @@ -804,7 +775,7 @@ bool NeedsRegen(const char* ninja_suffix, fprintf(stderr, "incomplete kati_stamp, regenerating...\n"); RETURN_TRUE; } - if (dump_kati_stamp) + if (g_flags.dump_kati_stamp) printf("Generated time: %f\n", gen_time); string s, s2; @@ -813,7 +784,7 @@ bool NeedsRegen(const char* ninja_suffix, LOAD_STRING(fp, &s); double ts = GetTimestamp(s); if (gen_time < ts) { - if (ignore_kati_binary) { + if (g_flags.regen_ignoring_kati_binary) { string kati_binary; GetExecutablePath(&kati_binary); if (s == kati_binary) { @@ -822,16 +793,16 @@ bool NeedsRegen(const char* ninja_suffix, } } if (ShouldIgnoreDirty(s)) { - if (dump_kati_stamp) + if (g_flags.dump_kati_stamp) printf("file %s: ignored (%f)\n", s.c_str(), ts); continue; } - if (dump_kati_stamp) + if (g_flags.dump_kati_stamp) printf("file %s: dirty (%f)\n", s.c_str(), ts); else fprintf(stderr, "%s was modified, regenerating...\n", s.c_str()); RETURN_TRUE; - } else if (dump_kati_stamp) { + } else if (g_flags.dump_kati_stamp) { printf("file %s: clean (%f)\n", s.c_str(), ts); } } @@ -840,14 +811,14 @@ bool NeedsRegen(const char* ninja_suffix, for (int i = 0; i < num_undefineds; i++) { LOAD_STRING(fp, &s); if (getenv(s.c_str())) { - if (dump_kati_stamp) { + if (g_flags.dump_kati_stamp) { printf("env %s: dirty (unset => %s)\n", s.c_str(), getenv(s.c_str())); } else { fprintf(stderr, "Environment variable %s was set, regenerating...\n", s.c_str()); } RETURN_TRUE; - } else if (dump_kati_stamp) { + } else if (g_flags.dump_kati_stamp) { printf("env %s: clean (unset)\n", s.c_str()); } } @@ -858,7 +829,7 @@ bool NeedsRegen(const char* ninja_suffix, StringPiece val(getenv(s.c_str())); LOAD_STRING(fp, &s2); if (val != s2) { - if (dump_kati_stamp) { + if (g_flags.dump_kati_stamp) { printf("env %s: dirty (%s => %.*s)\n", s.c_str(), s2.c_str(), SPF(val)); } else { @@ -867,7 +838,7 @@ bool NeedsRegen(const char* ninja_suffix, s.c_str(), s2.c_str(), SPF(val)); } RETURN_TRUE; - } else if (dump_kati_stamp) { + } else if (g_flags.dump_kati_stamp) { printf("env %s: clean (%.*s)\n", s.c_str(), SPF(val)); } } @@ -903,19 +874,19 @@ bool NeedsRegen(const char* ninja_suffix, } if (needs_regen) { if (ShouldIgnoreDirty(pat)) { - if (dump_kati_stamp) { + if (g_flags.dump_kati_stamp) { printf("wildcard %s: ignored\n", pat.c_str()); } continue; } - if (dump_kati_stamp) { + if (g_flags.dump_kati_stamp) { printf("wildcard %s: dirty\n", pat.c_str()); } else { fprintf(stderr, "wildcard(%s) was changed, regenerating...\n", pat.c_str()); } RETURN_TRUE; - } else if (dump_kati_stamp) { + } else if (g_flags.dump_kati_stamp) { printf("wildcard %s: clean\n", pat.c_str()); } } @@ -951,7 +922,7 @@ bool NeedsRegen(const char* ninja_suffix, } if (!should_run_command) { - if (dump_kati_stamp) + if (g_flags.dump_kati_stamp) printf("shell %s: clean (no rerun)\n", cmd.c_str()); continue; } @@ -960,7 +931,7 @@ bool NeedsRegen(const char* ninja_suffix, FindCommand fc; if (fc.Parse(cmd) && !fc.chdir.empty() && ShouldIgnoreDirty(fc.chdir)) { - if (dump_kati_stamp) + if (g_flags.dump_kati_stamp) printf("shell %s: ignored\n", cmd.c_str()); continue; } @@ -971,7 +942,7 @@ bool NeedsRegen(const char* ninja_suffix, RunCommand("/bin/sh", cmd, RedirectStderr::DEV_NULL, &result); FormatForCommandSubstitution(&result); if (expected != result) { - if (dump_kati_stamp) { + if (g_flags.dump_kati_stamp) { printf("shell %s: dirty\n", cmd.c_str()); } else { fprintf(stderr, "$(shell %s) was changed, regenerating...\n", @@ -982,7 +953,7 @@ bool NeedsRegen(const char* ninja_suffix, #endif } RETURN_TRUE; - } else if (dump_kati_stamp) { + } else if (g_flags.dump_kati_stamp) { printf("shell %s: clean (rerun)\n", cmd.c_str()); } } @@ -27,20 +27,13 @@ using namespace std; struct DepNode; class Evaluator; -void GenerateNinja(const char* ninja_suffix, - const char* ninja_dir, - const vector<DepNode*>& nodes, +void GenerateNinja(const vector<DepNode*>& nodes, Evaluator* ev, bool build_all_targets, const string& orig_args, double start_time); -bool NeedsRegen(const char* ninja_suffix, - const char* ninja_dir, - bool ignore_kati_binary, - bool dump_kati_stamp, - double start_time, - const string& orig_args); +bool NeedsRegen(double start_time, const string& orig_args); // Exposed only for test. bool GetDepfileFromCommand(string* cmd, string* out); |
