[Scons-users] use of abspath

Bill Deegan bill at baddogconsulting.com
Fri Aug 11 14:31:17 EDT 2017


re abspath in scripts (Jack)
In such cases where you know the relative position of the script and the
resources it needs in your build tree, relative location can be used.
If you used abs path and you move your build anywhere, it stops working.
Take a little more time to setup, but saves the guy who moved the tree
somewhere (or unpacked an archive) from banging his head against the wall
trying to figure out why it doesn't work.

re: abspath and scons in general
That said one of the uses for abspath within scons that I've seen is in the
case where you have a script which must be run in the directory it's
sources reside in (and you can't rewrite for some reason), then having a
command string like
env.Command('output.file','input.file','cd ${SOURCE.dir}; ./dumb_script.sh
$SOURCE > ${TARGET.abspath}')

Or similiar where you must do something when not residing in the top level
dir..
-Bill

On Fri, Aug 11, 2017 at 11:17 AM, Jack Brennen <jbrennen at qti.qualcomm.com>
wrote:

> 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 listScons-users at scons.orghttps://pairlist4.pair.net/mailman/listinfo/scons-users
>
> .
>
>
>
>
> _______________________________________________
> 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/7e95adde/attachment.html>


More information about the Scons-users mailing list