[Scons-users] use of abspath

Mats Wichmann mats at wichmann.us
Fri Aug 11 13:18:35 EDT 2017


Bear with me, this project is taking me a really long time to sort out,
there are 20,000 lines in aggregate in the sconscripts.

One of the things I've been chasing is builds which bypass VariantDir -
where objects land in the src directory rather than in the variant.

Some of the reasons for this are pretty obvious, those places using
"native Python" in a way that leaves scons out of the loop:

src_dir = os.path.abspath(os.curdir)

some_env.PrependUnique(CPPPATH=[src_dir])

src_files = [
    os.path.join(src_dir, 'somefile.c'),
    ...


src_dir is thus an absolute path obtained outside scons which has no
chance to do the appropriate substitution.  A simple change to:

src_dir = Dir('.').abspath

moves things in the direction I want.

that's not really the question, though.  Along the way I get curious,
why 'abspath'?  Is there a compelling reason to use an absolute path
_except_ when referring to things that are outside the project tree
(system files, cross-compile toolchains, the like: there an abspath
makes sense to me)?  Since .path is relative to the top of the tree,
wouldn't that do as well?

In fact, is there a better model for referring to source files in
target-specific subdirectories, which is what is happening here?

Namely, a script in one directory starts building a list of files for
eventually passing to a builder, call it FOO_SRC, from common files,
then based on target, or based on selection from a list of supported
interfaces, calls an sconscript in an appropriately named subdirectory
which adds to FOO_SRC:

some_env.AppendUnique(FOO_SRC=src_files)

For building that list, is there a better model than using:

    os.path.join(full-path-to-current-subdir, 'somefile.c')


More information about the Scons-users mailing list