1

I'm new to waf build tool and I've googled for answers but very few unhelpful links.

Does anyone know?

As wscript is essentially a python script, I suppose I could use the os package?

jinglei
  • 3,269
  • 11
  • 27
  • 46
  • 1
    You can use `import os` everywhere you could do it in any other python script. `wscript`s are (more or less) platform agnostic - depending on what code you put into it. I personally use `platform` and not `os` for that case. If I have things that behave different on Windows and Linux/Unix, I use something like that `if platform.system().lower().startswith('win'): a = 'x' else: a = 'y'`. Does this answer your question? Then I will put a complete example as answer. – user69453 Dec 27 '17 at 12:56
  • @user69453: I suggest you make your comment an answer. You could edit if the question changes. – neuro Jan 09 '18 at 08:07

2 Answers2

2

Don't use the os module, instead use the DEST_* variables:

ctx.load('compiler_c')
print (ctx.env.DEST_OS, ctx.env.DEST_CPU, ctx.env.DEST_BINFMT)

On my machine this would print ('linux', 'x86_64', 'elf'). Then you can dispatch on that.

user69453
  • 1,279
  • 1
  • 17
  • 43
Björn Lindqvist
  • 19,221
  • 20
  • 87
  • 122
0

You can use import at every point where you could use it any other python script.

I prefer using platform for programming a function os-agnostic instead on evaluate some attributes of os.

Writing the Build-related commands example in the waf book os-agnostic, could look something like this:

import platform

top = '.'
out = 'build_directory'

def configure(ctx):
    pass

def build(ctx):
    if platform.system().lower().startswith('win'):
        cp = 'copy'
    else:
        cp = 'cp'
    ctx(rule=cp+' ${SRC} ${TGT}', source='foo.txt', target='bar.txt')
user69453
  • 1,279
  • 1
  • 17
  • 43