SCons/Builder.py
SCons/compat/__init__.py
SCons/compat/_scons_hashlib.py
+SCons/compat/_scons_io.py
SCons/compat/_scons_itertools.py
SCons/compat/_scons_optparse.py
SCons/compat/_scons_sets.py
SCons.Util.AddMethod(self, batch_key, 'batch_key')
def print_cmd_line(self, s, target, source, env):
- sys.stdout.write(s + "\n")
+ sys.stdout.write(s + u"\n")
def __call__(self, target, source, env,
exitstatfunc=_null,
source = executor.get_all_sources()
t = ' and '.join(map(str, target))
l = '\n '.join(self.presub_lines(env))
- out = "Building %s with action:\n %s\n" % (t, l)
+ out = u"Building %s with action:\n %s\n" % (t, l)
sys.stdout.write(out)
cmd = None
if show and self.strfunction:
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import SCons.compat
+
# Define a null function and a null class for use as builder actions.
# Where these are defined in the file seems to affect their byte-code
# contents, so try to minimize changes by defining them here, before we
def __call__(self):
pass
+import io
import os
import re
-import StringIO
import sys
import types
import unittest
# Capture all the stuff the Actions will print,
# so it doesn't clutter the output.
-sys.stdout = StringIO.StringIO()
+sys.stdout = io.StringIO()
class CmdStringHolder:
def __init__(self, cmd, literal=None):
pass
a = SCons.Action.Action(execfunc)
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
a.print_cmd_line("foo bar", None, None, None)
s = sio.getvalue()
return 9
b = SCons.Action.Action([firstfunc, execfunc, lastfunc])
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = a("out", "in", env)
assert result.status == 7, result
a.chdir = 'xyz'
expect = "os.chdir(%s)\nexecfunc(['out'], ['in'])\nos.chdir(%s)\n"
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = a("out", "in", env)
assert result.status == 7, result.status
s = sio.getvalue()
assert s == expect % (repr('xyz'), repr(test.workpath())), s
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = a("out", "in", env, chdir='sub')
assert result.status == 7, result.status
a.chdir = None
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = b("out", "in", env)
assert result.status == 7, result.status
SCons.Action.execute_actions = 0
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = a("out", "in", env)
assert result == 0, result
s = sio.getvalue()
assert s == "execfunc(['out'], ['in'])\n", s
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = b("out", "in", env)
assert result == 0, result
SCons.Action.print_actions_presub = 1
SCons.Action.execute_actions = 1
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = a("out", "in", env)
assert result.status == 7, result.status
s = sio.getvalue()
assert s == "Building out with action:\n execfunc(target, source, env)\nexecfunc(['out'], ['in'])\n", s
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = a("out", "in", env, presub=0)
assert result.status == 7, result.status
s = sio.getvalue()
assert s == "execfunc(['out'], ['in'])\n", s
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = a("out", "in", env, presub=1)
assert result.status == 7, result.status
s = sio.getvalue()
assert s == "Building out with action:\n execfunc(target, source, env)\nexecfunc(['out'], ['in'])\n", s
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = b(["out"], "in", env, presub=1)
assert result.status == 7, result.status
s = sio.getvalue()
assert s == "Building out with action:\n firstfunc(target, source, env)\nfirstfunc(['out'], ['in'])\nBuilding out with action:\n execfunc(target, source, env)\nexecfunc(['out'], ['in'])\n", s
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = b(["out", "list"], "in", env, presub=1)
assert result.status == 7, result.status
a2 = SCons.Action.Action(execfunc)
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = a2("out", "in", env)
assert result.status == 7, result.status
s = sio.getvalue()
assert s == "Building out with action:\n execfunc(target, source, env)\nexecfunc(['out'], ['in'])\n", s
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = a2("out", "in", env, presub=0)
assert result.status == 7, result.status
SCons.Action.execute_actions = 0
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = a2("out", "in", env, presub=0)
assert result == 0, result
s = sio.getvalue()
assert s == "execfunc(['out'], ['in'])\n", s
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
result = a("out", "in", env, presub=0, execute=1, show=0)
assert result.status == 7, result.status
def Func():
pass
+import io
import os.path
import re
import sys
-import StringIO
import unittest
import UserList
import SCons.Subst
import SCons.Util
-sys.stdout = StringIO.StringIO()
+sys.stdout = io.StringIO()
# Initial setup of the common environment for all tests,
# a temporary working directory containing a
out,err = p.communicate()
status = p.wait()
if err:
- sys.stderr.write(err)
+ sys.stderr.write(unicode(err))
if status:
raise OSError("'%s' exited %d" % (command, status))
return out
import SCons.compat
import copy
+import io
import os
-import StringIO
import sys
import TestCmd
import unittest
python = '"' + sys.executable + '"'
try:
- sys.stderr = StringIO.StringIO()
+ sys.stderr = io.StringIO()
cmd = '%s %s' % (python, test.workpath('stdout.py'))
output = env.backtick(cmd)
errout = sys.stderr.getvalue()
assert output == 'this came from stdout.py\n', output
assert errout == '', errout
- sys.stderr = StringIO.StringIO()
+ sys.stderr = io.StringIO()
cmd = '%s %s' % (python, test.workpath('stderr.py'))
output = env.backtick(cmd)
errout = sys.stderr.getvalue()
assert output == '', output
assert errout == 'this came from stderr.py\n', errout
- sys.stderr = StringIO.StringIO()
+ sys.stderr = io.StringIO()
cmd = '%s %s' % (python, test.workpath('fail.py'))
try:
env.backtick(cmd)
else:
self.fail("did not catch expected OSError")
- sys.stderr = StringIO.StringIO()
+ sys.stderr = io.StringIO()
cmd = '%s %s' % (python, test.workpath('echo.py'))
env['ENV'] = os.environ.copy()
env['ENV']['ECHO'] = 'this came from ECHO'
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
from itertools import izip
-import cStringIO
import fnmatch
import os
import os.path
if verbose and not callable(verbose):
if not SCons.Util.is_String(verbose):
verbose = "find_file"
- _verbose = ' %s: ' % verbose
+ _verbose = u' %s: ' % verbose
verbose = lambda s: sys.stdout.write(_verbose + s)
filedir, filename = os.path.split(filename)
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import SCons.compat
+
import os
import os.path
import sys
# 'bar/baz' as a Dir.
SCons.Node.FS.find_file('baz/no_file_here', paths)
- import StringIO
+ import io
save_sys_stdout = sys.stdout
try:
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
SCons.Node.FS.find_file('foo2', paths, verbose="xyz")
expect = " xyz: looking for 'foo2' in '.' ...\n" + \
c = sio.getvalue()
assert c == expect, c
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
SCons.Node.FS.find_file('baz2', paths, verbose=1)
expect = " find_file: looking for 'baz2' in '.' ...\n" + \
c = sio.getvalue()
assert c == expect, c
- sio = StringIO.StringIO()
+ sio = io.StringIO()
sys.stdout = sio
SCons.Node.FS.find_file('on_disk', paths, verbose=1)
expect = " find_file: looking for 'on_disk' in '.' ...\n" + \
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import SCons.compat
+
+import io
import os
import re
-import StringIO
import sys
import traceback
"""
def __init__(self, orig):
self.orig = orig
- self.s = StringIO.StringIO()
+ self.s = io.StringIO()
def write(self, str):
if self.orig:
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import SCons.compat
+
+import io
import os
import re
-import StringIO
import sys
from types import *
import unittest
import TestCmd
-sys.stdout = StringIO.StringIO()
+sys.stdout = io.StringIO()
if sys.platform == 'win32':
existing_lib = "msvcrt"
the Action is actually called to build the targets.
"""
T = self.tm.trace
- if T: T.write(self.trace_message('Task.prepare()', self.node))
+ if T: T.write(self.trace_message(u'Task.prepare()', self.node))
# Now that it's the appropriate time, give the TaskMaster a
# chance to raise any exceptions it encountered while preparing
prepare(), executed() or failed().
"""
T = self.tm.trace
- if T: T.write(self.trace_message('Task.execute()', self.node))
+ if T: T.write(self.trace_message(u'Task.execute()', self.node))
try:
everything_was_cached = 1
This is the default behavior for building only what's necessary.
"""
T = self.tm.trace
- if T: T.write(self.trace_message('Task.make_ready_current()',
+ if T: T.write(self.trace_message(u'Task.make_ready_current()',
self.node))
self.out_of_date = []
that can be put back on the candidates list.
"""
T = self.tm.trace
- if T: T.write(self.trace_message('Task.postprocess()', self.node))
+ if T: T.write(self.trace_message(u'Task.postprocess()', self.node))
# We may have built multiple targets, some of which may have
# common parents waiting for this build. Count up how many
# A node can only be in the pending_children set if it has
# some waiting_parents.
if t.waiting_parents:
- if T: T.write(self.trace_message('Task.postprocess()',
+ if T: T.write(self.trace_message(u'Task.postprocess()',
t,
'removing'))
pending_children.discard(t)
for p, subtract in parents.items():
p.ref_count = p.ref_count - subtract
- if T: T.write(self.trace_message('Task.postprocess()',
+ if T: T.write(self.trace_message(u'Task.postprocess()',
p,
'adjusted parent ref count'))
if p.ref_count == 0:
self.ready_exc = None
T = self.trace
- if T: T.write('\n' + self.trace_message('Looking for a node to evaluate'))
+ if T: T.write(u'\n' + self.trace_message('Looking for a node to evaluate'))
while True:
node = self.next_candidate()
if node is None:
- if T: T.write(self.trace_message('No candidate anymore.') + '\n')
+ if T: T.write(self.trace_message('No candidate anymore.') + u'\n')
return None
node = node.disambiguate()
else:
S = None
- if T: T.write(self.trace_message(' Considering node %s and its children:' % self.trace_node(node)))
+ if T: T.write(self.trace_message(u' Considering node %s and its children:' % self.trace_node(node)))
if state == NODE_NO_STATE:
# Mark this node as being on the execution stack:
elif state > NODE_PENDING:
# Skip this node if it has already been evaluated:
if S: S.already_handled = S.already_handled + 1
- if T: T.write(self.trace_message(' already handled (executed)'))
+ if T: T.write(self.trace_message(u' already handled (executed)'))
continue
executor = node.get_executor()
for child in chain(executor.get_all_prerequisites(), children):
childstate = child.get_state()
- if T: T.write(self.trace_message(' ' + self.trace_node(child)))
+ if T: T.write(self.trace_message(u' ' + self.trace_node(child)))
if childstate == NODE_NO_STATE:
children_not_visited.append(child)
# count so we can be put back on the list for
# re-evaluation when they've all finished.
node.ref_count = node.ref_count + child.add_to_waiting_parents(node)
- if T: T.write(self.trace_message(' adjusted ref count: %s, child %s' %
+ if T: T.write(self.trace_message(u' adjusted ref count: %s, child %s' %
(self.trace_node(node), repr(str(child)))))
if T:
# The default when we've gotten through all of the checks above:
# this node is ready to be built.
if S: S.build = S.build + 1
- if T: T.write(self.trace_message('Evaluating %s\n' %
+ if T: T.write(self.trace_message(u'Evaluating %s\n' %
self.trace_node(node)))
# For debugging only:
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import SCons.compat
+
import copy
import sys
import unittest
def test_trace(self):
"""Test Taskmaster tracing
"""
- import StringIO
+ import io
- trace = StringIO.StringIO()
+ trace = io.StringIO()
n1 = Node("n1")
n2 = Node("n2")
n3 = Node("n3", [n1, n2])
def print_it(self, text, append_newline=1):
if append_newline: text = text + '\n'
try:
- sys.stdout.write(text)
+ sys.stdout.write(unicode(text))
except IOError:
# Stdout might be connected to a pipe that has been closed
# by now. The most likely reason for the pipe being closed
if showtags:
if showtags == 2:
- print ' E = exists'
- print ' R = exists in repository only'
- print ' b = implicit builder'
- print ' B = explicit builder'
- print ' S = side effect'
- print ' P = precious'
- print ' A = always build'
- print ' C = current'
- print ' N = no clean'
- print ' H = no cache'
- print ''
+ legend = (' E = exists\n' +
+ ' R = exists in repository only\n' +
+ ' b = implicit builder\n' +
+ ' B = explicit builder\n' +
+ ' S = side effect\n' +
+ ' P = precious\n' +
+ ' A = always build\n' +
+ ' C = current\n' +
+ ' N = no clean\n' +
+ ' H = no cache\n' +
+ '\n')
+ sys.stdout.write(unicode(legend))
tags = ['[']
tags.append(' E'[IDX(root.exists())])
children = child_func(root)
if prune and rname in visited and children:
- print ''.join(tags + margins + ['+-[', rname, ']'])
+ sys.stdout.write(''.join(tags + margins + ['+-[', rname, ']']) + u'\n')
return
- print ''.join(tags + margins + ['+-', rname])
+ sys.stdout.write(''.join(tags + margins + ['+-', rname]) + u'\n')
visited[rname] = 1
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import SCons.compat
+
+import io
import os
import os.path
-import StringIO
import sys
import unittest
try:
node, expect, withtags = self.tree_case_1()
- sys.stdout = StringIO.StringIO()
+ sys.stdout = io.StringIO()
print_tree(node, get_children)
actual = sys.stdout.getvalue()
assert expect == actual, (expect, actual)
- sys.stdout = StringIO.StringIO()
+ sys.stdout = io.StringIO()
print_tree(node, get_children, showtags=1)
actual = sys.stdout.getvalue()
assert withtags == actual, (withtags, actual)
node, expect, withtags = self.tree_case_2(prune=0)
- sys.stdout = StringIO.StringIO()
+ sys.stdout = io.StringIO()
print_tree(node, get_children, 1)
actual = sys.stdout.getvalue()
assert expect == actual, (expect, actual)
- sys.stdout = StringIO.StringIO()
+ sys.stdout = io.StringIO()
# The following call should work here:
# print_tree(node, get_children, 1, showtags=1)
# For some reason I don't understand, though, *this*
def test_LogicalLines(self):
"""Test the LogicalLines class"""
- fobj = StringIO.StringIO(r"""
+ fobj = io.StringIO(r"""
foo \
bar \
baz
fnmatch.filter = filter
del filter
+try:
+ import io
+except ImportError:
+ # Pre-2.6 Python has no io module.
+ import_as('_scons_io', 'io')
+
try:
import itertools
except ImportError:
--- /dev/null
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__doc__ = """
+io compatibility module for older (pre-2.6) Python versions
+
+This does not not NOT (repeat, *NOT*) provide complete io
+functionality. It only wraps the portions of io functionality used
+by SCons, in an interface that looks enough like io for our purposes.
+"""
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+from cStringIO import StringIO
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: