Get node path relative to the SConstruct from inside a SConscript

Viewed 47

In a hierarchical build, one of my SConscript files, located in a sub-directory needs to print paths of a few nodes (for use by an external script). However, the paths need to be relative to the main directory, in which SConstruct resides, not to the sub-directory I'm currently in.

The functions I'm normally use to get node paths are str(node) and node.get_path(). Both of them return the path relative to the sub-directory.

How can I get a path relative to the root directory of the project?

1 Answers

Node object have two properties that appear to store paths relative to the root directory:

  • node.path
  • node.relpath

(link to the manual)

Their descriptions are kinda similar, although, from what information I've managed to gather, node.path is preferable.

Related