Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 0758470

Browse files
committedDec 15, 2011
Rewrite the bootstrap script in Python
This allows trouble-free builds on platforms with non-standard Python executable names. As a bonus, it passes the arguments received on to configure.py, so you don't have to reconfigure to build in a non-standard manner.
1 parent 121f36d commit 0758470

File tree

5 files changed

+76
-57
lines changed

5 files changed

+76
-57
lines changed
 

‎HACKING

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Adjusting build flags:
2-
CFLAGS=-O3 ./configure
2+
CFLAGS=-O3 ./configure.py
33
and rebuild.
44

55
Test-driven development:
@@ -56,7 +56,7 @@ Windows development on Linux (this is kind of hacky right now):
5656

5757
Windows development on Windows:
5858
- install mingw, msys, and python
59-
- in the mingw shell, put Python in your path, and: sh bootstrap.sh
59+
- in the mingw shell, put Python in your path, and: python bootstrap.py
6060
- to reconfigure, run 'python configure.py'
6161
- remember to strip the resulting executable if size matters to you
6262
- you'll need to rename ninja.exe into my-ninja.exe during development,

‎README

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ See the manual -- http://martine.github.com/ninja/manual.html or
55
doc/manual.asciidoc included in the distribution -- for background
66
and more details.
77

8-
To build, run ./bootstrap.sh. It first blindly compiles all non-test
8+
To build, run ./bootstrap.py. It first blindly compiles all non-test
99
source files together, then re-builds Ninja using itself. You should
1010
end up with a 'ninja' binary in the source root. Run './ninja -h' for
1111
help.

‎bootstrap.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python
2+
# Copyright 2011 Google Inc. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import re
17+
import sys
18+
import os
19+
import glob
20+
import errno
21+
import subprocess
22+
23+
def run(*args, **kwargs):
24+
try:
25+
subprocess.check_call(*args, **kwargs)
26+
except subprocess.CalledProcessError, e:
27+
sys.exit(e.returncode)
28+
29+
# Compute system-specific CFLAGS/LDFLAGS as used in both in the below
30+
# g++ call as well as in the later configure.py.
31+
cflags = os.environ.get('CFLAGS', '')
32+
ldflags = os.environ.get('LDFLAGS', '')
33+
if sys.platform.startswith('freebsd'):
34+
cflags += ' -I/usr/local/include'
35+
ldflags += ' -L/usr/local/lib'
36+
37+
print 'Building ninja manually...'
38+
39+
try:
40+
os.mkdir('build')
41+
except OSError, e:
42+
if e.errno != errno.EEXIST:
43+
raise
44+
45+
with open('src/browse.py') as browse_py:
46+
with open('build/browse_py.h', 'w') as browse_py_h:
47+
run(['./src/inline.sh', 'kBrowsePy'],
48+
stdin=browse_py, stdout=browse_py_h)
49+
50+
pattern = r'test\.cc$|\.in\.cc$'
51+
52+
if sys.platform.startswith('win32'):
53+
pattern += r'|/browse\.cc$|/subprocess\.cc$'
54+
else:
55+
pattern += r'|-win32\.cc$'
56+
57+
sources = [src for src in glob.glob('src/*.cc') if not re.search(pattern, src)]
58+
59+
args = [os.environ.get('CXX', 'g++'), '-Wno-deprecated',
60+
'-DNINJA_PYTHON="' + sys.executable + '"']
61+
args.extend(cflags.split())
62+
args.extend(ldflags.split())
63+
args.extend(['-o', 'ninja.bootstrap'])
64+
args.extend(sources)
65+
run(args)
66+
67+
print 'Building ninja using itself...'
68+
run([sys.executable, 'configure.py'] + sys.argv[1:])
69+
run(['./ninja.bootstrap'])
70+
os.unlink('ninja.bootstrap')
71+
72+
print 'Done!'

‎bootstrap.sh

-53
This file was deleted.

‎src/browse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22
#
33
# Copyright 2001 Google Inc. All Rights Reserved.
44
#

0 commit comments

Comments
 (0)
This repository has been archived.