开发者

Why the success of SCons build depends on variant_dir name?

I am bored to death with such behavior. So in SConstruct file we have the last string like this one:

import compilers, os

env = Environment(ENV = os.environ, TOOLS = ['default'])

def set_compiler(compiler_name):
    env.Replace(FORTRAN = compiler_name)
    env.Replace(F77 = compiler_name)
    env.Replace(F90 = compiler_name)
    env.Replace(F95 = compiler_name)

def set_flags(flags):
    env.Replace(FORTRANFLAGS = flags)
    env.Replace(F77FLAGS = flags)
    env.Replace(F90FLAGS = flags)
    env.Replace(F95FLAGS = flags)

mod_dir_prefix = {
    "gfortran": "-J ",
    "ifort": "-???",
    "pgfortran": "-module " 
}

flags = {
    ("gfortran", "debug"): "-O0 -g -Wall -Wextra -pedantic -fimplicit-none -fbounds-check -fbacktrace",
    ("gfortran", "release"): "-O3",
    ("pgfortran", "debug"): "-O0 -g -C -traceback",
    ("pgfortran",  "release"): "-O4"
}

if not GetOption('clean'):
    print "\nAvailable Fortran compilers:\n"

    for k, v in compilers.compilers_dict().iteritems():
        print "%10s : %s" % (k, v)

    compiler = raw_input("\nChoose compiler: ")

    set_compiler(compiler)

    debug_or_release = raw_input("\nDebug or release: ")

    set_flags(flags[(compiler, debug_or_release)])

    env.Replace(FORTRANMODDIRPREFIX = mod_dir_prefix[compiler])

    env.Replace(LINK = compiler)
    env.Replace(LINKCOM = "$LINK -o $TARGET $LINKFLAGS $SOURCES $_LIBDIRFLAGS $_LIBFLAGS $_FRAMEWORKPATH $_FRAMEWORKS $FRAMEWORKSFLAGS")
    env.Replace(LINKFLAGS = "")

env.Replace(FORTRANMODDIR = '#Mod')
Export('env')

SConscript('Sources/SConscript', variant_dir='Build', duplicate=0)

compilers.py is my own module to find some Fortran compilers which are available.

In Sources folder we have a couple of Fortran source files.

Sources\SConscript

Import('env')
env.Program('app', Glob('*.f90'))

Scons supports Fortran and everything works fine.

gfortran -o Temp\kinds.o -c -O3 -JMod Sources\kinds.f90
gfortran -o Temp\math.o -c -O3 -JMod Sources\math.f90
gfortran -o Temp\sorts.o -c -O3 -JMod Sources\sorts.f90
gfortran -o Temp\utils.o -c -O3 -JMod Sources\utils.f90
gfortran -o Temp\main.o -c -O3 -JMod Sources\main.f90
gfortran -o Temp\app.exe Temp\kinds.o Temp\main.o Temp\math.o Temp\sorts.o Temp\utils.o
scons: done building targets.

After renaming variant_dir name to let say #Bin or #Build we get error message:

gfortran -o Bin\kinds.o -c -O3 -JMod Sources\kinds.f90
gfortran -o Bin\main.o -c -O3 -JMod Sources\main.f90
Sources\main.f90:3.11:

  USE sorts
           1
Fatal Error: Can't open module file 'sorts.mod' for reading at (1): No such file or directory

Of course the order of compilation matters. But why it depends on variant_dir name? Seems like a bug, but maybe I'm doing something wrong.

P.S. This behavi开发者_开发技巧or doesn't depend on duplicate variable value.

P.P.S. Tested with SCons 2.0.1 on Windows with Python 2.7 and Mac OS X with Python 2.5.1.


This is a reply to an old thread, but I had virtually the same problem and needed to dig around for a solution.

Firstly, your build order is probably off because the dependency scanner for Fortran does not work properly. Try running

scons [your_arguments] -n --tree=all | less

which won't actually compile anything but show you the commands and in the end will print the dependency tree as Scons sees it.

A possible solution:

Try adding the line (I added your source for context):

env.Replace(FORTRANMODDIR = '#Mod') env.Replace(FORTRANPATH = '.' ] Export('env')

As far as I understand, paths are relative to the "virtual" location of the SConscript file (i.e. the src directory or the variant build directory), this should add the directory containing the source files to the scanner's search path.

In my version of scons (2.3.0), I cannot use the duplicate=0 argument, since it automatically inserts the original source directory into the module path, causing the command line to look like -module build/ -module src/ (ifort) and essentially overriding my preference not to clutter the source directory. This might be a bug, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜