From ff1146bc8c3b489fafce5746ce9d3c5f1d80fd96 Mon Sep 17 00:00:00 2001 From: Hemmo Nieminen Date: Mon, 12 Feb 2018 20:57:23 +0200 Subject: [PATCH] Fix subproject prefix handling when checking subproject option validity. --- mesonbuild/optinterpreter.py | 33 ++++++++++++++----- .../subprojects/one/meson.build | 2 +- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py index d4ea06a75..16eaf7897 100644 --- a/mesonbuild/optinterpreter.py +++ b/mesonbuild/optinterpreter.py @@ -154,6 +154,30 @@ class OptionInterpreter: continue self.cmd_line_options[key] = value + def get_bad_options(self): + subproj_len = len(self.subproject) + if subproj_len > 0: + subproj_len += 1 + retval = [] + # The options need to be sorted (e.g. here) to get consistent + # error messages (on all platforms) which is required by some test + # cases that check (also) the order of these options. + for option in sorted(self.cmd_line_options): + if option in list(self.options) + forbidden_option_names: + continue + if any(option[subproj_len:].startswith(p) for p in forbidden_prefixes): + continue + retval += [option] + return retval + + def check_for_bad_options(self): + bad = self.get_bad_options() + if bad: + sub = 'In subproject {}: '.format(self.subproject) if self.subproject else '' + mlog.warning( + '{}Unknown command line options: "{}"\n' + 'This will become a hard error in a future Meson release.'.format(sub, ', '.join(bad))) + def process(self, option_file): try: with open(option_file, 'r', encoding='utf8') as f: @@ -173,14 +197,7 @@ class OptionInterpreter: e.colno = cur.colno e.file = os.path.join('meson_options.txt') raise e - bad = [o for o in sorted(self.cmd_line_options) if not - (o in list(self.options) + forbidden_option_names or - any(o.startswith(p) for p in forbidden_prefixes))] - if bad: - sub = 'In subproject {}: '.format(self.subproject) if self.subproject else '' - mlog.warning( - '{}Unknown command line options: "{}"\n' - 'This will become a hard error in a future Meson release.'.format(sub, ', '.join(bad))) + self.check_for_bad_options() def reduce_single(self, arg): if isinstance(arg, str): diff --git a/test cases/unit/19 bad command line options/subprojects/one/meson.build b/test cases/unit/19 bad command line options/subprojects/one/meson.build index 39ae07ed8..85ef74210 100644 --- a/test cases/unit/19 bad command line options/subprojects/one/meson.build +++ b/test cases/unit/19 bad command line options/subprojects/one/meson.build @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -project('one subproject') +project('one subproject', default_options : [ 'b_colorout=never' ])