summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/browse.cc7
-rw-r--r--src/ninja.cc9
-rw-r--r--src/util.cc12
3 files changed, 23 insertions, 5 deletions
diff --git a/src/browse.cc b/src/browse.cc
index 14900f8..c08c9f4 100644
--- a/src/browse.cc
+++ b/src/browse.cc
@@ -14,6 +14,7 @@
#include "browse.h"
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -57,7 +58,11 @@ void RunBrowsePython(State* state, const char* ninja_command,
}
command.push_back(NULL);
execvp(command[0], (char**)&command[0]);
- perror("ninja: execvp");
+ if (errno == ENOENT) {
+ printf("ninja: %s is required for the browse tool\n", NINJA_PYTHON);
+ } else {
+ perror("ninja: execvp");
+ }
} while (false);
_exit(1);
} else { // Child.
diff --git a/src/ninja.cc b/src/ninja.cc
index a6790e1..1267b03 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -387,7 +387,12 @@ int NinjaMain::ToolBrowse(const Options* options, int argc, char* argv[]) {
// If we get here, the browse failed.
return 1;
}
-#endif // _WIN32
+#else
+int NinjaMain::ToolBrowse(const Options*, int, char**) {
+ Fatal("browse tool not supported on this platform");
+ return 1;
+}
+#endif
#if defined(_MSC_VER)
int NinjaMain::ToolMSVC(const Options* options, int argc, char* argv[]) {
@@ -803,10 +808,8 @@ int NinjaMain::ToolUrtle(const Options* options, int argc, char** argv) {
/// Returns a Tool, or NULL if Ninja should exit.
const Tool* ChooseTool(const string& tool_name) {
static const Tool kTools[] = {
-#if defined(NINJA_HAVE_BROWSE)
{ "browse", "browse dependency graph in a web browser",
Tool::RUN_AFTER_LOAD, &NinjaMain::ToolBrowse },
-#endif
#if defined(_MSC_VER)
{ "msvc", "build helper for MSVC cl.exe (EXPERIMENTAL)",
Tool::RUN_AFTER_FLAGS, &NinjaMain::ToolMSVC },
diff --git a/src/util.cc b/src/util.cc
index 7bfe033..e793a92 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -346,9 +346,19 @@ int ReadFile(const string& path, string* contents, string* err) {
return -errno;
}
+ struct stat st;
+ if (fstat(fileno(f), &st) < 0) {
+ err->assign(strerror(errno));
+ fclose(f);
+ return -errno;
+ }
+
+ // +1 is for the resize in ManifestParser::Load
+ contents->reserve(st.st_size + 1);
+
char buf[64 << 10];
size_t len;
- while ((len = fread(buf, 1, sizeof(buf), f)) > 0) {
+ while (!feof(f) && (len = fread(buf, 1, sizeof(buf), f)) > 0) {
contents->append(buf, len);
}
if (ferror(f)) {