Skip to content

Commit

Permalink
Add waf buildscript, a reference waf build, that can be copied to any…
Browse files Browse the repository at this point in the history
… FWGS project, make env names for subproject more complex to avoid collision, add subproject test
  • Loading branch information
a1batross committed Jun 1, 2019
1 parent c331a35 commit 9ba31f9
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/*
.waf*
.lock*
*.pyc
10 changes: 10 additions & 0 deletions build-waf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

TOOLS="msvc,clang_compilation_database"
PRELUDE=$'\tsys.path.insert(0, \'scripts/waifulib\')'

pushd wafsrc
./waf-light "--tools=$TOOLS" "--prelude=$PRELUDE"
mv waf ../
popd

49 changes: 27 additions & 22 deletions scripts/waifulib/subproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
Helps you have standalone environment for each subproject(subdirectory)
Usage::
Usage:
def options(opt):
opt.load('subproject')
def configure(conf):
conf.add_subproject('folder1 folder2')
def build(bld):
bld.add_subproject('folder1 folder2')
'''
Expand All @@ -22,19 +25,20 @@ def build(bld):

def depth_push(path):
global DEPTH

DEPTH = os.path.join(DEPTH, path)
# print DEPTH

def depth_pop():
global DEPTH

DEPTH = os.path.dirname(DEPTH)
# print DEPTH

def depth():
def get_name_by_depth():
global DEPTH
return DEPTH

return DEPTH.replace(os.sep, '_')

def opt(f):
"""
Expand All @@ -49,12 +53,12 @@ def opt(f):
@opt
def add_subproject(ctx, names):
names_lst = Utils.to_list(names)

for name in names_lst:
depth_push(name)
wscript_path = os.path.join(depth(), 'wscript')

wscript_path = os.path.join(DEPTH, 'wscript')

if not os.path.isfile(wscript_path):
# HACKHACK: this way we get warning message right in the help
# so this just becomes more noticeable
Expand All @@ -66,8 +70,8 @@ def add_subproject(ctx, names):

def options(opt):
grp = opt.add_option_group('Subproject options')
grp.add_option('-S', '--skip-subprojects', action='store', dest = 'SKIP_SUBDIRS', default=None,

grp.add_option('-S', '--skip-subprojects', action='store', dest = 'SKIP_SUBDIRS', default=None,
help = 'don\'t recurse into specified subprojects. Use only directory name.')

def get_subproject_env(ctx, path, log=False):
Expand All @@ -90,38 +94,39 @@ def get_subproject_env(ctx, path, log=False):
if log: Logs.pprint('YELLOW', 'env: changed to default env')
raise IndexError('top env')


def configure(conf):
if conf.options.SKIP_SUBDIRS:
conf.env.IGNORED_SUBDIRS = conf.options.SKIP_SUBDIRS.split(',')

@Configure.conf
def add_subproject(ctx, names):
names_lst = Utils.to_list(names)

if isinstance(ctx, Configure.ConfigurationContext):
if not ctx.env.IGNORED_SUBDIRS and ctx.options.SKIP_SUBDIRS:
ctx.env.IGNORED_SUBDIRS = ctx.options.SKIP_SUBDIRS.split(',')

for name in names_lst:
depth_push(name)
if name in ctx.env.IGNORED_SUBDIRS:
ctx.msg(msg='--X %s' % depth(), result='ignored', color='YELLOW')
ctx.msg(msg='--X %s' % DEPTH, result='ignored', color='YELLOW')
depth_pop()
continue
saveenv = ctx.env
ctx.setenv(name, ctx.env) # derive new env from previous
ctx.setenv(get_name_by_depth(), ctx.env) # derive new env from previous
ctx.env.ENVNAME = name
ctx.msg(msg='--> %s' % depth(), result='in progress', color='BLUE')
ctx.msg(msg='--> %s' % DEPTH, result='in progress', color='BLUE')
ctx.recurse(name)
ctx.msg(msg='<-- %s' % depth(), result='done', color='BLUE')
ctx.msg(msg='<-- %s' % DEPTH, result='done', color='BLUE')
ctx.setenv('') # save env changes
ctx.env = saveenv # but use previous
depth_pop()
else:
if not ctx.all_envs:
ctx.load_envs()
for name in names_lst:
depth_push(name)
if name in ctx.env.IGNORED_SUBDIRS:
depth_pop()
continue
saveenv = ctx.env
ctx.env = ctx.all_envs[name]
ctx.env = ctx.all_envs[get_name_by_depth()]
ctx.recurse(name)
ctx.env = saveenv
depth_pop()
22 changes: 22 additions & 0 deletions tests/subdirs/foo/wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/env python
# encoding: utf-8
# a1batross, 2019

def options(opt):
opt.add_option('--foo_test', action='store_true', default=True, dest='foo_test')

def configure(conf):
conf.env.SUBDIRS_FOO = 'foo'

# check options() was called
if not conf.options.foo_test:
raise Exception('TEST FAILED')

# check if we really derived environment
if conf.env.SUBDIRS_ROOT != 'meow':
raise Exception('TEST FAILED')

def build(bld):
# check if environment was derived correctly
if bld.env.SUBDIRS_ROOT != 'meow':
raise Exception('TEST FAILED')
21 changes: 21 additions & 0 deletions tests/subdirs/wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /usr/bin/env python
# encoding: utf-8
# a1batross, 2019

def options(opt):
opt.add_subproject('foo')

def configure(conf):
conf.env.SUBDIRS_ROOT = 'meow'
conf.add_subproject('foo')

# check that we're still using our enviroment
if 'SUBDIRS_FOO' in conf.env:
raise Exception('TEST FAILED')

def build(bld):
bld.add_subproject('foo')

# check that 'foo' env isn't derived
if 'SUBDIRS_FOO' in bld.env:
raise Exception('TEST FAILED')
15 changes: 15 additions & 0 deletions tests/wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/env python
# encoding: utf-8
# a1batross, 2019

def options(opt):
opt.add_subproject('subdirs')
pass

def configure(conf):
conf.add_subproject('subdirs')
pass

def build(bld):
bld.add_subproject('subdirs')
pass
169 changes: 169 additions & 0 deletions waf

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#! /usr/bin/env python
# encoding: utf-8
# a1batross, mittorn, 2018

from __future__ import print_function

VERSION = '1.0'
APPNAME = 'waifu-tests'
top = '.'

def subdirs():
return map(lambda x: x.name, SUBDIRS)

def options(opt):
opt.load('subproject')
opt.add_subproject('tests')
pass

def configure(conf):
conf.add_subproject('tests')
pass

def build(bld):
bld.add_subproject('tests')
pass

0 comments on commit 9ba31f9

Please sign in to comment.