Jeff
Jeff

Reputation: 5956

waf 1.7: How do you copy an environment?

I have a waf file that is building several libraries for multiple targets, multiple platforms and, in some cases, multiple architectures.

I currently have the environment set up according to waf 1.7's documents for variants like so:

def configure(conf):
   # set up one platform, multiple variants, multiple archs
   for arch in ['x86', 'x86_64']:
      for tgt in ['dbg', 'rel']:
         conf.setenv('platform_' + arch + '_' + tgt)
         conf.load('gcc')   # or some other compiler, such as msvc
         conf.load('gxx')
         #set platform arguments

However, this causes waf to output multiple lines searching for the compiler during configure. It also means that I'm frequently setting up close to the same environment multiple times. I'd like to do this once if possible, for example:

def configure(conf):
    # set up platform
    conf.setenv('platform')
    conf.load('gcc')
    conf.load('gxx')
    # set platform arguments
    for arch in ['x86', 'x86_64']:
        for tgt in ['dbg', 'rel']:
            conf.setenv('platform_' + arch + '_' + tgt, conf.env.derive())
            # set specific arguments as needed

However, conf.env.derive is a shallow copy, and conf.env.copy() gives me the error 'list' object is not callable

How is this done in waf 1.7?

Upvotes: 3

Views: 838

Answers (1)

Jeff
Jeff

Reputation: 5956

The answer, it turns out, is to derive from the top architecture, then detach to allow yourself to add more flags to the configuration. Example:

def configure(conf):
    conf.setenv('platform')
    conf.load('gcc')
    conf.load('gxx')
    for arch, tgt in itertools.product(['x86', 'x86_64'],  ['dbg', 'rel']):
        conf.setenv('platform')
        new_env = conf.env.derive()
        new_env.detach()
        conf.setenv('platform_' + arch + '_' + tgt, new_env)
        # Set architecture / target specifics

Upvotes: 5

Related Questions