[Scons-users] Confused on VariantDir and build outputs on large project

Carl Cerecke carl.cerecke at compacsort.com
Tue Dec 3 15:10:47 EST 2013


Thanks Francis for your detailed example. I think I will adapt your
approach for our situation.

One thing I am still struggling with is getting the VariantDir to have any
effect:

SConstruct 1 (doesn't work - doesn't use 'build' dir)

env.VariantDir('build','.')
env.Export(shared=env)
env.SConscript(['SConscript'])

SConstruct 2 (does work. Uses 'build' dir)

env.Export(shared=env)
env.SConscript(['SConscript'], variant_dir='build')

I can just use the variant_dir named arg of version 2, but I'd like to know
why version 1 doesn't work.

Cheers,
Carl.




On 3 December 2013 16:37, Francis Bolduc <fbolduc at gmail.com> wrote:


> > Firstly, I don't think it is a good idea to use the default 'duplicate'

> semantics

> > of variant_dir. There are simply far too many files for them to be copied

> > around so often. And the reasons for 'duplicate' do not apply to me (it

> seems

> > to be that duplicate=0 should be the default, not duplicate=1).

>

> The reasoning behind duplicating the source files in the variant dir

> is to guarantee reproducible builds. In order to do this, SCons must

> know *all* the dependencies of your source files. So, by copying all

> the files that it knows about in a separate directory (ie: the variant

> dir), then any missing dependency won't be there and will fail the

> build.

>

> Obviously, copying files around is costly. So the idea of duplicate=0

> is to do a bastard approach where SCons get's creative with the

> command lines to build stuff in the variant dir, but use source files

> from their actual location.

>

>

> > But now my problem is that the include dirs are being interpreted

> relative

> > to the build dir, and not the source dir. In the SConscript I have:

> > env.Append(CPPPATH=['../FooBar']) # I want this to be relative to the dir

> > the SConstruct file is in.

>

> Using ".." with variant dir is a recipe for pain. As you found out,

> this will be relative to the variant dir, and not the SConscript dir.

> If you really can't have your SConscript files in the same directory

> as your SConstruct, then you could use the # character, which is

> replaced by the path to the SConstruct. Like this:

>

> env.Append(CPPPATH=['#/woot/FooBar'])

>

>

> > Furthermore, there is some current directory wierdness going on.

> > In the SConscript file, I have "print os.getcwd()"

> > If the build dir is nonexistent, the first time I run I get cwd as the

> > directory with the SConscript in. This makes sense to me.

> > The second time I run, the cwd is the build dir! Even though, with

> > duplicate=0, the build dir is empty. Yet somehow, cppFiles =

> > Glob('*.cpp') still gets the correct files from the src dir (the one

> > with the SConscript file).

> >

> > I just want the compiled files to end up in a directory that I specify.

> > This cannot be as hard as it seems to be right now...

>

> Yes, you seem to be fighting an uphill battle. As I previously said, I

> was in the same situation 3 years ago, and I decided to stop fighting

> SCons. I simply accepted that I had to put the SConstruct and

> SConscript files at the top-level of my project, and then everything

> started working like a charm.

>

> You can try to fight it. Who knows, maybe you'll win. But if you want

> stuff to just work, I recommend you have the following tree for your

> project:

>

> somewhere/SConstruct

> somewhere/A.SConscript

> somewhere/A/include

> somewhere/A/src

> somewhere/B.SConscript

> somewhere/B/include

> somewhere/B/src

> somewhere/C.SConscript

> somewhere/C/include

> somewhere/C/src

> somewhere/P1.SConscript

> somewhere/P1/include

> somewhere/P1/src

> somewhere/P2.SConscript

> somewhere/P2/include

> somewhere/P2/src

>

> With the following content SConstruct:

>

> global = Environment()

> global.VariantDir('build/${NAME}')

> release = global.Clone()

> release['NAME'] = 'release'

> release['DEBUG_SUFFIX'] = ''

> release.AppendUnique(CCFLAGS=['-O2'])

> release.Export(shared=release)

> debug = global.Clone()

> debug['NAME'] = 'debug'

> debug['DEBUG_SUFFIX'] = 'g'

> debug.AppendUnique(CCFLAGS=['g'])

> debug.Export(shared=debug)

> sconscripts = '''

> A.SConscript

> B.SConscript

> C.SConscript

> P1.SConscript

> P2.SConscript

> '''.split()

> for i in sconscripts:

> release.SConscript(i)

> debug.SConscript(i)

>

> And the following content for A.SConscript (same for B and C):

>

> env = shared.Clone()

> env.AppendUnique(CPPPATH=['A/include'])

> env.SharedLibrary('A${DEBUG_SUFFIX}', source=env.Glob('A/src/*.cpp')

>

> And the following content for P1.SConscript (same for P2):

>

> env = shared.Clone()

> env.AppendUnique(CPPPATH=['A/include'])

> env.AppendUnique(CPPPATH=['P1/include'])

> env.AppendUnique(LIBPATH=['.'])

> env.AppendUnique(LIBS=['A${DEBUG_SUFFIX}'])

> env.Program('P1${DEBUG_SUFFIX}', source=env.Glob('P1/src/*.cpp')

>

>

> That is the fundamental thing I do where I work.

> _______________________________________________

> Scons-users mailing list

> Scons-users at scons.org

> http://four.pairlist.net/mailman/listinfo/scons-users

>




--
Carl Cerecke
SENIOR SOFTWARE DEVELOPER



*M:* +64 21 205 0239
*F:* +64 9 634 4491
*Skype:* carl-compac
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://four.pairlist.net/pipermail/scons-users/attachments/20131204/2bbba9e6/attachment-0001.htm


More information about the Scons-users mailing list