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

Pieter van der Meulen Pieter.vanderMeulen at surfnet.nl
Mon Jan 4 15:07:56 EST 2016


Update because I included a wrong SConstruct file in my first email.

> On 4 Jan 2016, at 17:08, Pieter van der Meulen <Pieter.vanderMeulen at surfnet.nl> wrote:
> 
> 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.

** SConstruct file **

DefaultEnvironment(tools = []) # Disable default tools
AllowSubstExceptions() # Report all variable expansion problems

# Setup a build environment and add out own commands (tools) to it
env = Environment()

root_dir=Dir('#').abspath   # Root directory (i.e. the directory of this SConstruct)
AddOption('--build-dir', dest='build-dir', type='string', nargs=1, action='store', metavar='BUILDDIR',
          help='build directory',
          default=root_dir )
build_dir = GetOption('build-dir')   # The directory to build into

AddOption('--no-download', dest='do_download', action='store_false', default=True,
          help='Disable download')

do_download = GetOption('do_download')

print "Building from directory: %s" % root_dir
print "Using build directory: %s" % build_dir
print "Download: %s" % do_download

# Include the "SConscript" file that contains the actual build commands
if (build_dir != root_dir):
    Mkdir(build_dir) # Make sure build dir exists
    env.SConsignFile(build_dir+'/.sconsign.dblite') # Keep scons database in the build directory
    SConscript( 'SConscript', exports='env', variant_dir=build_dir, duplicate=1 )
else:
    SConscript( 'SConscript', exports='env' )

> ** 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")
> 
> 
> ** 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/4a07d3f4/attachment.bin>


More information about the Scons-users mailing list