From 5b9d79b9029f1a9be897188c6ffbdce65d4e510b Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Mon, 25 Sep 2017 23:30:40 +0300 Subject: [PATCH] Print instructions on how to promote subsubprojects. --- mesonbuild/interpreter.py | 23 +++++++++++++++++++++++ mesonbuild/mesonlib.py | 29 +++++++++++++++++++++++++++++ mesonbuild/wrap/wraptool.py | 23 +++-------------------- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index cbf141374..58bcf1dde 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2196,6 +2196,7 @@ to directly access options of other subprojects.''') # we won't actually read all the build files. return fallback_dep if not dep: + self.print_nested_info(name) assert(exception is not None) raise exception @@ -2209,6 +2210,28 @@ to directly access options of other subprojects.''') def func_disabler(self, node, args, kwargs): return Disabler() + def print_nested_info(self, dependency_name): + message_templ = '''\nDependency %s not found but it is available in a sub-subproject. +To use it in the current project, promote it by going in the project source +root and issuing %s. + +''' + sprojs = mesonlib.detect_subprojects('subprojects', self.source_root) + if dependency_name not in sprojs: + return + found = sprojs[dependency_name] + if len(found) > 1: + suffix = 'one of the following commands' + else: + suffix = 'the following command' + message = message_templ % (dependency_name, suffix) + cmds = [] + command_templ = 'meson wrap promote ' + for l in found: + cmds.append(command_templ + l[len(self.source_root)+1:]) + final_message = message + '\n'.join(cmds) + print(final_message) + def get_subproject_infos(self, kwargs): fbinfo = kwargs['fallback'] check_stringlist(fbinfo) diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 9ad066821..8da08d3e6 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -881,6 +881,35 @@ def windows_proof_rmtree(f): # Try one last time and throw if it fails. shutil.rmtree(f) +def unholder_array(entries): + result = [] + entries = flatten(entries) + for e in entries: + if hasattr(e, 'held_object'): + e = e.held_object + result.append(e) + return result + + +def detect_subprojects(spdir_name, current_dir='', result=None): + if result is None: + result = {} + spdir = os.path.join(current_dir, spdir_name) + if not os.path.exists(spdir): + return result + for trial in glob(os.path.join(spdir, '*')): + basename = os.path.split(trial)[1] + if trial == 'packagecache': + continue + if not os.path.isdir(trial): + continue + if basename in result: + result[basename].append(trial) + else: + result[basename] = [trial] + detect_subprojects(spdir_name, trial, result) + return result + class OrderedSet(collections.MutableSet): """A set that preserves the order in which items are added, by first insertion. diff --git a/mesonbuild/wrap/wraptool.py b/mesonbuild/wrap/wraptool.py index 42f0bb683..096ab4d51 100644 --- a/mesonbuild/wrap/wraptool.py +++ b/mesonbuild/wrap/wraptool.py @@ -21,6 +21,8 @@ from glob import glob from .wrap import API_ROOT, open_wrapdburl +from .. import mesonlib + help_templ = '''This program allows you to manage your Wrap dependencies using the online wrap database http://wrapdb.mesonbuild.com. @@ -149,29 +151,10 @@ def do_promotion(from_path, spdir_name): sys.exit('Output dir %s already exists. Will not overwrite.' % outputdir) shutil.copytree(from_path, outputdir, ignore=shutil.ignore_patterns('subprojects')) -def detect_subprojects(spdir_name, current_dir='', result=None): - if result is None: - result = {} - spdir = os.path.join(current_dir, spdir_name) - if not os.path.exists(spdir): - return result - for trial in glob(os.path.join(spdir, '*')): - basename = os.path.split(trial)[1] - if trial == 'packagecache': - continue - if not os.path.isdir(trial): - continue - if basename in result: - result[basename].append(trial) - else: - result[basename] = [trial] - detect_subprojects(spdir_name, trial, result) - return result - def promote(argument): path_segment, subproject_name = os.path.split(argument) spdir_name = 'subprojects' - sprojs = detect_subprojects(spdir_name) + sprojs = mesonlib.detect_subprojects(spdir_name) if subproject_name not in sprojs: sys.exit('Subproject %s not found in directory tree.' % subproject_name) matches = sprojs[subproject_name]