I've been running into a rather odd error involving the use of the scons function Glob in a SConscript. My actual build script is more complicated, but I have narrowed it down to the following minimal example.
In the base SConstruct:
SConscript('SConscript',
variant_dir='build')
Then, in the SConscript:
Glob('*.cc')
This exits, with the error message TypeError : Tried to lookup Dir 'build' as a File. This has been tested with both v2.1.0 and v2.3.0.
I have found a number of workarounds, none of which are entirely satisfactory.
- If I move the SConscript to a subdirectory, scons runs without error. However, that would then require my entire src tree to be moved to a subdirectory, which feels messy.
- If I create the directory
buildprior to running scons, scons runs without error. However, this requires an extra step, and empty directories do not play nicely with git. - I could add a line
Execute(Mkdir('build'))prior to calling the SConscript. However, this does not work when performing a dry run withscons -n. - I can call the SConscript with
duplicate=False, which prevents the error. However, as I understand the documentation, this can cause errors in the build, depending on the location of include files.
I'm fumbling around, and not really understanding the root cause of the issue. Is there a clean solution to this problem?
Edit: It was requested that I add additional details of my intention, not just code that causes the error message. I am attempting to make a build file for cross-compiling both linux executable and Windows executables simultaneously.
First, setting up the compilation environments in the SConstruct.
import os
win32 = Environment()
win64 = Environment()
linux = Environment()
#Define the working directory
win32['SYS'] = 'win32'
win64['SYS'] = 'win64'
linux['SYS'] = 'linux'
#Define the compilers
win32.Replace(CXX='i686-w64-mingw32-g++')
win64.Replace(CXX='x86_64-w64-mingw32-g++')
#Define the appropriate file formats
win32.Replace(SHLIBPREFIX='')
win32.Replace(SHLIBSUFFIX='.dll')
win32.Replace(PROGSUFFIX='.exe')
win32.Append(LINKFLAGS='-static')
win64.Replace(SHLIBPREFIX='')
win64.Replace(SHLIBSUFFIX='.dll')
win64.Replace(PROGSUFFIX='.exe')
win64.Append(LINKFLAGS='-static')
for env in [win32,win64,linux]:
build_dir = os.path.join('build',env['SYS'])
exe = SConscript('SConscript',
variant_dir=build_dir,
exports=['env'])
Then, having the actual build rules in the SConscript.
Import('env')
env.Append(CPPPATH=['include'])
for main in Glob('*.cc'):
env.Program([main, Glob('src/*.cc')])
This exhibits the error message shown above when called with scons -n.