summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-04-02 11:15:26 -0700
committerDylan Baker <dylan@pnwbakers.com>2025-04-08 10:00:16 -0700
commit4c1d1da9b6a1e3f144d26dbc73f9d02f4f7f7e97 (patch)
tree6627ed741721d1961427237bb5e7b1e6d012034e
parent90d6a3e61100e39ab74ff7b2b4bc456af5a8114c (diff)
downloadmeson-4c1d1da9b6a1e3f144d26dbc73f9d02f4f7f7e97.tar.gz
options: fix typing issues stemming from initialize_from_top_level_project_call
Machine files provide a `Mapping[OptionKey, ElementaryOptionValues]`, but the expectation listed was that they provided options in the raw DSL format.
-rw-r--r--mesonbuild/options.py20
-rw-r--r--unittests/optiontests.py2
2 files changed, 15 insertions, 7 deletions
diff --git a/mesonbuild/options.py b/mesonbuild/options.py
index 4339f7773..8a7b7ec3b 100644
--- a/mesonbuild/options.py
+++ b/mesonbuild/options.py
@@ -6,6 +6,7 @@ from __future__ import annotations
from collections import OrderedDict
from itertools import chain
import argparse
+import copy
import dataclasses
import itertools
import os
@@ -1236,21 +1237,28 @@ class OptionStore:
def first_handle_prefix(self,
project_default_options: T.Union[T.List[str], OptionStringLikeDict],
cmd_line_options: T.Union[T.List[str], OptionStringLikeDict],
- machine_file_options: T.Union[T.List[str], OptionStringLikeDict]) \
+ machine_file_options: T.Mapping[OptionKey, ElementaryOptionValues]) \
-> T.Tuple[T.Union[T.List[str], OptionStringLikeDict],
T.Union[T.List[str], OptionStringLikeDict],
- T.Union[T.List[str], OptionStringLikeDict]]:
+ T.MutableMapping[OptionKey, ElementaryOptionValues]]:
+ # Copy to avoid later mutation
+ nopref_machine_file_options = T.cast(
+ 'T.MutableMapping[OptionKey, ElementaryOptionValues]', copy.copy(machine_file_options))
+
prefix = None
(possible_prefix, nopref_project_default_options) = self.prefix_split_options(project_default_options)
prefix = prefix if possible_prefix is None else possible_prefix
- (possible_prefix, nopref_native_file_options) = self.prefix_split_options(machine_file_options)
- prefix = prefix if possible_prefix is None else possible_prefix
+
+ possible_prefixv = nopref_machine_file_options.pop(OptionKey('prefix'), None)
+ assert possible_prefixv is None or isinstance(possible_prefixv, str), 'mypy: prefix from machine file was not a string?'
+ prefix = prefix if possible_prefixv is None else possible_prefixv
+
(possible_prefix, nopref_cmd_line_options) = self.prefix_split_options(cmd_line_options)
prefix = prefix if possible_prefix is None else possible_prefix
if prefix is not None:
self.hard_reset_from_prefix(prefix)
- return (nopref_project_default_options, nopref_cmd_line_options, nopref_native_file_options)
+ return (nopref_project_default_options, nopref_cmd_line_options, nopref_machine_file_options)
def hard_reset_from_prefix(self, prefix: str) -> None:
prefix = self.sanitize_prefix(prefix)
@@ -1268,7 +1276,7 @@ class OptionStore:
def initialize_from_top_level_project_call(self,
project_default_options_in: T.Union[T.List[str], OptionStringLikeDict],
cmd_line_options_in: T.Union[T.List[str], OptionStringLikeDict],
- machine_file_options_in: T.Union[T.List[str], OptionStringLikeDict]) -> None:
+ machine_file_options_in: T.Mapping[OptionKey, ElementaryOptionValues]) -> None:
first_invocation = True
(project_default_options, cmd_line_options, machine_file_options) = self.first_handle_prefix(project_default_options_in,
cmd_line_options_in,
diff --git a/unittests/optiontests.py b/unittests/optiontests.py
index d02119a06..3b3ffc98e 100644
--- a/unittests/optiontests.py
+++ b/unittests/optiontests.py
@@ -32,7 +32,7 @@ class OptionTests(unittest.TestCase):
vo = UserStringOption(k.name, 'An option of some sort', default_value)
optstore.add_system_option(k.name, vo)
self.assertEqual(optstore.get_value_for(k), default_value)
- optstore.initialize_from_top_level_project_call([f'someoption={new_value}'], {}, {})
+ optstore.initialize_from_top_level_project_call({OptionKey('someoption'): new_value}, {}, {})
self.assertEqual(optstore.get_value_for(k), new_value)
def test_parsing(self):