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

Pieter van der Meulen Pieter.vanderMeulen at surfnet.nl
Wed Jan 13 08:18:25 EST 2016


> On 5 Jan 2016, at 01:13, Dirk Bächle <tshortik at gmx.de> wrote:
> 
> Pieter,
> 
> On 04.01.2016 21:07, Pieter van der Meulen wrote:
>> 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?
>>> 
> 
> please try downloading the file to the source folder directly in the top-level SConstruct, such that it's not under the influence of the "variant_dir”.

Thanks for the tip, this works well!

Below what I ended up doing using the same example:

==
# SConstruct

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')
download_dir=root_dir
if (build_dir != root_dir):
    if Execute(Mkdir(build_dir)): # Make sure build dir exists
        print "Could not create build directory: %s" % build_dir
        Exit(1)
    build_dir=Dir(build_dir).abspath
    download_dir=root_dir+"/download/"+build_dir
    if Execute(Mkdir(download_dir)): # Make sure downloads dir exists
        print "Could not create download directory: %s" % download_dir
        Exit(1)

env['DOWNLOAD_DIR'] = download_dir
env['DO_DOWNLOAD'] = do_download

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

# Include the "SConscript" files that contain the actual build commands
SConscript( 'SConscript.downloads', exports='env')  # For download files into DOWNLOAD_DIR
if (build_dir != root_dir):
    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.downloads
Import('env')

env.Command( target="${DOWNLOAD_DIR}/downloadedfile", source="", action="date > ${TARGET}” )

==
# SConscript

Import('env')

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

> Best regards,
> 
> Dirk
> 
> 
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users

-------------- 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/20160113/14df9e3e/attachment.bin>


More information about the Scons-users mailing list