aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xm2n48
-rw-r--r--main.cc5
-rw-r--r--ninja.cc31
-rw-r--r--ninja.h3
4 files changed, 64 insertions, 23 deletions
diff --git a/m2n b/m2n
index 0996885..709000a 100755
--- a/m2n
+++ b/m2n
@@ -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
diff --git a/main.cc b/main.cc
index 88725c1..163a114 100644
--- a/main.cc
+++ b/main.cc
@@ -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;
}
diff --git a/ninja.cc b/ninja.cc
index 5282bc9..020b530 100644
--- a/ninja.cc
+++ b/ninja.cc
@@ -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);
}
diff --git a/ninja.h b/ninja.h
index e53e309..b976284 100644
--- a/ninja.h
+++ b/ninja.h
@@ -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);