1

I have a wscript which reads some files during the configure step and based on this sets some variabales. How do I get waf to automatically re-configure the project, if one of the configuration files change, when running waf build instead of waf configure build?

Consider the following scenario:

  1. waf configure
  2. waf build
  3. The content in configuration file a.config is changed
  4. the user just runs waf build, instead of waf configure build.

--> How must the wscript look like, that it checks before running build if the configuration files have changed, and if so, the project is reconfigured before running build?

Example:

There is a file a.config and the wscript looks like this:

# wscript
def configure(conf):
    a = conf.path.find_node('a.config')
    conf.env.config = a.read()

def build(bld):
    # check the configuration files are up to date.
    # actual build
    pass
neuro
  • 14,948
  • 3
  • 36
  • 59

1 Answers1

0

configure is not really for that. You can use the same code but in build:

def build(bld):

    a = bld.path.find_node('a.config')
    bld.env.config = a.read()

    bld(features = "myfeature", vars = ["config"], ...)

You can directly use configure with autoconfig:

from waflib import Configure

def options(opt):
    Configure.autoconfig = True

def configure(conf):
    conf.env.config = "my_value"

def my_processing(task):
    print "Processing..."

def build(bld):
    bld(rule = my_processing, vars = ["config"])

Any change to conf.env.config will trigger rebuild.

If you need to have separate config files, you can use load:

def configure(conf):
    pass

def my_processing(task):
    print "Processing..."

def build(bld):
    bld.load("my_config", tooldir="my_config_dir")
    bld(rule = my_processing, vars = ["config1", "config2"])

with a my_config_dir/my_config.py file like that:

def build(bld):

    bld.env.config1 = "one"
    bld.env.config2 = "two"
    # ...

bld.load() will execute the build function in my_config.

Any change to config1 or config2 will trigger rebuild

neuro
  • 14,948
  • 3
  • 36
  • 59
  • Changing the content of a does not lead to a rebuild if I use e.g., the c or cprogram feature. Did it work for you? –  Apr 16 '20 at 13:38
  • @softwareissoftware: My mistake. `vars` must be a list. Works for me. – neuro Apr 20 '20 at 15:26
  • Ok, that interesting. It works for your example (`rule=...`). But this does not work if you use a feature. Do you have an idea what could be the problem? –  Apr 21 '20 at 07:45
  • Some features may change vars to fit their needs. For instance, the C task define `vars = ['CCDEPS']`. You can use CCDEPS directly or add a taskgen method to modify vars. – neuro Apr 21 '20 at 10:15
  • @softwareissoftware: In any case, I think you should use directly your configuration file as a dependency in your build. Configure is meant for tools and platform dependant configuration. – neuro Apr 21 '20 at 10:19