summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'BuildTools/scons2ninja.py')
-rwxr-xr-xBuildTools/scons2ninja.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/BuildTools/scons2ninja.py b/BuildTools/scons2ninja.py
index 6c77c88..df4c655 100755
--- a/BuildTools/scons2ninja.py
+++ b/BuildTools/scons2ninja.py
@@ -1,11 +1,11 @@
#!/usr/bin/env python
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*-
################################################################################
#
# scons2ninja: A script to create a Ninja build file from SCons.
#
# Copyright (c) 2013 Remko Tronçon
# Licensed under the simplified BSD license.
# See COPYING for details.
#
@@ -198,21 +198,21 @@ class NinjaBuilder :
result += "\n"
result += self.pools + "\n"
result += self.rules + "\n"
result += self._build + "\n"
return result
def to_string(self, lst, quote = False) :
if is_list(lst) :
if quote :
- return ' '.join([quote_spaces(x) for x in lst])
+ return ' '.join([quote_spaces(x) for x in lst])
else :
- return ' '.join([escape(x) for x in lst])
+ return ' '.join([escape(x) for x in lst])
if is_regexp(lst) :
return ' '.join([escape(x) for x in self.targets if lst.match(x)])
return escape(lst)
def get_flags_variable(self, flags_type, flags) :
if len(flags) == 0 :
return ''
if flags_type not in self._flags :
self._flags[flags_type] = {}
@@ -242,20 +242,20 @@ scons_dependencies = [os.path.normpath(x) for x in scons_dependencies]
################################################################################
# Rules
################################################################################
ninja = NinjaBuilder()
ninja.pool('scons_pool', depth = 1)
if sys.platform == 'win32' :
- ninja.rule('cl',
- deps = 'msvc',
+ ninja.rule('cl',
+ deps = 'msvc',
command = '$cl /showIncludes $clflags -c $in /Fo$out',
description = 'CXX $out')
ninja.rule('link',
command = '$link $in $linkflags $libs /out:$out',
description = 'LINK $out')
ninja.rule('link_mt',
command = '$link $in $linkflags $libs /out:$out ; $mt $mtflags',
@@ -363,19 +363,19 @@ previous_file = None
f = subprocess.Popen(scons_generate_cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell=True)
stage = 'preamble'
skip_nth_line = -1
stack = ['.']
for line in f.stdout :
line = line.rstrip()
# Skip lines if requested from previous command
if skip_nth_line >= 0 :
- skip_nth_line -= 1
+ skip_nth_line -= 1
if skip_nth_line == 0 :
continue
if line.startswith('scons: done building targets') :
break
if stage == "preamble" :
# Pass all lines from the SCons configuration step to output
if re.match("^scons: Building targets ...", line) :
@@ -401,19 +401,19 @@ for line in f.stdout :
elif stage == "dependencies" :
if not re.match('^[\s|]+\+\-', line) :
# Work around bug in SCons that splits output over multiple lines
continue
level = line.index('+-') / 2
filename = line[level*2+2:]
if filename.startswith('[') :
- filename = filename[1:-1]
+ filename = filename[1:-1]
# Check if we use the 'fixed' format which escapes filenamenames
if filename.startswith('\'') and filename.endswith('\'') :
filename = eval(filename)
if level < len(stack) :
stack = stack[0:level]
elif level > len(stack) :
if level != len(stack) + 1 :
@@ -423,19 +423,19 @@ for line in f.stdout :
# Skip absolute paths
if not os.path.isabs(filename) :
target = stack[-1]
if target not in dependencies :
dependencies[target] = []
dependencies[target].append(filename)
previous_filename = filename
if f.wait() != 0 :
- print "Error calling '" + scons_generate_cmd + "'"
+ print("Error calling '" + scons_generate_cmd + "'")
print f.stderr.read()
exit(-1)
# Pass 2: Parse build rules
tools = {}
for line in build_lines :
# Custom python function
m = re.match('^(\w+)\(\[([^\]]*)\]', line)
if m :
@@ -522,22 +522,22 @@ for line in build_lines :
ninja.build(out, 'lib', files, libflags = flags)
elif tool == 'link':
objects, flags = partition(flags, lambda x: x.endswith('.obj') or x.endswith('.res'))
out, flags = extract_unary_flag("/out:", flags)
libs, flags = partition(flags, lambda x: not x.startswith("/") and x.endswith(".lib"))
libpaths = get_unary_flags("/libpath:", flags)
deps = get_built_libs(libs, libpaths, ninja.targets)
if out in mtflags :
- ninja.build(out, 'link_mt', objects, deps = sorted(deps),
+ ninja.build(out, 'link_mt', objects, deps = sorted(deps),
libs = libs, linkflags = flags, mtflags = mtflags[out])
else :
- ninja.build(out, 'link', objects, deps = sorted(deps),
+ ninja.build(out, 'link', objects, deps = sorted(deps),
libs = libs, linkflags = flags)
elif tool == 'rc':
out, flags = extract_unary_flag("/fo", flags)
files, flags = extract_non_flags(flags)
ninja.build(out, 'rc', files[0], order_deps = '_generated_headers', rcflags = flags)
elif tool == 'mt':
# Already handled
@@ -583,22 +583,24 @@ for line in build_lines :
elif tool == 'dsymutil':
out, flags = extract_binary_flag("-o", flags)
files, flags = extract_non_flags(flags)
ninja.build(out, 'dsymutil', files, dsymutilflags = flags)
elif tool == 'sdef' :
source = flags[0];
outdir, flags = extract_binary_flag("-o", flags)
basename, flags = extract_binary_flag("--basename", flags)
- ninja.build(os.path.join(outdir, basename + ".h"), 'sdef', [source],
+ ninja.build(os.path.join(outdir, basename + ".h"), 'sdef', [source],
basename = basename,
outdir = outdir)
+ elif tool == 'checker':
+ pass
elif not ninja_custom_command(ninja, line) :
raise Exception("Unknown tool: '" + line + "'")
# Phony target for all generated headers, used as an order-only depency from all C/C++ sources
ninja.build('_generated_headers', 'phony', ninja.header_targets())
# Regenerate build.ninja file