summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/browse.cc17
-rwxr-xr-xsrc/browse.py4
-rwxr-xr-xsrc/inline.sh29
3 files changed, 35 insertions, 15 deletions
diff --git a/src/browse.cc b/src/browse.cc
index 92b290d..db89db0 100644
--- a/src/browse.cc
+++ b/src/browse.cc
@@ -17,19 +17,9 @@
#include <stdio.h>
#include <unistd.h>
+#include "../build/browse_py.h"
#include "ninja.h"
-// Import browse.py as binary data.
-asm(
-".data\n"
-"browse_data_begin:\n"
-".incbin \"src/browse.py\"\n"
-"browse_data_end:\n"
-);
-// Declare the symbols defined above.
-extern const char browse_data_begin[];
-extern const char browse_data_end[];
-
void RunBrowsePython(State* state, const char* ninja_command) {
// Fork off a Python process and have it run our code via its stdin.
// (Actually the Python process becomes the parent.)
@@ -65,9 +55,8 @@ void RunBrowsePython(State* state, const char* ninja_command) {
close(pipefd[0]);
// Write the script file into the stdin of the Python process.
- const int browse_data_len = browse_data_end - browse_data_begin;
- int len = write(pipefd[1], browse_data_begin, browse_data_len);
- if (len < browse_data_len)
+ ssize_t len = write(pipefd[1], kBrowsePy, sizeof(kBrowsePy));
+ if (len < (ssize_t)sizeof(kBrowsePy))
perror("write");
close(pipefd[1]);
exit(0);
diff --git a/src/browse.py b/src/browse.py
index 92c7eaa..1860df3 100755
--- a/src/browse.py
+++ b/src/browse.py
@@ -26,7 +26,9 @@ import sys
import webbrowser
def match_strip(prefix, line):
- assert line.startswith(prefix)
+ if not line.startswith(prefix):
+ print prefix, line
+ assert line.startswith(prefix)
return line[len(prefix):]
def parse(text):
diff --git a/src/inline.sh b/src/inline.sh
new file mode 100755
index 0000000..e32f33d
--- /dev/null
+++ b/src/inline.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# Copyright 2001 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This quick script converts a text file into an #include-able header.
+# It expects the name of the variable as its first argument, and reads
+# stdin and writes stdout.
+
+varname="$1"
+echo "const char $varname[] ="
+IFS=
+while read line; do
+ escaped=$(echo "$line" | sed -e 's|\\|\\\\|g; s|"|\\"|g')
+ echo "\"$escaped\\n\""
+done
+echo ";"
+