diff --git a/flags.cc b/flags.cc index 07b57483..54828e56 100644 --- a/flags.cc +++ b/flags.cc @@ -82,6 +82,8 @@ void Flags::Parse(int argc, char** argv) { enable_kati_warnings = true; } else if (!strcmp(arg, "--ninja")) { generate_ninja = true; + } else if (!strcmp(arg, "--empty_ninja_file")) { + generate_empty_ninja = true; } else if (!strcmp(arg, "--gen_all_targets")) { gen_all_targets = true; } else if (!strcmp(arg, "--regen")) { diff --git a/flags.h b/flags.h index 025979a6..62865a35 100644 --- a/flags.h +++ b/flags.h @@ -32,6 +32,7 @@ struct Flags { bool enable_stat_logs; bool gen_all_targets; bool generate_ninja; + bool generate_empty_ninja; bool is_dry_run; bool is_silent_mode; bool is_syntax_check_only; diff --git a/ninja.cc b/ninja.cc index 0b87d5c6..90e56c83 100644 --- a/ninja.cc +++ b/ninja.cc @@ -629,8 +629,10 @@ class NinjaGenerator { } tp->Wait(); - for (const ostringstream& buf : bufs) { - fprintf(fp_, "%s", buf.str().c_str()); + if (!g_flags.generate_empty_ninja) { + for (const ostringstream& buf : bufs) { + fprintf(fp_, "%s", buf.str().c_str()); + } } SymbolSet used_env_vars(Vars::used_env_vars()); @@ -652,8 +654,10 @@ class NinjaGenerator { default_targets += EscapeBuildTarget(s); } } - fprintf(fp_, "\n"); - fprintf(fp_, "default %s\n", default_targets.c_str()); + if (!g_flags.generate_empty_ninja) { + fprintf(fp_, "\n"); + fprintf(fp_, "default %s\n", default_targets.c_str()); + } fclose(fp_); }