Search code examples
pythonscons

How to find absolute path in Scons site_tools


I'm running into problems with the difference in environment between SConscripts and custom tools under site_tools.

I'm trying to find the absolute path of a string, which is fine in SConscript:

print File('#something').get_abspath()
>> /home/projects/something

Similar code in site_tools:

from SCons.Node.FS import File
print File('#something').get_abspath()
>> TypeError: __init__() takes exactly 4 arguments (2 given)

So clearly the File() constructed in SConscript is not a SCons.Node.FS.File.

So the questions are:

1) What is the File object in a SConscript, and how can I get one in a builder/site_tools?

2) How can I get the absolute path in site_tools? I need this because I'm constructing command-line arguments for tools which need absolute paths.


Solution

  • This looks like an XY problem to me. If you need the absolute path of single files or directories in your command lines, the construction of the full path should be left to SCons itself. Please check out the MAN page (http://scons.org/doc/production/HTML/scons-man.html or "man scons") under the section "Variable Substitution". You're able to append further specifiers (like abspath in your case) to variables, and they get substituted before command execution. So the command line string for your Builder action could look something like this:

    $MYTOOL -i $SOURCE.abspath $TARGET.abspath