From 9912a0d8b8bd102285b7a4c1f1f90294dba42606 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Thu, 5 Sep 2024 16:56:50 +0300 Subject: [PATCH] Move configure option -A functionality to -D. --- mesonbuild/mconf.py | 10 +--------- mesonbuild/options.py | 39 +++++++++++++++++++++++++------------ unittests/linuxliketests.py | 4 ++-- unittests/optiontests.py | 12 ++++++------ 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py index 47e528ce0844..065d14195e33 100644 --- a/mesonbuild/mconf.py +++ b/mesonbuild/mconf.py @@ -48,8 +48,6 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None: help='Clear cached state (e.g. found dependencies)') parser.add_argument('--no-pager', action='store_false', dest='pager', help='Do not redirect output to a pager') - parser.add_argument('-A', action='append', dest='A', - help='Add a subproject option.') parser.add_argument('-U', action='append', dest='U', help='Remove a subproject option.') @@ -358,8 +356,6 @@ def print_augments(self) -> None: def has_option_flags(options: T.Any) -> bool: if options.cmd_line_options: return True - if options.A: - return True if hasattr(options, 'D') and options.D: return True if options.U: @@ -386,10 +382,6 @@ def run_impl(options: CMDOptions, builddir: str) -> int: save = False if has_option_flags(options): - if hasattr(options, 'A'): - A = options.A - else: - A = [] if hasattr(options, 'U'): U = options.U else: @@ -397,7 +389,7 @@ def run_impl(options: CMDOptions, builddir: str) -> int: all_D = options.projectoptions[:] for keystr, valstr in options.cmd_line_options.items(): all_D.append(f'{keystr}={valstr}') - save |= c.coredata.optstore.set_from_configure_command(all_D, A, U) + save |= c.coredata.optstore.set_from_configure_command(all_D, U) coredata.update_cmd_line_file(builddir, options) if options.clearcache: c.clear_cache() diff --git a/mesonbuild/options.py b/mesonbuild/options.py index fd28aabf8a18..bfd4ed8bbf7b 100644 --- a/mesonbuild/options.py +++ b/mesonbuild/options.py @@ -1104,26 +1104,41 @@ def set_subproject_options(self, subproject, spcall_default_options, project_def if keystr not in self.augments: self.augments[keystr] = valstr - def set_from_configure_command(self, D: T.List[str], A: T.List[str], U: T.List[str]) -> bool: + def classify_D_arguments(self, D: T.List[str]): + global_options = [] + project_options = [] + perproject_global_options = [] + for setval in D: + keystr, valstr = setval.split('=', 1) + key = OptionKey.from_string(keystr) + valuetuple = (key, valstr) + if self.is_project_option(key): + project_options.append(valuetuple) + elif key.subproject is None: + global_options.append(valuetuple) + else: + # FIXME, augments are currently stored as strings, not OptionKeys + valuetuple = (keystr, valstr) + perproject_global_options.append(valuetuple) + return (global_options, perproject_global_options, project_options) + + def set_from_configure_command(self, D: T.List[str], U: T.List[str]) -> bool: dirty = False D = [] if D is None else D - A = [] if A is None else A + (global_options, perproject_global_options, project_options) = self.classify_D_arguments(D) U = [] if U is None else U - for setval in D: - keystr, valstr = setval.split('=', 1) + for key, valstr in global_options: + dirty |= self.set_option_from_string(key, valstr) + for key, valstr in project_options: + dirty |= self.set_option_from_string(key, valstr) + for keystr, valstr in perproject_global_options: if keystr in self.augments: if self.augments[keystr] != valstr: self.augments[keystr] = valstr dirty = True else: - dirty |= self.set_option_from_string(keystr, valstr) - for add in A: - keystr, valstr = add.split('=', 1) - assert ':' in keystr - if keystr in self.augments: - raise MesonException(f'Tried to add augment to option {keystr}, which already has an augment. Set it with -D instead.') - self.augments[keystr] = valstr - dirty = True + self.augments[keystr] = valstr + dirty = True for delete in U: if delete in self.augments: del self.augments[delete] diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py index 86088cee7cca..e360dda87bc8 100644 --- a/unittests/linuxliketests.py +++ b/unittests/linuxliketests.py @@ -1833,7 +1833,7 @@ def test_persp_options(self): self.check_has_flag(compdb, sub2src, '-O1') # Set subproject option to O2 - self.setconf(['-Dround=2', '-A', 'sub2:optimization=3']) + self.setconf(['-Dround=2', '-D', 'sub2:optimization=3']) compdb = self.get_compdb() self.check_has_flag(compdb, mainsrc, '-O1') self.check_has_flag(compdb, sub1src, '-O1') @@ -1847,7 +1847,7 @@ def test_persp_options(self): self.check_has_flag(compdb, sub2src, '-O2') # Set top level option to O3 - self.setconf(['-Dround=4', '-A:optimization=3']) + self.setconf(['-Dround=4', '-D:optimization=3']) compdb = self.get_compdb() self.check_has_flag(compdb, mainsrc, '-O3') self.check_has_flag(compdb, sub1src, '-O1') diff --git a/unittests/optiontests.py b/unittests/optiontests.py index a688a96b777c..7dad6f279c25 100644 --- a/unittests/optiontests.py +++ b/unittests/optiontests.py @@ -119,24 +119,24 @@ def test_augments(self): self.assertEqual(optstore.get_value_for(name, sub2_name), top_value) # First augment a subproject - optstore.set_from_configure_command([], [f'{sub_name}:{name}={aug_value}'], []) + optstore.set_from_configure_command([f'{sub_name}:{name}={aug_value}'], []) self.assertEqual(optstore.get_value_for(name), top_value) self.assertEqual(optstore.get_value_for(name, sub_name), aug_value) self.assertEqual(optstore.get_value_for(name, sub2_name), top_value) - optstore.set_from_configure_command([], [], [f'{sub_name}:{name}']) + optstore.set_from_configure_command([], [f'{sub_name}:{name}']) self.assertEqual(optstore.get_value_for(name), top_value) self.assertEqual(optstore.get_value_for(name, sub_name), top_value) self.assertEqual(optstore.get_value_for(name, sub2_name), top_value) # And now augment the top level option - optstore.set_from_configure_command([], [f':{name}={aug_value}'], []) + optstore.set_from_configure_command([f':{name}={aug_value}'], []) self.assertEqual(optstore.get_value_for(name, None), top_value) self.assertEqual(optstore.get_value_for(name, ''), aug_value) self.assertEqual(optstore.get_value_for(name, sub_name), top_value) self.assertEqual(optstore.get_value_for(name, sub2_name), top_value) - optstore.set_from_configure_command([], [], [f':{name}']) + optstore.set_from_configure_command([], [f':{name}']) self.assertEqual(optstore.get_value_for(name), top_value) self.assertEqual(optstore.get_value_for(name, sub_name), top_value) self.assertEqual(optstore.get_value_for(name, sub2_name), top_value) @@ -155,8 +155,8 @@ def test_augment_set_sub(self): ['c++98', 'c++11', 'c++14', 'c++17', 'c++20', 'c++23'], top_value) optstore.add_system_option(name, co) - optstore.set_from_configure_command([], [f'{sub_name}:{name}={aug_value}'], []) - optstore.set_from_configure_command([f'{sub_name}:{name}={set_value}'], [], []) + optstore.set_from_configure_command([f'{sub_name}:{name}={aug_value}'], []) + optstore.set_from_configure_command([f'{sub_name}:{name}={set_value}'], []) self.assertEqual(optstore.get_value_for(name), top_value) self.assertEqual(optstore.get_value_for(name, sub_name), set_value)