Ani
Ani

Reputation: 1526

waf copy a file from source tree to the build tree

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

Upvotes: 5

Views: 1435

Answers (3)

Roland Puntaier
Roland Puntaier

Reputation: 3501

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.

Upvotes: 1

dbn
dbn

Reputation: 13910

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.

Upvotes: 1

drahnr
drahnr

Reputation: 6886

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.

Upvotes: 0

Related Questions