[Scons-users] SideEffect use in further operations

Bill Deegan bill at baddogconsulting.com
Tue Jun 24 12:53:29 EDT 2014


Mark,

In your example log.txt is a target file and not a sideeffect.
You may need to write an emitter and a proper builder for this.
Or a third builder which depends on :
log1.txt and log2.txt and generates log.txt
(where logN.txt is generated by each Command)

-Bill


On Tue, Jun 17, 2014 at 4:45 AM, Mark Holloway <hollowaymr at hotmail.com>
wrote:

> 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 -n
> scons: Reading SConscript files ...
> scons: done reading SConscript files.
> scons: Building targets ...
> copy file1.in file1.out >> log.txt
> copy file2.in file2.out >> log.txt
> Archive(["thing.zip"], ["log.txt"])
> scons: done building targets.
>
> # 4 Jobs: Note the missing archive step.
> C:\Users\Build\testme>scons --jobs=4 -n
> scons: Reading SConscript files ...
> scons: done reading SConscript files.
> scons: Building targets ...
> copy file1.in file1.out >> log.txt
> copy file2.in file2.out >> log.txt
> scons: done building targets.
>
> # So I take a look at the dependencies, and they all seem fine:
> C:\Users\Build\testme>scons -n --tree=prune
> scons: Reading SConscript files ...
> scons: done reading SConscript files.
> scons: Building targets ...
> copy file1.in file1.out >> log.txt
> copy file2.in file2.out >> log.txt
> Archive(["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
>
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> http://four.pairlist.net/mailman/listinfo/scons-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20140624/f2af4a41/attachment.html>


More information about the Scons-users mailing list