[Scons-users] SCons messes up ordering with VariantDir

Markus Ewald cygon at nuclex.org
Sun Sep 29 05:54:24 EDT 2019


Hi!

I'm trying to write a SCons script that performs the following three steps:

     1. Download a source code archive

     2. Extract sources from said archive

     3. Compile the extracted sources


I've correctly set up the dependencies and it works well without using 
env.VariantDir() - even when running 'scons -j16'.

However, as soon as I use env.VariantDir(), SCons will attempt to 
compile the source code before it is extracted.


Quoted at the bottom if this message is my current script that 
reproduces the issue. It has no dependencies besides SCons and a Linux 
environment.

Delete the 'build', 'bin' and 'obj' directories if they exist from a 
previous run, then run with 'scons -j16' to reproduce the error:


What am I doing wrong?


    #!/usr/bin/env python

    import sys
    import importlib
    import os

    #
    -----------------------------------------------------------------------------------------------
    #

    def rebase(file_list, old_directory, new_directory):
         """Quick and dirty stand-in to alter the path of a set of files"""

         rebased_file_list = []

         for file in file_list:
             rebased_file_list.append(str(file).replace(old_directory,
    new_directory))

         return rebased_file_list

    #
    -----------------------------------------------------------------------------------------------
    #

    environment = Environment()

    #
    -----------------------------------------------------------------------------------------------
    #
    # Step 1: Download the current release

    download_url =
    'https://github.com/google/googletest/archive/release-1.8.1.tar.gz'

    # Determine the target filename for the download (below 'downloads'
    folder)
    archive_filename = os.path.basename(download_url)
    archive_file = environment.File(os.path.join('downloads',
    archive_filename))

    # Tell SCons how to "produce" the downloaded archive (by calling wget)
    download_archive = environment.Command(
         source = None, # The real world script points to a
    'download_url' file
         action = 'wget ' + download_url + ' --output-document=$TARGET',
         target = archive_file
    )

    #
    -----------------------------------------------------------------------------------------------
    #
    # Step 2: Extract the release into the build directory

    source_files = [
         'build/googletest/src/gtest.cc',
         'build/googletest/src/gtest-death-test.cc',
         'build/googletest/src/gtest-filepath.cc',
         'build/googletest/src/gtest-port.cc',
         'build/googletest/src/gtest-printers.cc',
         'build/googletest/src/gtest-test-part.cc',
         'build/googletest/src/gtest-typed-test.cc'
    ]

    # Tell SCons how to "produce" the sources & headers (by calling tar)
    extract_archive = environment.Command(
         source = archive_file,
         action = 'tar --extract --gzip --strip-components=1
    --file=$SOURCE --directory=build',
         target = source_files
    )

    #
    -----------------------------------------------------------------------------------------------
    #
    # Step 3: Compile the library

    if False: # Works: waits for the archive to extract, then compiles
         gtest_environment = environment.Clone()
         gtest_environment.Append(CPPPATH=['build/googletest'])
         gtest_environment.StaticLibrary('bin/gtest', source_files)

    else: # Fails: attempts to compile before the archive is extracted
         gtest_environment = environment.Clone()
         gtest_environment.Append(CPPPATH=['build/googletest'])

         gtest_environment.VariantDir('obj/linux-amd64/src',
    'build/googletest/src', duplicate = 0)
         variantdir_source_files = rebase(
             source_files, 'build/googletest/src/', 'obj/linux-amd64/src/'
         )
         gtest_environment.StaticLibrary('bin/gtest',
    variantdir_source_files)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20190929/880808e3/attachment.html>


More information about the Scons-users mailing list