[Scons-dev] Fwd: [GSoC Mentors Announce] Now Accepting Applications for Mentoring Organizations for GSoC 2014

Kenny, Jason L jason.l.kenny at intel.com
Fri Feb 14 11:23:27 EST 2014


What I did was a bit more advance, it adds coloring to windows as well, command line support to control coloring, detection of redirection, logging support, and other stuff we found in the practice. But it does require like your solution to the remapping of the stderr or and stdin.

I only suggest it as it does add value to the system as a whole.

Jason

From: scons-dev-bounces at scons.org [mailto:scons-dev-bounces at scons.org] On Behalf Of Alexandre Feblot
Sent: Thursday, February 13, 2014 11:14 AM
To: SCons developer list
Subject: Re: [Scons-dev] Fwd: [GSoC Mentors Announce] Now Accepting Applications for Mentoring Organizations for GSoC 2014

Not sure exactly about what you fixed, but as you speak about coloring, I wanted to share the colorizer tool I am using. Compared to what was proposed in the wiki, it allows to colorize everything in stdout and/or stderr, being printed either by scons itself or by external commands spawned by scons. In order to do this, indeed, I had to overwrite the spawn method. Works only on unix, I used basic terminal color codes.

import sys
import os
import re
import select
import subprocess
import platform

c_underline = "\033[04m"
c_blink = "\033[05m"
c_norm = "\033[00m"

# Normal
c_black = "\033[30m"
c_red = "\033[31m"
c_green = "\033[32m"
c_yellow = "\033[33m"
c_blue = "\033[34m"
c_purple = "\033[35m"
c_cyan = "\033[36m"
c_white = "\033[37m"

# Bold
cb_black = "\033[1;30m"
cb_red = "\033[1;31m"
cb_green = "\033[1;32m"
cb_yellow = "\033[1;33m"
cb_blue = "\033[1;34m"
cb_purple = "\033[1;35m"
cb_cyan = "\033[1;36m"
cb_white = "\033[1;37m"

# BackGround
cback_blue = "\033[1;44m"
cback_white = "\033[1;47m"
cback_black = "\033[1;45m"

#------------------------------------------------------------------------------
# regexps and what they will be replaced with
#------------------------------------------------------------------------------
colorPatterns = [
(re.compile(r'(.*: [Ww]arning[:,].*)') , r'%s[Warning] %s\1%s' % (cb_red, cb_yellow, c_norm)),
(re.compile(r'(.*: [Ee]rror[:,].*)') , r'%s[Error] \1%s' % (cb_red, c_norm)),
(re.compile(r'\[(CC|CXX|UIC|MOC|Q2K|RCC|RAN|LNK)\](.*?)([^/]+)$') , r'%s[\1]%s\2%s\3%s' % (c_blue, c_purple, cb_purple, c_norm)),
]

#------------------------------------------------------------------------------
# Colorize a line according to defined patterns
#------------------------------------------------------------------------------
def colorize(line):
for regexp, replacement in colorPatterns:
line = regexp.sub(replacement, line)

return line;


#------------------------------------------------------------------------------
# Allows to hijack default stdout and stderr to colorize them
#------------------------------------------------------------------------------
class Colorizer(object):
def __init__(self, redirected):
self.buf = ''
self.redirected = redirected

def isatty(self):
return self.redirected.isatty()

def write(self, msg):
if self.buf:
msg = self.buf + msg
self.buf = ''
line, sep, msg = msg.partition('\n')
while sep:
self.redirected.write(colorize(line)+'\n')
line, sep, msg = msg.partition('\n')
if line:
self.buf = line

def __del__(self):
if self.buf:
self.redirected.write(colorize(self.buf))


#------------------------------------------------------------------------------
# Asynchroneously stream subprocess stdout/stderr to our own stdout/stderr
#------------------------------------------------------------------------------
def colorizeSpawn(shell, escape, cmd, args, env):
proc = subprocess.Popen(' '.join(args),
stderr=subprocess.PIPE, stdout=subprocess.PIPE,
shell=True, env=env
)
monitoredStreams = [proc.stdout, proc.stderr]
while monitoredStreams:
rsig, wsig, xsig = select.select(monitoredStreams, [], [])

if proc.stdout in rsig:
data = os.read(proc.stdout.fileno(), 1024)
if data:
sys.stdout.write(data)
else:
proc.stdout.close()
monitoredStreams.remove(proc.stdout)

if proc.stderr in rsig:
data = os.read(proc.stderr.fileno(), 1024)
if data:
sys.stderr.write(data)
else:
proc.stderr.close()
monitoredStreams.remove(proc.stderr)

ret = proc.poll()
return ret


#------------------------------------------------------------------------------
# Initialize the colorizer
#------------------------------------------------------------------------------
def generate(env, **kw):
if platform.system() != 'Windows':
if type(sys.stdout) == file and sys.stdout.isatty():
env['SPAWN'] = colorizeSpawn
sys.stdout = Colorizer(sys.stdout)
if type(sys.stderr) == file and sys.stderr.isatty():
env['SPAWN'] = colorizeSpawn
sys.stderr = Colorizer(sys.stderr)

def exists(env):
return 1

2014-02-12 16:25 GMT+01:00 Kenny, Jason L <jason.l.kenny at intel.com<mailto:jason.l.kenny at intel.com>>:

> Fix async subprocess execution with proper handling of std* streams.

So I fixed the issue with output in Parts. I not saying it could not be clean up some more. However it solves the output issues, and adds coloring ( which seems to need some fixing in certain cases.. ie mac mostly) and logging support. It might not be too hard for someone to move the code over to SCons and integrated its usage into SCons.

Just a thought.

Jason

From: scons-dev-bounces at scons.org<mailto:scons-dev-bounces at scons.org> [mailto:scons-dev-bounces at scons.org<mailto:scons-dev-bounces at scons.org>] On Behalf Of Bill Deegan
Sent: Tuesday, February 11, 2014 5:58 PM
To: SCons developer list
Subject: Re: [Scons-dev] Fwd: [GSoC Mentors Announce] Now Accepting Applications for Mentoring Organizations for GSoC 2014

Anatoly,
While I agree many of the things in your list would be nice to get done.
I'm not sure most of them are a good thing for a GSOC student to attempt.
Few students would have the time to ramp up on all the info needed and make some concrete contributions in the time allowed.
my 2cents.
-Bill

On Tue, Feb 11, 2014 at 12:35 PM, anatoly techtonik <techtonik at gmail.com<mailto:techtonik at gmail.com>> wrote:
On Tue, Feb 11, 2014 at 11:30 PM, anatoly techtonik <techtonik at gmail.com<mailto:techtonik at gmail.com>> wrote:

> On Mon, Feb 3, 2014 at 10:05 PM, Gary Oberbrunner <garyo at oberbrunner.com<mailto:garyo at oberbrunner.com>> wrote:

>> Hi folks; if we want to get a GSoC project this year, now's the time to

>> think about it.

>>

>> Top of my priority list for a GSoC student would be someone to convert

>> everything to python3, finishing what we've started already.

>

> Can of worms. IMHO.

>

>> Other ideas?

>

> Concentrate on visualizing and documenting how SCons works. Cleaning

> up and opening internals to the public. Enhance test running, bring

> back slaves. List current workflows and tools discovery, research best

> practices and see how the tool discovery should be improved.

>

> Research and document the problem of compiling C programs.

> Research and document the problem of compiling C++ programs.

> Enhance documentation.

> Add more design touches.

> Integrate best practices from other projects.

>

> Fix async subprocess execution with proper handling of std* streams.

Also integrate with https://github.com/facebook/watchman to speed up
rebuilds (instead of scanning the whole tree again and again).

--
anatoly t.
_______________________________________________
Scons-dev mailing list
Scons-dev at scons.org<mailto:Scons-dev at scons.org>
http://two.pairlist.net/mailman/listinfo/scons-dev


_______________________________________________
Scons-dev mailing list
Scons-dev at scons.org<mailto:Scons-dev at scons.org>
http://two.pairlist.net/mailman/listinfo/scons-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/scons-dev/attachments/20140214/3419ae5e/attachment-0001.htm>


More information about the Scons-dev mailing list