aboutsummaryrefslogtreecommitdiff
path: root/ninja.cc
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2015-11-09 13:39:14 -0800
committerColin Cross <ccross@android.com>2015-11-09 15:54:25 -0800
commit27df5311c5ea2b5b5ae9132a5e60277b2a5982d4 (patch)
tree65e7e8c11546697847935a3c3e491212199a6d06 /ninja.cc
parent4e3b421f136299f6104d359605644756cc412a6c (diff)
[C++] separate ninja shell script into two
Separate the environment variables out of the ninja shell script so that the caller can source the environment script and then manually call ninja. Change-Id: If977a8316dceae955d71c32d528232d8b3f3aeef
Diffstat (limited to 'ninja.cc')
-rw-r--r--ninja.cc22
1 files changed, 20 insertions, 2 deletions
diff --git a/ninja.cc b/ninja.cc
index b0026e1..575ef1c 100644
--- a/ninja.cc
+++ b/ninja.cc
@@ -552,6 +552,10 @@ class NinjaGenerator {
return GetFilename("ninja%s.sh");
}
+ string GetEnvScriptFilename() const {
+ return GetFilename("env%s.sh");
+ }
+
static string GetFilename(const char* fmt) {
string r = g_flags.ninja_dir ? g_flags.ninja_dir : ".";
r += '/';
@@ -614,9 +618,9 @@ class NinjaGenerator {
}
void GenerateShell() {
- FILE* fp = fopen(GetShellScriptFilename().c_str(), "wb");
+ FILE* fp = fopen(GetEnvScriptFilename().c_str(), "wb");
if (fp == NULL)
- PERROR("fopen(ninja.sh) failed");
+ PERROR("fopen(env.sh) failed");
fprintf(fp, "#!/bin/sh\n");
fprintf(fp, "# Generated by kati %s\n", kGitVersion);
@@ -631,6 +635,18 @@ class NinjaGenerator {
}
}
+ fclose(fp);
+
+ fp = fopen(GetShellScriptFilename().c_str(), "wb");
+ if (fp == NULL)
+ PERROR("fopen(ninja.sh) failed");
+
+ fprintf(fp, "#!/bin/sh\n");
+ fprintf(fp, "# Generated by kati %s\n", kGitVersion);
+ fprintf(fp, "\n");
+
+ fprintf(fp, ". %s\n", GetEnvScriptFilename().c_str());
+
fprintf(fp, "exec ninja -f %s ", GetNinjaFilename().c_str());
if (g_flags.remote_num_jobs > 0) {
fprintf(fp, "-j%d ", g_flags.remote_num_jobs);
@@ -639,6 +655,8 @@ class NinjaGenerator {
}
fprintf(fp, "\"$@\"\n");
+ fclose(fp);
+
if (chmod(GetShellScriptFilename().c_str(), 0755) != 0)
PERROR("chmod ninja.sh failed");
}