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

Jason Kenny dragon512 at live.com
Mon Jun 6 10:08:24 EDT 2016


I think there are a few tips I can share for this one.

 

 

VariantDir works fine, but has a few quirks. 

 

If you call it yourself, you have to make sure the node that you create are correctly formed with the variant/build path. If you fail to do this the node will not build correctly. For example:

 

VariantDir(“mybuild/dir”,”src/foo”)

F0= File(“src/foo/a.cpp”)

F1= File(“mybuild/dir /a.cpp”)

 

Object(F0) # will build in src/foo, not in mybuild/dir

 

Object(F1) # will build src/foo/a.cpp in mybuild/dir

 

 

For this reason it is much easier to define 

SConscript(…, variant_dir) 

As this will allow you to define the nodes in a more natural way. 

 

 

I found in Parts that I have to define a few extra Variant directory to deal with certain out of tree cases in which people like to define. Since under a SConscript call only one VariantDir() can be active for “source path” remapping I added a function AbsFileNode() and AbsDirNode() to allow me to provide users a function to deal with extra VariantDir() cases that I defined to deal with node out of the current “part/project” location. This code for the most part remaps the path of the node to fit one of the other two VariantDir I define to deal with node under the main SConstruct but outside the “part” directory and one for dealing with file not under the SConstruct directory at all. I would say give Parts a try, but if the details here are that you can write such a function yourself to prevents this problem in a raw SCons based build.

 

I understand there are cases in which people need to define files in odd places, However I find that most of the time this is a legacy issue, or  a special case. Most of the time the user model define in SCons should do the correct thing. Ie call SConscript() with a variant_dir argument.

 

Last of notes, I find the defining duplicate=0 is a speed and space saver as it avoid cases in which SCons cannot hardlink and starts to suck up disk space. Big deal if you try to copy a build around and did not clean up the “VariantDir” first

I also find that it nice to have a common “build” directory based on the location of the SConstruct. To do this adding “#” to the start of the VariantDir path can solve issues you have more than one level of projects/sconscript call from the main Sconstruct. This prevents an issues in which SCons will variant dir with in variant dir that have long paths you might not have expected. For example you might see paths like:

 

Mybuild/foo/mybuild/foo/subfoo

 

When you wanted, or expected mybuild/foo/subfoo

 

This happens when you you have a pattern like:

 

Sconstruct---

 

Sconscript(“foo”,variant_dir=”mybuild/foo”)#1

 

Foo/sconscript ---

 

Sconscript(“subfoo”,variant_dir=”mybuild/foo/subfoo”) #2

 

subfoo/sconscript ---

 

Object(“a.cpp”)

 

 

To fix this:

 

Define #2 variant_dir=”subfoo” instead

 

Or 

 

Define #1 as variant_dir=”#mybuild/foo”

Define #2 as variant_dir=”#mybuild/foo/subfoo”

 

The latter case I fine is best if you define a Variable such as “$BUILD_DIR_ROOT” to be used to define the build/variant directory. It guards you from cases in which files move around and you might have to change the sub component variant directory.

 

Hope this helps!

Jason

 

 

From: Scons-users [mailto:scons-users-bounces at scons.org] On Behalf Of Bill Deegan
Sent: Monday, June 6, 2016 7:57 AM
To: Dirk Bächle <dl9obn at darc.de>; SCons users mailing list <scons-users at scons.org>
Subject: Re: [Scons-users] scons not respecting variant_dir with object files

 

Dirk,

Shouldn't specifying VariantDir() explicitly also work?

-Bill

 

On Mon, Jun 6, 2016 at 3:14 AM, Dirk Bächle <tshortik at gmx.de <mailto:tshortik at gmx.de> > wrote:

Hi,

On 06.06.2016 01:30, Bill Deegan wrote:

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.


actually "No". Please first try rewriting your hierarchy of SConscripts, such that you can use the "variant_dir" option as described in chap 15 "Separating Source and Build Directories" of the UserGuide ( http://scons.org/doc/production/HTML/scons-user.html ). ;)

Regards,

Dirk




_______________________________________________
Scons-users mailing list
Scons-users at scons.org <mailto: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/20160606/4b31d0d3/attachment-0001.html>


More information about the Scons-users mailing list