Repository navigation
Description
Describe the bug
scons does not appear to be correctly find dependencies on *.mod files in Fortran files.
My project includes a Fortran library that includes a number of source files and a module including some shared variables. When compiling on windows with ifort, I get the following error when doing a clean build:
error #7002: Error in opening the compiled module file. Check INCLUDE paths.
Subsequent builds complete successfully.
Investigation shows that the above compiler error is seen because the *.mod file required by the source files is not built before the source file compilation. Reordering the list of source files improves the situation, but it still fails periodically when building in parallel. Subsequent attempts to compile work as the *.mod file is created during the first scons attempt and are thus already available.
Per suggestion from discord, I ran scons with --tree=prune to check if the consumers of the module correctly listed the *.mod file as a build dependency. The output below (anonymized) shows the output for one of the source files:
| +-<path>\<objName>.staticrt.obj
| | +-<relativePath>\<srcFile>.f
| | +-C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.5.281\windows\bin\intel64\ifort.EXE
Note that the source file does not list the *.mod file as a dependency.
The project is cross-platform so I also checked the result of --tree=prune on linux (compiled with gfortran). Scons also did not recognize the dependency on the mod file (output was the same as above with the exception of the compiler path). However, the code compiles without issue on linux.
Since the above shows that the source files are not identifying the *.mod file as a build dependency, my assumption is that there is some issue in the way that scons is determining dependencies for Fortran files. I'm not sure why there's not an issue with gfortran on linux.
Required information
- Link to SCons Users thread discussing your issue.
discussed on the scons discord (fortran-support channel) - Version of SCons
3.1.2 - Version of Python
3.7.13 - Which python distribution if applicable (python.org, cygwin, anaconda, macports, brew,etc)
cpython - How you installed SCons
pip install - What Platform are you on? (Linux/Windows and which version)
Windows 10 Enterprise version1909 - How to reproduce your issue? Please include a small self contained reproducer. Likely a SConstruct should do for most issues.
- How you invoke scons (The command line you're using "scons --flags some_arguments")
scons -j8
Activity
james-thunes commentedon Jun 15, 2022
I haven't been able to get a small test case set up yet. I will try to create one and post to this issue
dnwillia-work commentedon Jun 15, 2022
I'll just add that when I was testing this locally it seems to only be reproducible when running a parallel build with
-jN. A serial build would do things in the right order and I never saw that fail, but for parallel it's failing when a dependent source file is compiled concurrently before the module is complete.bdbaddog commentedon Jun 15, 2022
That's just luck... If parallel builds fail due to missing dependencies (for any build system), it means the build system doesn't have all the appropriate dependencies and so isn't building everything needed for the failing build step. I run into this often (though mainly with non-scons based build systems where it's harder to get this right)..
dnwillia-work commentedon Jun 15, 2022
Yeah, fair enough. Even for the parallel builds I'll add that it would sometimes work, sometimes not.
I wonder since it seems to be a windows specific thing then is something else going on. eg: the .mod file is still locked by the OS so the dependent module cannot link against it. We have run into this kind of issue with .lib (import library) files on windows parallel builds before as well if an
Install()was used to move the .lib file to some other place before it was linked into dependent module despite the fact that we would addDepends()on the install task to the dependent module. We removed the use ofInstall()targets for this as a result and it got better.bdbaddog commentedon Jun 15, 2022
Ugh.. the joys of NTFS..
bdbaddog commentedon Jun 15, 2022
How are you creating your Environment()? Specifically are you setting
FORTRANSUFFIXES(or any of theF*SUFFIXESenv vars)?bdbaddog commentedon Jun 15, 2022
Try adding this to your Environment()
FORTRANFILESUFFIXES=['.f90'],james-thunes commentedon Jun 15, 2022
this particular library has all *.f files, but I can try setting
FORTRANFILESUFFIXES=['.f'],dnwillia-work commentedon Jun 15, 2022
We definitely do not configure that particular variable currently. We do configure these variables related to this issue
It's the same for
ifortandgfortran.mwichmann commentedon Jun 17, 2022
Okay, I've located a simple example and don't see the problem with it. Here's the tree dump:
main-list.ois shown as depending on its source file, onlistmodule.mod, and on the compiler. That looks right to me? What am I missing?bdbaddog commentedon Jun 17, 2022
@mwichmann - I think this is only an intel fortran issue. And I think it's due to loading default tools, then ifort and having files named .f when ifort looks like it only wants files named .i or .i90?
bdbaddog commentedon Jun 17, 2022
Did that work?
mwichmann commentedon Jun 17, 2022
I still have to look at the .i/.i90 thing, I think it should work just find on ordinary suffixes and I don't know what those actually mean.
james-thunes commentedon Jun 17, 2022
Sorry, been busy with other tasks. Will try to get to this as soon as I can.
james-thunes commentedon Jun 20, 2022
Ok, I was able to spend a bit of time with this today. I'm a bit confused to be honest. Setting
FORTRANFILESUFFIXES=['.f'],did indeed appear to resolve the issue. I was able to see the module dependencies when looking at the output with--tree=prune. However, removing the flag and doing a clean rebuild of the code I see that the module dependencies is still seen. It definitely wasn't last week...45 remaining items
mwichmann commentedon Jun 30, 2023
Okay, a little more light on the non-copying variantdir: sources are absolute paths in this case, but targets shouldn't be so they can be handled by the variant code. But the module that will be generated, as detected by the emitter (not via the scanner, btw, but by using a regex that's supposed to stay in sync with the one in the scanner), has the absolute-path form.
So I presume that this snip from FortranCommon is the wrong way to generate the target node(s) for modules:
mwichmann commentedon Jun 30, 2023
If it helps to be explicit - it's not just that the module paths here are absolute, it's that they're to what would be considered the "source directory", as in:
absolute-path-to-topdir
/TestSConscript/module_one.modthe module file will never appear there... it will either be in the topdir if there's no
FORTRANMODDIR, or in the build directory specified by the variantdir if it is set as in the sample.mwichmann commentedon Jul 2, 2023
Okay, I'm just repeating stuff that's already been said, but module handling seems pretty broken. I set up another small test with a trivial module source file, repeated four times (uniqued for each version):
srcsubdirectory with own SConscriptvsrcsubdirectory, SConscript called as duplicating variantdirbuildvsrc-nosubdirectory, SConscript called as non-duplicating variantdirbuild-noCalling
Object()on each, with no setting ofFORTRANMODDIR, so the default empty string, which won't expand to any-Joption togfortran, you expect to get four object files and four.modfiles, and so we do:But that doesn't match what SCons thinks it did, which means we have a problem (the tree is trimmed to show only these eight):
It's never good when SCons builds up a picture of what exists, and then that's not what the compiler did. The simplest problem from that is you can't clean, but there's plenty more issues, like rebuilds being horked, etc.
mwichmann commentedon Jul 2, 2023
Now, if we redo the above with the experimental setting of
FORTRANMODDIR, so it's force-passed on every build, we at least get consistency:Giving us:
And the tree at least now matches what was built:
But that hasn't got into the other case of trying to
USEthese modules, and whether they're found where they got put so other sources will build.dnwillia commentedon Jul 2, 2023
Yup. At least you can reproduce what I’m also seeing.
mwichmann commentedon Jul 2, 2023
I thought I had a cute fix for the "if there's no
FORTRANMODDIR, SCons is out of sync with what the compiler does" problem, but it turns out an extra bit of variantdir cleverness defeats that in one case. Still thinking. This was the idea:mwichmann commentedon Jul 3, 2023
So the odd bit is recorded, it seems, if you set a relative path for
FORTRANMODDIR, and use a non-duplicating variantdir, scons will double the flag usage, emitting one module dir for the target (variant) directory and one for the original source directory, and that's illegal. Likewhich leads to:
I don't think I've caused this....
Leaving it out (the default is an empty string), or using a top-relative path (
"#/modules") does not cause this effect.mwichmann commentedon Jul 4, 2023
If a relative path is used, then
RDirs, the function passed in the_concatcall, is the one that makes this mess.So this:
has the prospect of producing something illegal, with Fortran compilers not accepting multiple module-directory options. I think it's better not to apply this particular transformation (i.e., leave out
RDirsfrom the generation of this flag.)mwichmann commentedon Jul 5, 2023
Hoo boy, this simple little matter might end up being a hair-loss event...
mwichmann commentedon Jul 10, 2023
Okay, this conclusion was just bogus. At SConscript evaluation time, the context is the directory of the SConscript, so it makes sense for the
substhere to come back with.. Ignore me...dnwillia commentedon Dec 30, 2024
OK so an update to this finally... Today I tried out all my tests posted at
https://github.com/dnwillia/SConsTests
and everything is building properly at release
v4.8.1on MacOS using gfortran. Great progress.I'll give it a shot with Linux/windows with both Intel (Windows/Linux) and GNU fortran (Linux) next week. @james-thunes
james-thunes commentedon Dec 31, 2024
great to hear. Thanks for giving it another try. And thanks to the developers for addressing :)
dnwillia commentedon Jan 9, 2025
OK so I would say I can confirm that on Linux and MacOS that the code in my test repo compiles with v4.8.1 out of the box with gfortran on Linux and MacOS. It's also working on windows up to the linker step, where linking fails, but that's a separate issue from this one.
@james-thunes Maybe you can close this issue unless you still see problems.