diff options
author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-07-06 18:55:47 +0900 |
---|---|---|
committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-07-06 19:43:40 +0900 |
commit | 8bddb46a8275ed3c4737c0d8020372ad17946ae1 (patch) | |
tree | a5328260b1c9b28036459c856f3c4cf6035129ed | |
parent | 3f2cf1e8f56af97459fbca9074feca4509f8a0bf (diff) | |
download | android_build_kati-8bddb46a8275ed3c4737c0d8020372ad17946ae1.tar.gz android_build_kati-8bddb46a8275ed3c4737c0d8020372ad17946ae1.tar.bz2 android_build_kati-8bddb46a8275ed3c4737c0d8020372ad17946ae1.zip |
Make it possible to generate ninja for specific target
-rwxr-xr-x | m2n | 48 | ||||
-rw-r--r-- | main.cc | 5 | ||||
-rw-r--r-- | ninja.cc | 31 | ||||
-rw-r--r-- | ninja.h | 3 |
4 files changed, 64 insertions, 23 deletions
@@ -28,10 +28,10 @@ while [ x"$1" != x"" ]; do --help) cat - <<EOF Usage: - m2n # for full-build - m2n --goma # use goma. \$HOME/goma must exist - m2n --go # use go version. Slower but maybe more portable. - m2n bionic # works like mmm + m2n # for default full-build + m2n --goma # use goma. \$HOME/goma must exist + m2n --go # use go version. Slower but maybe more portable. + m2n cts # for target 'cts' EOF exit 1 ;; @@ -55,13 +55,20 @@ EOF shift ;; + --mmm) + echo 'Note: --mmm may not work' + shift; + mmm="$1" + shift + ;; + --*) extra_flags+=" $1" shift ;; *) - target=$1 + targets="${targets} $1" shift ;; esac @@ -69,15 +76,32 @@ done kati=${kati_dir}/ckati -if [ x"${target}" != x"" ]; then - if [ -f ${target}/Android.mk ]; then - export ONE_SHOT_MAKEFILE=${target}/Android.mk - echo ONE_SHOT_MAKEFILE=${ONE_SHOT_MAKEFILE} - target= +ninja_suffix= +ninja_suffix_flag= + +if [ x"${mmm}" != x"" ]; then + mk="${mmm}/Android.mk" + if [ ! -f ${mk} ]; then + echo "${mk} does not exist" + exit 1 fi + + export ONE_SHOT_MAKEFILE=${mk} + echo ONE_SHOT_MAKEFILE=${ONE_SHOT_MAKEFILE} + + ninja_suffix=-mmm-${mmm} +fi + +if [ x"${targets}" != x"" ]; then + ninja_suffix+=-$(echo ${targets} | sed 's/ /-/') +fi + +if [ x"${ninja_suffix}" != x"" ]; then + ninja_suffix=$(echo ${ninja_suffix} | sed 'y/\//_/') + ninja_suffix_flag=--ninja_suffix=${ninja_suffix} fi -${kati} --ninja --ignore_optional_include=out/%.P --use_find_emulator ${goma_flag} ${extra_flags} ${target} +${kati} --ninja ${ninja_suffix_flag} --ignore_optional_include=out/%.P --use_find_emulator ${goma_flag} ${extra_flags} ${targets} echo -echo ninja.sh and build.ninja were generated, please run ./ninja.sh +echo ninja${ninja_suffix}.sh and build${ninja_suffix}.ninja were generated, please run ./ninja${ninja_suffix}.sh @@ -43,6 +43,7 @@ static const char* g_makefile; static bool g_is_syntax_check_only; static bool g_generate_ninja; +static const char* g_ninja_suffix; static bool g_use_find_emulator; static bool ParseCommandLineOptionWithArg(StringPiece option, @@ -79,6 +80,8 @@ static void ParseCommandLine(int argc, char* argv[], g_enable_stat_logs = true; } else if (!strcmp(arg, "--ninja")) { g_generate_ninja = true; + } else if (ParseCommandLineOptionWithArg( + "--ninja_suffix", argv, &i, &g_ninja_suffix)) { } else if (!strcmp(arg, "--use_find_emulator")) { g_use_find_emulator = true; } else if (ParseCommandLineOptionWithArg( @@ -232,7 +235,7 @@ static int Run(const vector<Symbol>& targets, if (g_generate_ninja) { ScopedTimeReporter tr("generate ninja time"); - GenerateNinja(nodes, ev); + GenerateNinja(g_ninja_suffix, nodes, ev); return 0; } @@ -136,11 +136,14 @@ bool GetDepfileFromCommand(StringPiece cmd, string* out) { class NinjaGenerator { public: - explicit NinjaGenerator(Evaluator* ev) + NinjaGenerator(const char* ninja_suffix, Evaluator* ev) : ce_(ev), ev_(ev), fp_(NULL), rule_id_(0) { ev_->set_avoid_io(true); if (g_goma_dir) gomacc_ = StringPrintf("%s/gomacc ", g_goma_dir); + if (ninja_suffix) { + ninja_suffix_ = ninja_suffix; + } } ~NinjaGenerator() { @@ -334,8 +337,16 @@ class NinjaGenerator { fprintf(fp_, "\n"); } + string GetNinjaFilename() const { + return StringPrintf("build%s.ninja", ninja_suffix_.c_str()); + } + + string GetShellScriptFilename() const { + return StringPrintf("ninja%s.sh", ninja_suffix_.c_str()); + } + void GenerateNinja(const vector<DepNode*>& nodes) { - fp_ = fopen("build.ninja", "wb"); + fp_ = fopen(GetNinjaFilename().c_str(), "wb"); if (fp_ == NULL) PERROR("fopen(build.ninja) failed"); @@ -356,7 +367,7 @@ class NinjaGenerator { } void GenerateShell() { - FILE* fp = fopen("ninja.sh", "wb"); + FILE* fp = fopen(GetShellScriptFilename().c_str(), "wb"); if (fp == NULL) PERROR("fopen(ninja.sh) failed"); @@ -374,13 +385,13 @@ class NinjaGenerator { } } + fprintf(fp, "exec ninja -f %s ", GetNinjaFilename().c_str()); if (g_goma_dir) { - fprintf(fp, "exec ninja -j300 \"$@\"\n"); - } else { - fprintf(fp, "exec ninja \"$@\"\n"); + fprintf(fp, "-j300 "); } + fprintf(fp, "\"$@\"\n"); - if (chmod("ninja.sh", 0755) != 0) + if (chmod(GetShellScriptFilename().c_str(), 0755) != 0) PERROR("chmod ninja.sh failed"); } @@ -391,9 +402,11 @@ class NinjaGenerator { int rule_id_; string cmd_buf_; string gomacc_; + string ninja_suffix_; }; -void GenerateNinja(const vector<DepNode*>& nodes, Evaluator* ev) { - NinjaGenerator ng(ev); +void GenerateNinja(const char* ninja_suffix, + const vector<DepNode*>& nodes, Evaluator* ev) { + NinjaGenerator ng(ninja_suffix, ev); ng.Generate(nodes); } @@ -25,7 +25,8 @@ using namespace std; class DepNode; class Evaluator; -void GenerateNinja(const vector<DepNode*>& nodes, Evaluator* ev); +void GenerateNinja(const char* ninja_suffix, + const vector<DepNode*>& nodes, Evaluator* ev); // Exposed only for test. bool GetDepfileFromCommand(StringPiece cmd, string* out); |