Get path to jamfile directory from id in boost build/b2/bjam

43 Views Asked by At

In my jamroot I have

use-project /myproject : $(TOP)/path/to/jamfile/dir/of/my/project ;

use-project is documented here.

Let's say myproject defines a library mylib

I can then do in a jamfile:

lib myotherlib : $(SRC)
                 /myproject//mylib<link>shared
                 ;

instead of:

lib myotherlib : $(SRC)
                 relative/path/to/jamfile/dir/of/my/project//mylib<link>shared
                 ;

But how can I programmatically get the path that the id /myproject points to, i.e. $(TOP)/path/to/jamfile/dir/of/my/project ?

This could be useful for various reasons:

  • not have to define ids for subprojects of "myproject" (i.e. jamfiles in subdirectories of $(TOP)/path/to/jamfile/dir/of/my/project)
  • share some resources files
1

There are 1 best solutions below

0
Gabriel Devillers On

Here is one function that allows that:

rule get_path_for_id ( id )
{
    import project ;
    local jamfile_for_id = [ project.find $(id) : . ] ;
    return [ project.attribute $(jamfile_for_id) location ] ;
}

You can use it like this:

myproject_dir = [ get_path_for_id /myproject ] ;
lib myotherlib : $(SRC)
                 $(myproject_dir)//mylib<link>shared
                 ;

(which is just an example, the id would be better here, obviously).

Note: I found no clean way to avoid an intermediary variable, only the ugly:

import string ;
lib myotherlib : $(SRC)
                 [ string.join [ get_path_for_id /myproject ] //mylib<link>shared ]
                 ;