[Scons-users] SideEffect use in further operations

Mark Holloway hollowaymr at hotmail.com
Tue Jun 17 07:45:55 EDT 2014


I'm seeing some strange side-effects of using SideEffect (sorry!). I've boiled it down to a simple example, which I'm hoping someone can shed some light on:
	import zipfile	import tarfile	import os.path
	def Archive( target, source, env ):		if str(target[0]).endswith('.zip'):			with zipfile.ZipFile( str(target[0]), 'w', zipfile.ZIP_DEFLATED) as myzip:				for source_file in source:					myzip.write( source_file.path )		elif str(target[0]).endswith('.tar.gz'):			with tarfile.open( str(target[0]), 'w:gz' ) as mytar:				for source_file in source:					mytar.add( source_file.path )
	_archive_builder = Builder( action=Archive )
	env = Environment()
	env.Append( BUILDERS = {'Archive': _archive_builder} )
	f1 = env.Command( 'file1.out', 'file1.in', 'copy $SOURCE $TARGET >> log.txt')	f2 = env.Command( 'file2.out', 'file2.in', 'copy $SOURCE $TARGET >> log.txt') 
	env.SideEffect('log.txt', [f1, f2]) 
	env.Archive( 'thing.zip', 'log.txt' )

So the idea is that the side effect is necessary because those commands should not run in parallel (as per the docs for SideEffect), but after all tasks which write to the log file are complete I'd like to include it in an archive to be saved as a result of the build. (I know I could use the install stuff, but for a few reasons - I don't want to use that, and in any case - I still want to understand what's wrong here).
So this works as expected, until more than one job is specified - a which point the archive is not created on first run, but does appear on subsequent runs (presumably because it can now see the log file).
# 1 Job:C:\Users\Build\testme>scons --jobs=1 -nscons: Reading SConscript files ...scons: done reading SConscript files.scons: Building targets ...copy file1.in file1.out >> log.txtcopy file2.in file2.out >> log.txtArchive(["thing.zip"], ["log.txt"])scons: done building targets.
# 4 Jobs: Note the missing archive step.C:\Users\Build\testme>scons --jobs=4 -nscons: Reading SConscript files ...scons: done reading SConscript files.scons: Building targets ...copy file1.in file1.out >> log.txtcopy file2.in file2.out >> log.txtscons: done building targets.
# So I take a look at the dependencies, and they all seem fine:C:\Users\Build\testme>scons -n --tree=prunescons: Reading SConscript files ...scons: done reading SConscript files.scons: Building targets ...copy file1.in file1.out >> log.txtcopy file2.in file2.out >> log.txtArchive(["thing.zip"], ["log.txt"])+-.  +-file1.in  +-file1.out  | +-file1.in  +-file2.in  +-file2.out  | +-file2.in  +-log.txt  | +-[file1.out]  | +-[file2.out]  +-SConstruct  +-thing.zip    +-[log.txt]scons: done building targets.

That looks okay to me - but I feel I may be missing some understanding about the side effect.
Thanks for any help!Mark
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20140617/bc3943fd/attachment.html>


More information about the Scons-users mailing list