Skip to content

Commit

Permalink
Add support for Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
zchothia committed Oct 18, 2012
1 parent b022e78 commit 1d5daec
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
25 changes: 17 additions & 8 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
import shutil
import subprocess

if sys.version_info[0] == 3:
import builtins
print_ = getattr(builtins, "print")
else:
def print_(*args):
sys.stdout.write(" ".join(str(x) for x in args))
sys.stdout.write("\n")

os.chdir(os.path.dirname(os.path.abspath(__file__)))

parser = OptionParser()
Expand All @@ -44,11 +52,12 @@ def run(*args, **kwargs):
cflags.append('-I/usr/local/include')
ldflags.append('-L/usr/local/lib')

print 'Building ninja manually...'
print_('Building ninja manually...')

try:
os.mkdir('build')
except OSError, e:
except OSError:
e = sys.exc_info()[1]
if e.errno != errno.EEXIST:
raise

Expand Down Expand Up @@ -103,7 +112,7 @@ def run(*args, **kwargs):
args.extend(['-o', binary])

if options.verbose:
print ' '.join(args)
print_(' '.join(args))

run(args)

Expand All @@ -112,7 +121,7 @@ def run(*args, **kwargs):
verbose = ['-v']

if sys.platform.startswith('win32'):
print 'Building ninja using itself...'
print_('Building ninja using itself...')
run([sys.executable, 'configure.py', '--with-ninja=%s' % binary] +
conf_args)
run(['./' + binary] + verbose)
Expand All @@ -124,17 +133,17 @@ def run(*args, **kwargs):
for obj in glob.glob('*.obj'):
os.unlink(obj)

print """
print_("""
Done!
Note: to work around Windows file locking, where you can't rebuild an
in-use binary, to run ninja after making any changes to build ninja itself
you should run ninja.bootstrap instead. Your build is also configured to
use ninja.bootstrap.exe as the MSVC helper; see the --with-ninja flag of
the --help output of configure.py."""
the --help output of configure.py.""")
else:
print 'Building ninja using itself...'
print_('Building ninja using itself...')
run([sys.executable, 'configure.py'] + conf_args)
run(['./' + binary] + verbose)
os.unlink(binary)
print 'Done!'
print_('Done!')
14 changes: 11 additions & 3 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@

import ninja_syntax

if sys.version_info[0] == 3:
import builtins
print_ = getattr(builtins, "print")
else:
def print_(*args):
sys.stdout.write(" ".join(str(x) for x in args))
sys.stdout.write("\n")

parser = OptionParser()
platforms = ['linux', 'freebsd', 'solaris', 'mingw', 'windows']
profilers = ['gmon', 'pprof']
Expand All @@ -50,7 +58,7 @@
default="ninja")
(options, args) = parser.parse_args()
if args:
print 'ERROR: extra unparsed command-line arguments:', args
print_('ERROR: extra unparsed command-line arguments:', args)
sys.exit(1)

platform = options.platform
Expand Down Expand Up @@ -256,7 +264,7 @@ def has_re2c():
n.build(src('depfile_parser.cc'), 're2c', src('depfile_parser.in.cc'))
n.build(src('lexer.cc'), 're2c', src('lexer.in.cc'))
else:
print ("warning: A compatible version of re2c (>= 0.11.3) was not found; "
print_("warning: A compatible version of re2c (>= 0.11.3) was not found; "
"changes to src/*.in.cc will not affect your build.")
n.newline()

Expand Down Expand Up @@ -436,4 +444,4 @@ def has_re2c():

n.build('all', 'phony', all_targets)

print 'wrote %s.' % BUILD_FILENAME
print_('wrote %s.' % BUILD_FILENAME)
2 changes: 1 addition & 1 deletion misc/ninja_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def build(self, outputs, rule, inputs=None, implicit=None, order_only=None,

if variables:
if isinstance(variables, dict):
iterator = variables.iteritems()
iterator = iter(variables.items())
else:
iterator = iter(variables)

Expand Down
6 changes: 5 additions & 1 deletion misc/ninja_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
# limitations under the License.

import unittest
from StringIO import StringIO

try:
from StringIO import StringIO
except ImportError:
from io import StringIO

import ninja_syntax

Expand Down

0 comments on commit 1d5daec

Please sign in to comment.