github.com/hwaf/hwaf@v0.0.0-20140814122253-5465f73b20f1/py-hwaftools/orch/configure.py (about) 1 #!/usr/bin/env python 2 ''' 3 Configure waf for worch. 4 5 It is expected that any external tools that add worch features have already been loaded. 6 ''' 7 import os 8 from glob import glob 9 10 import waflib.Logs as msg 11 from waflib import Context 12 13 from . import util 14 from . import pkgconf 15 from . import envmunge 16 17 def locate_config_files(pat): 18 if os.path.exists(pat): 19 return [pat] 20 if pat.startswith('/'): 21 return glob(pat) 22 23 for cdir in os.environ.get('WORCH_CONFIG_PATH','').split(':') + [Context.waf_dir]: 24 maybe = os.path.join(cdir,pat) 25 got = glob(maybe) 26 if got: return got 27 28 return None 29 30 31 def get_orch_config_files(cfg): 32 if not cfg.options.orch_config: 33 raise RuntimeError('No Orchestration configuration file given (--orch-config)') 34 orch_config = [] 35 okay = True 36 for pat in util.string2list(cfg.options.orch_config): 37 got = locate_config_files(pat) 38 if got: 39 orch_config += got 40 continue 41 msg.error('File not found: "%s"' % pat) 42 okay = False 43 if not okay: 44 raise ValueError('no configuration files') 45 return orch_config 46 47 def configure(cfg): 48 msg.debug('orch: CONFIG CALLED') 49 50 from . import features 51 features.load() 52 53 orch_config = get_orch_config_files(cfg) 54 cfg.msg('Orch configuration files', '"%s"' % '", "'.join(orch_config)) 55 56 extra = dict(cfg.env) 57 extra['top'] = cfg.path.abspath() 58 out = cfg.bldnode.abspath() # usually {top}/tmp 59 assert out, 'No out dir defined' 60 extra['out'] = out 61 extra['DESTDIR'] = getattr(cfg.options, 'destdir', '') 62 msg.debug('top="{top}" out="{out}" DESTDIR="{DESTDIR}"'.format(**extra)) 63 64 suite = pkgconf.load(orch_config, start = cfg.options.orch_start, **extra) 65 66 # load in any external tools in this configuration context that 67 # may be referenced in the configuration 68 for group in suite['groups']: 69 for package in group['packages']: 70 tools = package.get('tools') 71 if not tools: continue 72 for tool in util.string2list(tools): 73 msg.debug('orch: loading tool: "%s" for package "%s"' % (tool, package['package'])) 74 cfg.load(tool) 75 76 suite = pkgconf.fold_in(suite, **extra) 77 #pkgconf.dump_suite(suite) 78 79 80 # decompose the hierarchy of dicts into waf data 81 envmunge.decompose(cfg, suite) 82 83 cfg.msg('Orch configure envs', '"%s"' % '", "'.join(cfg.all_envs.keys())) 84 msg.debug('orch: CONFIG CALLED [done]') 85 return 86