3

Let's say I have x.y file in /mydir/a/b (on Linux)
When I run waf, it does not find the file.

def configure(context):
    pass

def build(build_context):
    build_context(source='/mydir/a/b/x.y', 
       rule='echo ${SRC} > ${TGT}', 
       target='test.out')

Result: source not found: '/mydir/a/b/x.y' in bld(features=[], idx=1, meths=['process_rule', 'process_source'] ...

Ok, maybe you want a relative path, Waf? And you are not telling me?

def build(context):

    path_str = '/mydir/a/b'
    xy_node = context.path.find_dir(path_str)
    if xy_node is None:
        exit ("Error: Failed to find path {}".format(path_str))

    # just refer to the current script
    orig_path = context.path.find_resource('wscript')
    rel_path = xy_node.path_from(orig_path)

    print "Relative path: ", rel_path

Result: Error: Failed to find path /mydir/a/b

But that directory exists! What's up with that?

And, by the way, the relative path for some subdirectory (which it can find) is one off. e.g. a/b under current directory results in relative path "../a/b". I'd expect "a/b"

Evgen
  • 194
  • 1
  • 11

3 Answers3

1

In general there are (at least) two node objects in each context: - path: is pointing to the location of the wscript - root: is pointing to the filesystem root

So in you case the solution is to use context.root:

def build(context):
    print context.path.abspath()
    print context.root.abspath()

    print context.root.find_dir('/mydir/a/b')
CK1
  • 694
  • 6
  • 13
0

Hmm, looks like I found an answer on the waf-users group forum, answered by Mr. Nagy himself:

The source files must be present under the top-level directory. You may either:

  • create a symlink to the source directory
  • copy the external source files into the build directory (which may cause problem if there is a structure of folders to copy)
  • set top to a common folder such as '/' (may require superuse permissions, so it is a bad idea in general)

The recommendation in conclusion is to add a symlink to the outside directory during the configuration step. I wonder how that would work, if I need this on both, Linux and Windows...

Community
  • 1
  • 1
Evgen
  • 194
  • 1
  • 11
0

Just pass the Node to the copy rule instead of passing the string representing the path:

def build(build_context):
source_node = build_context.root.find_node('/mydir/a/b/x.y')
build_context(source=source_node, 
   rule='echo ${SRC} > ${TGT}', 
   target='test.out')

Waf will be able to find the file even if outside of the top level directory.

Adriano
  • 487
  • 4
  • 8
  • I went with SCons instead - much more intuitive, and more help and docs available :) – Evgen Feb 07 '17 at 21:29
  • Scons documentation declare it is slower than CMake ( https://bitbucket.org/scons/scons/wiki/SconsVsOtherBuildTools#markdown-header-cmake ). This makes it not really scalable on big flows. – Adriano Feb 09 '17 at 03:49
  • 1
    Much more scalable to develop, though. That wins – Evgen Feb 10 '17 at 19:33