[Scons-users] scons not respecting variant_dir with object files

Bill Deegan bill at baddogconsulting.com
Sun Jun 5 19:30:32 EDT 2016


The problem you are running into is the following:
1) You've told SCons that dir/proj maps to build/out
2) You've then asked SCons to build a file in dir/
3) Since dir is not mapped to a variant dir, it builds the file there.

This is not a bug with SCons.  It's an error in your expectations of how
VariantDir (or variant_dir) works.

As Gary mentioned, if you merely want to have the output files explicitly
go somewhere, you can put that as the target in the builder.

If you want to use VariantDir for this:

Perhaps adding
VariantDir('build','proj', duplicate=0)
Would do the trick.

I see you've also posted the same issue in Stackoverflow
http://stackoverflow.com/questions/37645229/scons-not-respecting-variant-dir-with-object-files

Please try explicitly using VariantDir() for the file you're referencing
and see if that resolves the issue.

-Bill

On Sun, Jun 5, 2016 at 5:58 PM, Gary Granger <granger at ucar.edu> wrote:

> I don't use variant_dir much myself, so I'm learning as I go.  From the
> man page I discovered that this setup seems to produce the effect you want:
>
>
> #### SConstruct
>
> VariantDir('build/out', 'dir1', duplicate=0)
> SConscript('build/out/proj/SConscript')
> ####
>
>
> #### dir1/proj/SConscript
>
> StaticLibrary('../mylib', '../mysrc.cpp')
> ####
>
>
> $ scons
> scons: Reading SConscript files ...
> scons: done reading SConscript files.
> scons: Building targets ...
> g++ -o build/out/mysrc.o -c dir1/mysrc.cpp
> ar rc build/out/libmylib.a build/out/mysrc.o
> ranlib build/out/libmylib.a
> scons: done building targets.
>
> It seems like the challenge with absolute paths will be that each
> variant_dir still needs to be associated with a src_dir.  Whether your
> source files are named by relative or absolute path, they must be contained
> in a directory which has been identified as the src_dir for a variant_dir,
> such as with VariantDir().
>
> If you don't really want to create a mirror of your source tree underneath
> the variant_dir, you just want to put output there explicitly, then maybe
> there's an easy way to tweak the builders to put the objects into a
> directory other than the source directory.  The below works, but I'm sure
> it would be important to parameterize the build dir somehow, and it's not
> as flexible as variant dirs.
>
> #### SConstruct
> SConscript('dir1/proj/SConscript')
>
> #### dir1/proj/SConscript
> StaticLibrary('#build/mylib', StaticObject('#build/mysrc.o',
> '../mysrc.cpp'))
>
> Good luck,
> gary
>
> On 06/05/2016 02:44 PM, Bob Loblaw wrote:
>
> If I specify a relative path, that would fix it in this example. I believe
> I would need to change my SConstruct file to say:
>
>
> ####
>
> SConscript('dir1/proj/SConscript',
> src_dir='dir1', variant_dir='build/out', duplicate=0)
>
> ####
>
>
> Which adds the src_dir.
>
>
> What I provided in the original example was a simplified version of how
> I'm using scons. I will actually need to use full absolute paths to the
> source files.
>
>
> Is there a way this works with absolute paths?
>
>
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20160605/8393a485/attachment.html>


More information about the Scons-users mailing list