Skip to content

Commit

Permalink
Move configure option -A functionality to -D.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpakkane committed Sep 13, 2024
1 parent 4fe63cd commit 9912a0d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
10 changes: 1 addition & 9 deletions mesonbuild/mconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')

Expand Down Expand Up @@ -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:
Expand All @@ -386,18 +382,14 @@ 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:
U = []
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()
Expand Down
39 changes: 27 additions & 12 deletions mesonbuild/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions unittests/linuxliketests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
12 changes: 6 additions & 6 deletions unittests/optiontests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 9912a0d

Please sign in to comment.