scons icon indicating copy to clipboard operation
scons copied to clipboard

Scons crash when two targets produce the same file

Open lurobi opened this issue 5 years ago • 1 comments

Describe the bug When two targets both create the same output file, the Node's get_build_env() returns None on the second call, causing a Python crash.

In my case, the output file is a .mod file generated during the compilation of test1.f90i. The test1.f90 file is compiled twice, once to produce a .os and once to produce a .o file. Both compilations produce mod1.mod, because test1.f90 defines the mod1 module.

Expected: Either success, or a warning indicating conflicting output files Observed: Partial build ending with AttributeError: 'NoneType' object has no attribute 'get_build_env':

This bug prevents simultaneous builds of both .so and .a libraries in the same scons invocation for Fortran.

Required information

  • Link to SCons Users thread discussing your issue: https://pairlist4.pair.net/pipermail/scons-users/2020-April/008090.html
  • SCons Versions: v3.0.1 (WSL Ubuntu) and v3.1.2 (msys2)
  • Python Version 3.7
  • Scons installed via apt-get on ubuntu, and pacman on msys2
  • What Platform are you on? Both Linux and Windows
$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gfortran -o test1.os -c test1.f90
gfortran -o msys-testlib-shared.dll -Wl,-no-undefined -shared -Wl,--out-implib=libtestlib-shared.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--whole-archive test1.os -Wl,--no-whole-archive
gfortran -o test1.o -c test1.f90
scons: done building targets.
AttributeError: 'NoneType' object has no attribute 'get_build_env':
  File "/usr/lib/python3.7/site-packages/SCons/Script/Main.py", line 1381:
    _exec_main(parser, values)
  File "/usr/lib/python3.7/site-packages/SCons/Script/Main.py", line 1344:
    _main(parser)
  File "/usr/lib/python3.7/site-packages/SCons/Script/Main.py", line 1119:
    nodes = _build_targets(fs, options, targets, target_top)
  File "/usr/lib/python3.7/site-packages/SCons/Script/Main.py", line 1318:
    jobs.run(postfunc = jobs_postfunc)
  File "/usr/lib/python3.7/site-packages/SCons/Job.py", line 111:
    self.job.start()
  File "/usr/lib/python3.7/site-packages/SCons/Job.py", line 216:
    task.executed()
  File "/usr/lib/python3.7/site-packages/SCons/Script/Main.py", line 256:
    SCons.Taskmaster.OutOfDateTask.executed(self)
  File "/usr/lib/python3.7/site-packages/SCons/Taskmaster.py", line 312:
    t.push_to_cache()
  File "/usr/lib/python3.7/site-packages/SCons/Node/FS.py", line 2967:
    self.get_build_env().get_CacheDir().push(self)
  File "/usr/lib/python3.7/site-packages/SCons/Node/__init__.py", line 654:
    result = self.get_executor().get_build_env()

Test1.f90:

module mod1
    integer :: mod1_int
end module

Sconstruct:

env = Environment()
src = ['test1.f90']
env.SharedLibrary('testlib-shared',src)
env.StaticLibrary('testlib-static',src)

lurobi avatar Apr 28 '20 20:04 lurobi

@mwichmann. I think this should be working now but you need to use a variant dir to compile the two libraries. That is now working properly as of v4.8.1. See #4177 for a bit more details.

dnwillia avatar Jan 09 '25 19:01 dnwillia