aboutsummaryrefslogtreecommitdiffstats
path: root/ninja.cc
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-07-03 20:43:32 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-07-03 20:43:40 +0900
commit54b93baf40f86b7b7a08e014e97eeb009d1c21a6 (patch)
tree301609f15a651559c162b2ba94461f0ed79def93 /ninja.cc
parent9facae26c7df29e569928e96b524e5fb684234c5 (diff)
downloadplatform_build_kati-54b93baf40f86b7b7a08e014e97eeb009d1c21a6.tar.gz
platform_build_kati-54b93baf40f86b7b7a08e014e97eeb009d1c21a6.tar.bz2
platform_build_kati-54b93baf40f86b7b7a08e014e97eeb009d1c21a6.zip
[C++] Generate ninja.sh
Diffstat (limited to 'ninja.cc')
-rw-r--r--ninja.cc35
1 files changed, 29 insertions, 6 deletions
diff --git a/ninja.cc b/ninja.cc
index 07c040b..c86737c 100644
--- a/ninja.cc
+++ b/ninja.cc
@@ -17,6 +17,8 @@
#include "ninja.h"
#include <stdio.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <memory>
#include <string>
@@ -355,12 +357,33 @@ class NinjaGenerator {
}
void GenerateShell() {
-#if 0
- Var* v = ev->LookupVar("SHELL");
- shell_ = v->Eval(ev);
- if (shell_->empty())
- shell_ = make_shared<string>("/bin/sh");
-#endif
+ FILE* fp = fopen("ninja.sh", "wb");
+ if (fp == NULL)
+ PERROR("fopen(ninja.sh) failed");
+
+ Var* v = ev_->LookupVar(Intern("SHELL"));
+ shared_ptr<string> shell = v->Eval(ev_);
+ if (shell->empty())
+ shell = make_shared<string>("/bin/sh");
+ fprintf(fp, "#!%s\n", shell->c_str());
+
+ for (const auto& p : ev_->exports()) {
+ if (p.second) {
+ shared_ptr<string> val = ev_->LookupVar(p.first)->Eval(ev_);
+ fprintf(fp, "export %s=%s\n", p.first.c_str(), val->c_str());
+ } else {
+ fprintf(fp, "unset %s\n", p.first.c_str());
+ }
+ }
+
+ if (g_goma_dir) {
+ fprintf(fp, "exec ninja -j300 \"$@\"\n");
+ } else {
+ fprintf(fp, "exec ninja \"$@\"\n");
+ }
+
+ if (chmod("ninja.sh", 0755) != 0)
+ PERROR("chmod ninja.sh failed");
}
CommandEvaluator ce_;