[Scons-users] Problems with SConscript files using variant_dir and duplicate=False

Hans-Christian Wild hchr.wild at gmail.com
Thu May 21 13:54:00 EDT 2020


Hi,

I have two questions about SCons, I have uploaded a *working* example as
base where SCons does everything nearly as I want it. The problems start to
occur only when we do slight modifications to this example.

https://github.com/hchrwild/scons01/tree/master

In the project we have a main SConstruct file in `/example/mingw/` which
imports a library SConscript file from `/`. The SConscript file creates its
little library for the given environment and returns it together with its
public header include path. The SConstruct file in turn builds an
executable linking the static library and using the public header include
path.

Output:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: target\mylib\example\mingw
gcc -o target\src\main.obj -c -Itarget\mylib\include target\src\main.c
gcc -o target\mylib\src\Assert.obj -c -Itarget\mylib\include
-Itarget\mylib\src\include target\mylib\src\Assert.c
ar rc target\mylib\libmylib.a target\mylib\src\Assert.obj
gcc -o target\mingw-example.exe target\src\main.obj target\mylib\libmylib.a
scons: done building targets.

*Perfect!*
(Although I don't understand why it prints `building associated VariantDir
targets: *target\mylib\example\mingw*` which to me does not make sense, IMO
it should be *`example/mingw/target/mylib`* if anything, but let's put that
aside..)

*Now the actual problems:*

1) I don't like that SCons duplicates everything. What I really want is an
out-of-source variant build. When I set `duplicate=False`, the build fails,
however:

mylib_a, mylib_h = SConscript('../../SConscript', exports='env', variant_dir
='target/mylib', duplicate=False)

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: .
gcc -o target\src\main.obj -c *-Itarget\mylib\include* target\src\main.c
target\src\main.c:4:10: fatal error: Types.h: No such file or directory
 #include <Types.h>
          ^~~~~~~~~
compilation terminated.
scons: *** [target\src\main.obj] Error 1
scons: building terminated because of errors.

As marked in above output, the include path is not updated. The SConscript
file is at `../../` relative to SConstruct, and the include folder is
./include relative to SConscript. Therefore, without duplication, the
correct include path relative to SConstruct would be `../../include` ,
which SCons does not seem to compute however. Is this expected or a missing
feature/bug? I really like the idea, that the SConstruct file really only
needs to know where the SConscript file is located and having everything
else being figured out by the build system...

2) Let's put that aside and keep above change, but hardcode the expected
include path in SConstruct file:

program = env.Program('target/mingw-example', sources, CPPPATH=[
'../../include'], LIBS=[mylib_a])

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: .
gcc -o target\src\main.obj -c -IW:\Projects\mylib\include target\src\main.c
gcc -o target\mylib\src\Assert.obj -c *-Itarget\mylib\include
-IW:\Projects\mylib\include -Itarget\mylib\src\include
-IW:\Projects\mylib\src\include* W:\Projects\mylib\src\Assert.c
ar rc target\mylib\libmylib.a target\mylib\src\Assert.obj
gcc -o target\mingw-example.exe target\src\main.obj target\mylib\libmylib.a
scons: done building targets.

Now the compilation succeeds. However, scons has now duplicated the include
paths for the static library! One time with the invalid
variant-with-duplication path, and one time with the correct (absolute
path). Why does it do that? Is this a bug?

Sorry for the long post. Any feedback appreciated!

-hans
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20200521/d94eea20/attachment.html>


More information about the Scons-users mailing list