1

waf has the subst feature to copy files. In build context it can be used like that:

def build(bld):
    bld(features='subst', source='wscript', target='wscript_copy', is_copy=True)

But I need to make use of the subst feature in the configure step:

def configure(conf):
    conf(features='subst', source='wscript', target='wscript_copy', is_copy=True)

But this is not possible, as configure has no BuildContext:

TypeError: 'ConfigurationContext' object is not callable

Is there a way to make this work?

1 Answers1

1

ConfigureContext is not meant to use tasks.

If you really need it, you can do the same the conf.check() method do (see waf book §10.4.2). It uses waflib.Configure.run_build(self, *k, **kw), which is not exactly public. See waflib.Tools.c_config for its use by check().

It seems unneeded complexity to me. If you only need to copy files to setup your workspace, use plain python.

from shutil import copyfile

def configure(conf):
    copyfile('wscript', 'wscript_copy')

The build part use tasks management and tasks dependencies to build things if needed.

If you need substitution of env variables, you can code it in a waf tool to use like:

def configure(conf):
    conf.load("mysubst")
    conf.substitute(wscript', 'wscript_copy')
neuro
  • 14,948
  • 3
  • 36
  • 59
  • Because a workspace is configured in that step and this needs file copying. And this is done one time during configure. This must not be done during build. It must be possible in some way, as in configure test builds are also done when configuring a compiler and this needs a build context. –  May 08 '20 at 08:31
  • What I mean is that your workspace configuration should be done in build. In configure, the tests are done by functions that instantiate manually specific build context. This is like starting specific waf build commands. If you go that way then have a look at config commands. I will try to give you an example if I have time. Nevertheless, it is usually better to make those step in build. – neuro May 11 '20 at 15:17
  • Thanks for your time and answers so far. Could you elaborate why the workspace should be configured in build instead of configure? The workspace (a bunch of files in a toplevel directory) is created once and does not changed when building. It is depended on the platform and version dependent tools (compiler, linker, include directories, python and python version) that are found and configured during the configure step. After all tools are found (or not) the workspace is configured accordingly. Why should this not be part of configure? –  May 12 '20 at 10:19
  • 1
    Well, subst use the task management of waf and thus is meant to be used in the build. subst will substitute only if its sources are modified for example. In the configure step, there no such thing as task management. If you need file copying in configure, done one time, you don't need task management. Just use python copy, KISS :) – neuro May 15 '20 at 09:27
  • I would say yes, keeping it simple is good, but I wanted to make use of `@VAR@` feature of waf. But I think I will use just fily coping and manually edit the files content. –  May 15 '20 at 09:43
  • 1
    You can have a look at subst and make your own substitute. I've just done that :) A simple read, replace will generally do. You can package it in a method to use with your configure context – neuro May 15 '20 at 09:59