[Scons-users] SCons bug when combining CacheDir and MSVC_BATCH

Steve Hill (Wireless) Steve.Hill1 at viavisolutions.com
Wed May 24 08:24:44 EDT 2023


All,

We have recently switched on CacheDir in our CI machine and, while this has largely been a positive experience, we have seen the odd link failure that we could not explain. I was eventually able to reproduce the issue and produce a minimal SConstruct that illustrates the problem.

Firstly, here are the versions that I am using:

$ python --version && scons --version
Python 3.8.10
SCons by Steven Knight et al.:
        SCons: v4.5.2.120fd4f633e9ef3cafbc0fec35306d7555ffd1db, Tue, 21 Mar 2023 12:11:27 -0400, by bdbaddog on M1DOG2021
        SCons path: ['c:\\tmp\\repro\\.venv\\lib\\site-packages\\SCons']
Copyright (c) 2001 - 2023 The SCons Foundation

To reproduce the problem, I have created two C files and a SConstruct:

src/main.c:
=========

void Foo(void);

int main()
{
   Foo();
   return 0;
}

src/foo.c:
========

void Foo(void)
{
   //
}

SConstruct:
==========

CacheDir(r"C:\tmp\cache")

env1 = Environment()
env1["MSVC_BATCH"] = True
env1.VariantDir("build1", "src", duplicate=False)
env1.Program("build1/a.exe", ["build1/main.c", "build1/foo.c"])

env2 = Environment()
env2["MSVC_BATCH"] = True
env2.VariantDir("build2", "src", duplicate=False)
env2.Program("build2/a.exe", ["build2/main.c", "build2/foo.c"])

The steps to reproduce the issue are:


  1.  Perform a build to populate the cache
  2.  Delete build1/main.obj
  3.  Edit src/foo.c (so that it needs to be rebuilt and won't be in the cache)
  4.  Perform another build

At step 4, I would expect src/foo.c to be rebuilt and build1/main.obj to be fetched from the cache, both executables would then be relinked. Instead, I get a link failure:

$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
Retrieved `build1\main.obj' from cache
cl /Fobuild1\\ /c src\main.c src\foo.c /nologo
main.c
foo.c
Generating Code...
link /nologo /OUT:build1\a.exe build1\main.obj build1\foo.obj
Retrieved `build2\main.obj' from cache
cl /Fobuild2\\ /c src\foo.c /nologo
foo.c
link /nologo /OUT:build2\a.exe build2\main.obj build2\foo.obj
LINK : fatal error LNK1181: cannot open input file 'build2\main.obj'
scons: *** [build2\a.exe] Error 1181
scons: building terminated because of errors.

At this point build2/main.obj has been removed (hence the link failure) but running scons again:

$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
Retrieved `build2\main.obj' from cache
Retrieved `build2\foo.obj' from cache
link /nologo /OUT:build2\a.exe build2\main.obj build2\foo.obj
scons: done building targets.

Would you like me to raise an issue on GitHub for this?

Cheers,

Steve.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20230524/116d9172/attachment.htm>


More information about the Scons-users mailing list