[Scons-users] use of abspath

Jack Brennen jbrennen at qti.qualcomm.com
Fri Aug 11 14:17:07 EDT 2017


Perhaps this is obvious, but the flip side of abspath comes in useful in 
one case that I use a lot.  I will often have a build generate scripts 
which contain references to other files which are built.  These scripts 
are intended for execution outside of the SCons environment.  In those 
cases, I'll use abspath processing so that the file name referenced in 
the script is absolute instead of relative.  Makes the script work 
correctly no matter where you run it from.  One of the main places I do 
this is something like this:

 1. Build target_program.
 2. Build a script named debug_target_program, which when executed,
    loads up target_program in a debugger with the proper configuration
    and symbol information, etc.
    In this script, there are no relative paths; all paths are absolute.

So another compelling reason to use an absolute path is when you're 
expecting something outside the project tree to refer to something 
inside the project tree -- sort of the opposite of your proposed use case.

- Jack


On 8/11/2017 10:18 AM, Mats Wichmann wrote:
> 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')
> _______________________________________________
> 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/20170811/196c995c/attachment-0001.html>


More information about the Scons-users mailing list