waifulib: subproject: experimental changes to how subenvs are handled

This commit is contained in:
Alibek Omarov 2019-10-08 02:33:01 +03:00
parent 71fb72519a
commit 9cfc5cc296

View File

@ -21,25 +21,6 @@ Usage:
from waflib import Configure, Logs, Options, Utils from waflib import Configure, Logs, Options, Utils
import os import os
DEPTH = ''
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 get_name_by_depth():
global DEPTH
return DEPTH.replace(os.sep, '_')
def opt(f): def opt(f):
""" """
Decorator: attach new option functions to :py:class:`waflib.Options.OptionsContext`. Decorator: attach new option functions to :py:class:`waflib.Options.OptionsContext`.
@ -55,19 +36,18 @@ def add_subproject(ctx, names):
names_lst = Utils.to_list(names) names_lst = Utils.to_list(names)
for name in names_lst: for name in names_lst:
depth_push(name) if not os.path.isabs(name):
# absolute paths only
wscript_path = os.path.join(DEPTH, 'wscript') wscript_path = os.path.join(ctx.path.abspath(), name, 'wscript')
else: wscript_path = os.path.join(name, 'wscript')
if not os.path.isfile(wscript_path): if not os.path.isfile(wscript_path):
# HACKHACK: this way we get warning message right in the help # HACKHACK: this way we get warning message right in the help
# so this just becomes more noticeable # so this just becomes more noticeable
ctx.add_option_group('Cannot find wscript in ' + name + '. You probably missed submodule update') ctx.add_option_group('Cannot find wscript in ' + wscript_path + '. You probably missed submodule update')
else: else:
ctx.recurse(name) ctx.recurse(name)
depth_pop()
def options(opt): def options(opt):
grp = opt.add_option_group('Subproject options') grp = opt.add_option_group('Subproject options')
@ -95,38 +75,71 @@ def get_subproject_env(ctx, path, log=False):
raise IndexError('top env') raise IndexError('top env')
@Configure.conf @Configure.conf
def add_subproject(ctx, names): def add_subproject(ctx, dirs, prepend = None):
names_lst = Utils.to_list(names) '''
Recurse into subproject directory
:param dirs: Directories we recurse into
:type dirs: array or string
:param prepend: Prepend virtual path, useful when managing projects with different environments
:type prepend: string
'''
if isinstance(ctx, Configure.ConfigurationContext): if isinstance(ctx, Configure.ConfigurationContext):
if not ctx.env.IGNORED_SUBDIRS and ctx.options.SKIP_SUBDIRS: if not ctx.env.IGNORED_SUBDIRS and ctx.options.SKIP_SUBDIRS:
ctx.env.IGNORED_SUBDIRS = ctx.options.SKIP_SUBDIRS.split(',') ctx.env.IGNORED_SUBDIRS = ctx.options.SKIP_SUBDIRS.split(',')
for name in names_lst: for prj in Utils.to_list(dirs):
depth_push(name) if ctx.env.SUBPROJECT_PATH:
if name in ctx.env.IGNORED_SUBDIRS: subprj_path = list(ctx.env.SUBPROJECT_PATH)
ctx.msg(msg='--X %s' % DEPTH, result='ignored', color='YELLOW') else:
depth_pop() subprj_path = ['']
if prj in ctx.env.IGNORED_SUBDIRS:
ctx.msg(msg='--X %s' % '/'.join(subprj_path), result='ignored', color='YELLOW')
continue continue
if prepend:
subprj_path.append(prepend)
subprj_path.append(prj)
saveenv = ctx.env saveenv = ctx.env
ctx.setenv(get_name_by_depth(), ctx.env) # derive new env from previous
ctx.env.ENVNAME = name ctx.setenv('_'.join(subprj_path), ctx.env) # derive new env from previous
ctx.msg(msg='--> %s' % DEPTH, result='in progress', color='BLUE')
ctx.recurse(name) ctx.env.ENVNAME = prj
ctx.msg(msg='<-- %s' % DEPTH, result='done', color='BLUE') ctx.env.SUBPROJECT_PATH = list(subprj_path)
ctx.msg(msg='--> %s' % '/'.join(subprj_path), result='in progress', color='BLUE')
ctx.recurse(prj)
ctx.msg(msg='<-- %s' % '/'.join(subprj_path), result='done', color='BLUE')
ctx.setenv('') # save env changes ctx.setenv('') # save env changes
ctx.env = saveenv # but use previous ctx.env = saveenv # but use previous
depth_pop()
else: else:
if not ctx.all_envs: if not ctx.all_envs:
ctx.load_envs() ctx.load_envs()
for name in names_lst:
depth_push(name) for prj in Utils.to_list(dirs):
if name in ctx.env.IGNORED_SUBDIRS: if prj in ctx.env.IGNORED_SUBDIRS:
depth_pop()
continue continue
if ctx.env.SUBPROJECT_PATH:
subprj_path = list(ctx.env.SUBPROJECT_PATH)
else:
subprj_path = ['']
if prepend:
subprj_path.append(prepend)
subprj_path.append(prj)
saveenv = ctx.env saveenv = ctx.env
ctx.env = ctx.all_envs[get_name_by_depth()] try:
ctx.recurse(name) ctx.env = ctx.all_envs['_'.join(subprj_path)]
except:
ctx.fatal('Can\'t find env cache %s' % '_'.join(subprj_path))
ctx.recurse(prj)
ctx.env = saveenv ctx.env = saveenv
depth_pop()