5

I have the following snippet, to copy a file as-is to the build dir:

for m in std_mibs:
    print("Copying", m)
    bld(name       = 'cpstdmib',
        rule       = 'cp -f ${SRC} ${TGT}',
        #source     =  m + '.mib',
        source     =  bld.path.make_node(m + '.mib'), # <-- section 5.3.3 of the waf book
        target     =  bld.path.get_bld().make_node(m + '.mib')
        )

I see that this rule, though hit (from the print), the copy doesnt seem to be happening! I also changed the source to use the make_node as shown, in an example in the section 5.3.3 of the waf book, still no luck! Am I missing something obvious here!?

Also, I have some rules after this, which rely on the copied files, and I tried adding an intervening

bld.add_group()

I hope that the sequencing will work, if this copy succeeds

Ani
  • 1,448
  • 1
  • 16
  • 38

3 Answers3

1

If you run the rule once, it will not be run again until source is updated. This is true even if the target is deleted, for instance (which is probably how you were testing.)

If you want to recopy if the target is deleted, you will need always=True, or you'll need to check for existence and set target.sig = None.

dbn
  • 13,144
  • 3
  • 60
  • 86
  • I'm still investigating this, clearly this is not a full or complete solution. See also the bottom part of https://download.samba.org/pub/unpacked/waf/docs/book/nodes.txt, which is also incomplete. – dbn Apr 28 '17 at 01:25
1

Two alternatives:

  • features="subst" with is_copy=True:

     bld(features='subst', source='wscript', target='wscript', is_copy=True)
    
  • waflib.extras.buildcopy like this:

    from waflib.extras import buildcopy
    #...
    def build(bld):
        bld(features='buildcopy',buildcopy_source=['file'])
    

cp is not platform independent.

A task_gen object is created, which later will become a Task, that will be executed before process_sources. Don't expect an immediate effect.

Roland Puntaier
  • 3,250
  • 30
  • 35
  • Unfortunately, the `buildcopy` module isn't distributed with waf anymore so you have to copy the `buildcopy.py` file into your project. Then just import using `import buildcopy` – Björn Lindqvist Jan 19 '18 at 16:37
0

Have a look into your out dir, there will be out/${TGT} (not exactly, but ${TGT} path relative to your top directory)


This is totally to be expected behaviour, since you do not want to modify your source tree when building.

drahnr
  • 6,782
  • 5
  • 48
  • 75