Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 42620103d8ee8a2d972d3103bad0ab73 > files > 240

waf-1.5.19-1.fc14.noarch.rpm

#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2006-2010 (ita)

top = '.'
out = 'build'

# by using the following interceptor, a 'build.log'
# containing all the output during the build phase
# you may add this snippet anywhere in your project (wscript)

# run
# "waf distclean configure build"
# less -R build/build.log

import os, sys, logging
import Build, Utils

old = Build.BuildContext.compile
def compile(self):
	class tee(object):
		def __init__(self, orig, dup):
			self.orig = orig
			self.dup = dup
		def write(self, value):
			self.orig.write(value)
			self.dup.write(value)
		def flush(self):
			self.orig.flush()
			self.dup.flush()
		def fileno(self):
			return self.orig.fileno()

	try:
		stdout = sys.stdout
		stderr = sys.stderr
		log = open(os.path.join(self.bldnode.abspath(), 'build.log'), 'w')
		sys.stderr = sys.stdout = tee(stdout, log)

		old_exec_command = Build.BuildContext.exec_command
		def exec_command(self, s, **kw):
			if 'log' in kw:
				kw['stdout'] = kw['stderr'] = kw['log']
				del(kw['log'])
			else:
				kw['stdout'] = kw['stderr'] = Utils.pproc.PIPE
			kw['shell'] = isinstance(s, str)

			try:
				proc = Utils.pproc.Popen(s, **kw)
				(out, err) = proc.communicate()
				sys.stdout.write(out)
				sys.stderr.write(err)
				return proc.returncode
			except OSError:
				return -1
		Build.BuildContext.exec_command = exec_command

		foo = logging.getLogger()
		for h in foo.handlers:
			if h.stream:
				h.oldstream = h.stream
				h.stream = sys.stderr

		old(self)
	finally:
		sys.stdout = stdout
		sys.stderr = stderr
		Build.BuildContext.exec_command = old_exec_command

		foo = logging.getLogger()
		for h in foo.handlers:
			if h.stream:
				h.stream = h.oldstream

		log.close()
Build.BuildContext.compile = compile

#------------------------------------------------
#    normal code follows

def configure(conf):
	pass

def build(bld):
	bld(rule="echo ohai", always=True)