[Scons-users] Using/keeping previously generated files in a variant_dir

Pieter van der Meulen Pieter.vanderMeulen at surfnet.nl
Mon Jan 4 11:08:26 EST 2016


Hi

I'm using scons to manage a build process which downloads a source file during the build. This file is big and changes periodically. I want to add a “--no-download" option to the scons build that optionally skips downloading this file and uses the previously downloaded version. Without using a variant_dir this works as expected for me, when using a variant_dir this does not work because at the beginning of the build scons removes the downloaded file (/tmp/build/downloadedfile) from the variant_dir. 

Is there a way to make scons retain a file in a variant directory? Or is there an alternative or better way in scons to achieve this effect?

Below a minimalised SConscript and SConstruct and the output of running them. I’m using scons 2.4.1.

** SConscript file **
Import('env')

do_download = GetOption('do_download')

if do_download:
    n=env.Command( target="downloadedfile", source="", action="date > ${TARGET}" )
    env.Precious(n)

env.Command( source="downloadedfile", target="output", action="cp ${SOURCE} ${TARGET}")
env.AlwaysBuild("output")

** SConstruct file **
# SConscript

Import('env')

do_download = GetOption('do_download')

if do_download:
    n=env.Command( target="downloadedfile", source="", action="date > ${TARGET}" )
    env.Precious(n)

env.Command( source="downloadedfile", target="output", action="cp ${SOURCE} ${TARGET}")
env.AlwaysBuild("output”)


** Not using variant dir **
$ scons
scons: Reading SConscript files ...
Building from directory: /opt/example
Using build directory: /opt/example
Download: True
scons: done reading SConscript files.
scons: Building targets ...
date > downloadedfile
cp downloadedfile output
scons: done building targets.

$ scons --no-download
scons: Reading SConscript files ...
Building from directory: /opt/example
Using build directory: /opt/example
Download: False
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.


** Using variant dir **
$ scons --build-dir=/tmp/build
scons: Reading SConscript files ...
Building from directory: /opt/metadata/example
Using build directory: /tmp/build
Download: True
Mkdir("/tmp/build")
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: /tmp/build
date > /tmp/build/downloadedfile
cp /tmp/build/downloadedfile /tmp/build/output
scons: `.' is up to date.
scons: done building targets.

$ scons --build-dir=/tmp/build --no-download
scons: Reading SConscript files ...
Building from directory: /opt/metadata/example
Using build directory: /tmp/build
Download: False
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: /tmp/build
scons: *** [/tmp/build/output] Source `/tmp/build/downloadedfile' not found, needed by target `/tmp/build/output'.
scons: building terminated because of errors.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4312 bytes
Desc: not available
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20160104/a3a84727/attachment.bin>


More information about the Scons-users mailing list