summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2025-10-07 15:03:49 +0200
committerJussi Pakkanen <jussi.pakkanen@mailbox.org>2025-10-29 18:59:30 +0200
commit1f0644f9c60eb8c4db7057db50f3316575d06b76 (patch)
treee88e05557ba603e465c76e8ee76870a14d6abac3
parenta4444c21f3890b4ae18d128864850062d6472ac6 (diff)
downloadmeson-1f0644f9c60eb8c4db7057db50f3316575d06b76.tar.gz
coredata: move cmd_line.txt and command line handling to a new module
cmd_line.txt is not related to serialized data, in fact it's a fallback for when serialized data cannot be used and is also related to setting up argparse for command line parsing. Since there is no code in common with the rest of coredata, move it to a new module. Fixes: #15081 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--mesonbuild/cmdline.py183
-rw-r--r--mesonbuild/coredata.py157
-rw-r--r--mesonbuild/environment.py13
-rw-r--r--mesonbuild/interpreter/mesonmain.py6
-rw-r--r--mesonbuild/machinefile.py16
-rw-r--r--mesonbuild/mconf.py11
-rw-r--r--mesonbuild/mdist.py10
-rw-r--r--mesonbuild/msetup.py20
-rw-r--r--mesonbuild/scripts/scanbuild.py3
-rw-r--r--mesonbuild/utils/universal.py2
-rw-r--r--test cases/unit/116 empty project/expected_mods.json3
11 files changed, 219 insertions, 205 deletions
diff --git a/mesonbuild/cmdline.py b/mesonbuild/cmdline.py
new file mode 100644
index 000000000..efa4a2f4c
--- /dev/null
+++ b/mesonbuild/cmdline.py
@@ -0,0 +1,183 @@
+# SPDX-License-Identifier: Apache-2.0
+# Copyright 2013-2025 The Meson development team
+
+from __future__ import annotations
+
+import argparse
+import ast
+import configparser
+import os
+import shlex
+import typing as T
+from collections import OrderedDict
+from itertools import chain
+
+from . import options
+from .mesonlib import MesonException
+from .options import OptionKey
+
+if T.TYPE_CHECKING:
+ from typing_extensions import Protocol
+
+ # typeshed
+ StrOrBytesPath = T.Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
+
+ class SharedCMDOptions(Protocol):
+ """Representation of command line options from Meson setup, configure,
+ and dist.
+
+ :param cmd_line_options: command line options parsed into an OptionKey:
+ str mapping
+ """
+
+ cmd_line_options: T.Dict[OptionKey, T.Optional[str]]
+ cross_file: T.List[str]
+ native_file: T.List[str]
+
+
+class CmdLineFileParser(configparser.ConfigParser):
+ def __init__(self) -> None:
+ # We don't want ':' as key delimiter, otherwise it would break when
+ # storing subproject options like "subproject:option=value"
+ super().__init__(delimiters=['='], interpolation=None)
+
+ def read(self, filenames: T.Union['StrOrBytesPath', T.Iterable['StrOrBytesPath']], encoding: T.Optional[str] = 'utf-8') -> T.List[str]:
+ return super().read(filenames, encoding)
+
+ def optionxform(self, optionstr: str) -> str:
+ # Don't call str.lower() on keys
+ return optionstr
+
+
+def get_cmd_line_file(build_dir: str) -> str:
+ return os.path.join(build_dir, 'meson-private', 'cmd_line.txt')
+
+def read_cmd_line_file(build_dir: str, options: SharedCMDOptions) -> None:
+ filename = get_cmd_line_file(build_dir)
+ if not os.path.isfile(filename):
+ return
+
+ config = CmdLineFileParser()
+ config.read(filename)
+
+ # Do a copy because config is not really a dict. options.cmd_line_options
+ # overrides values from the file.
+ d = {OptionKey.from_string(k): v for k, v in config['options'].items()}
+ d.update(options.cmd_line_options)
+ options.cmd_line_options = d
+
+ properties = config['properties']
+ if not options.cross_file:
+ options.cross_file = ast.literal_eval(properties.get('cross_file', '[]'))
+ if not options.native_file:
+ # This will be a string in the form: "['first', 'second', ...]", use
+ # literal_eval to get it into the list of strings.
+ options.native_file = ast.literal_eval(properties.get('native_file', '[]'))
+
+def write_cmd_line_file(build_dir: str, options: SharedCMDOptions) -> None:
+ filename = get_cmd_line_file(build_dir)
+ config = CmdLineFileParser()
+
+ properties: OrderedDict[str, str] = OrderedDict()
+ if options.cross_file:
+ properties['cross_file'] = options.cross_file
+ if options.native_file:
+ properties['native_file'] = options.native_file
+
+ config['options'] = {str(k): str(v) for k, v in options.cmd_line_options.items()}
+ config['properties'] = properties
+ with open(filename, 'w', encoding='utf-8') as f:
+ config.write(f)
+
+def update_cmd_line_file(build_dir: str, options: SharedCMDOptions) -> None:
+ filename = get_cmd_line_file(build_dir)
+ config = CmdLineFileParser()
+ config.read(filename)
+ for k, v in options.cmd_line_options.items():
+ keystr = str(k)
+ if v is not None:
+ config['options'][keystr] = str(v)
+ elif keystr in config['options']:
+ del config['options'][keystr]
+
+ with open(filename, 'w', encoding='utf-8') as f:
+ config.write(f)
+
+def format_cmd_line_options(options: SharedCMDOptions) -> str:
+ cmdline = ['-D{}={}'.format(str(k), v) for k, v in options.cmd_line_options.items()]
+ if options.cross_file:
+ cmdline += [f'--cross-file={f}' for f in options.cross_file]
+ if options.native_file:
+ cmdline += [f'--native-file={f}' for f in options.native_file]
+ return ' '.join([shlex.quote(x) for x in cmdline])
+
+
+class KeyNoneAction(argparse.Action):
+ """
+ Custom argparse Action that stores values in a dictionary as keys with value None.
+ """
+
+ def __init__(self, option_strings, dest, nargs=None, **kwargs: object) -> None:
+ assert nargs is None or nargs == 1
+ super().__init__(option_strings, dest, nargs=1, **kwargs)
+
+ def __call__(self, parser: argparse.ArgumentParser, namespace: argparse.Namespace,
+ arg: T.List[str], option_string: str = None) -> None:
+ current_dict = getattr(namespace, self.dest)
+ if current_dict is None:
+ current_dict = {}
+ setattr(namespace, self.dest, current_dict)
+
+ key = OptionKey.from_string(arg[0])
+ current_dict[key] = None
+
+
+class KeyValueAction(argparse.Action):
+ """
+ Custom argparse Action that parses KEY=VAL arguments and stores them in a dictionary.
+ """
+
+ def __init__(self, option_strings, dest, nargs=None, **kwargs: object) -> None:
+ assert nargs is None or nargs == 1
+ super().__init__(option_strings, dest, nargs=1, **kwargs)
+
+ def __call__(self, parser: argparse.ArgumentParser, namespace: argparse.Namespace,
+ arg: T.List[str], option_string: str = None) -> None:
+ current_dict = getattr(namespace, self.dest)
+ if current_dict is None:
+ current_dict = {}
+ setattr(namespace, self.dest, current_dict)
+
+ try:
+ keystr, value = arg[0].split('=', 1)
+ key = OptionKey.from_string(keystr)
+ current_dict[key] = value
+ except ValueError:
+ parser.error(f'The argument for option {option_string!r} must be in OPTION=VALUE format.')
+
+
+def register_builtin_arguments(parser: argparse.ArgumentParser) -> None:
+ for n, b in options.BUILTIN_OPTIONS.items():
+ options.option_to_argparse(b, n, parser, '')
+ for n, b in options.BUILTIN_OPTIONS_PER_MACHINE.items():
+ options.option_to_argparse(b, n, parser, ' (just for host machine)')
+ options.option_to_argparse(b, n.as_build(), parser, ' (just for build machine)')
+ parser.add_argument('-D', action=KeyValueAction, dest='cmd_line_options', default={}, metavar="option=value",
+ help='Set the value of an option, can be used several times to set multiple options.')
+
+def parse_cmd_line_options(args: SharedCMDOptions) -> None:
+ # Merge builtin options set with --option into the dict.
+ for key in chain(
+ options.BUILTIN_OPTIONS.keys(),
+ (k.as_build() for k in options.BUILTIN_OPTIONS_PER_MACHINE.keys()),
+ options.BUILTIN_OPTIONS_PER_MACHINE.keys(),
+ ):
+ name = str(key)
+ value = getattr(args, name, None)
+ if value is not None:
+ if key in args.cmd_line_options:
+ cmdline_name = options.argparse_name_to_arg(name)
+ raise MesonException(
+ f'Got argument {name} as both -D{name} and {cmdline_name}. Pick one.')
+ args.cmd_line_options[key] = value
+ delattr(args, name)
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index f801f0321..8e47322b8 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -7,11 +7,9 @@ from __future__ import annotations
import copy
from . import mlog, options
-import argparse
import pickle, os, uuid
import sys
from functools import lru_cache
-from itertools import chain
from collections import OrderedDict
import textwrap
@@ -23,16 +21,10 @@ from .mesonlib import (
from .options import OptionKey
-from .machinefile import CmdLineFileParser
-
-import ast
import enum
-import shlex
import typing as T
if T.TYPE_CHECKING:
- from typing_extensions import Protocol
-
from . import dependencies
from .compilers.compilers import Compiler, CompileResult, RunResult, CompileCheckMode
from .dependencies.detect import TV_DepID
@@ -41,28 +33,13 @@ if T.TYPE_CHECKING:
from .interpreterbase import SubProject
from .options import ElementaryOptionValues, MutableKeyedOptionDictType
from .build import BuildTarget
-
- class SharedCMDOptions(Protocol):
-
- """Representation of command line options from Meson setup, configure,
- and dist.
-
- :param cmd_line_options: command line options parsed into an OptionKey:
- str mapping
- """
-
- cmd_line_options: T.Dict[OptionKey, T.Optional[str]]
- cross_file: T.List[str]
- native_file: T.List[str]
+ from .cmdline import SharedCMDOptions
OptionDictType = T.Dict[str, options.AnyOptionType]
CompilerCheckCacheKey = T.Tuple[T.Tuple[str, ...], str, FileOrString, T.Tuple[str, ...], CompileCheckMode]
# code, args
RunCheckCacheKey = T.Tuple[str, T.Tuple[str, ...]]
- # typeshed
- StrOrBytesPath = T.Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
-
# Check major_versions_differ() if changing versioning scheme.
#
# Pip requires that RCs are named like this: '0.1.0.rc1'
@@ -479,67 +456,6 @@ class CoreData:
Please see https://mesonbuild.com/Builtin-options.html#Notes_about_Apple_Bitcode_support for more details.''')
mlog.warning(msg, once=True, fatal=False)
-def get_cmd_line_file(build_dir: str) -> str:
- return os.path.join(build_dir, 'meson-private', 'cmd_line.txt')
-
-def read_cmd_line_file(build_dir: str, options: SharedCMDOptions) -> None:
- filename = get_cmd_line_file(build_dir)
- if not os.path.isfile(filename):
- return
-
- config = CmdLineFileParser()
- config.read(filename)
-
- # Do a copy because config is not really a dict. options.cmd_line_options
- # overrides values from the file.
- d = {OptionKey.from_string(k): v for k, v in config['options'].items()}
- d.update(options.cmd_line_options)
- options.cmd_line_options = d
-
- properties = config['properties']
- if not options.cross_file:
- options.cross_file = ast.literal_eval(properties.get('cross_file', '[]'))
- if not options.native_file:
- # This will be a string in the form: "['first', 'second', ...]", use
- # literal_eval to get it into the list of strings.
- options.native_file = ast.literal_eval(properties.get('native_file', '[]'))
-
-def write_cmd_line_file(build_dir: str, options: SharedCMDOptions) -> None:
- filename = get_cmd_line_file(build_dir)
- config = CmdLineFileParser()
-
- properties: OrderedDict[str, str] = OrderedDict()
- if options.cross_file:
- properties['cross_file'] = options.cross_file
- if options.native_file:
- properties['native_file'] = options.native_file
-
- config['options'] = {str(k): str(v) for k, v in options.cmd_line_options.items()}
- config['properties'] = properties
- with open(filename, 'w', encoding='utf-8') as f:
- config.write(f)
-
-def update_cmd_line_file(build_dir: str, options: SharedCMDOptions) -> None:
- filename = get_cmd_line_file(build_dir)
- config = CmdLineFileParser()
- config.read(filename)
- for k, v in options.cmd_line_options.items():
- keystr = str(k)
- if v is not None:
- config['options'][keystr] = str(v)
- elif keystr in config['options']:
- del config['options'][keystr]
-
- with open(filename, 'w', encoding='utf-8') as f:
- config.write(f)
-
-def format_cmd_line_options(options: SharedCMDOptions) -> str:
- cmdline = ['-D{}={}'.format(str(k), v) for k, v in options.cmd_line_options.items()]
- if options.cross_file:
- cmdline += [f'--cross-file={f}' for f in options.cross_file]
- if options.native_file:
- cmdline += [f'--native-file={f}' for f in options.native_file]
- return ' '.join([shlex.quote(x) for x in cmdline])
def major_versions_differ(v1: str, v2: str) -> bool:
v1_major, v1_minor = v1.rsplit('.', 1)
@@ -569,77 +485,6 @@ def save(obj: CoreData, build_dir: str) -> str:
return filename
-class KeyNoneAction(argparse.Action):
- """
- Custom argparse Action that stores values in a dictionary as keys with value None.
- """
-
- def __init__(self, option_strings, dest, nargs=None, **kwargs: object) -> None:
- assert nargs is None or nargs == 1
- super().__init__(option_strings, dest, nargs=1, **kwargs)
-
- def __call__(self, parser: argparse.ArgumentParser, namespace: argparse.Namespace,
- arg: T.List[str], option_string: str = None) -> None:
- current_dict = getattr(namespace, self.dest)
- if current_dict is None:
- current_dict = {}
- setattr(namespace, self.dest, current_dict)
-
- key = OptionKey.from_string(arg[0])
- current_dict[key] = None
-
-
-class KeyValueAction(argparse.Action):
- """
- Custom argparse Action that parses KEY=VAL arguments and stores them in a dictionary.
- """
-
- def __init__(self, option_strings, dest, nargs=None, **kwargs: object) -> None:
- assert nargs is None or nargs == 1
- super().__init__(option_strings, dest, nargs=1, **kwargs)
-
- def __call__(self, parser: argparse.ArgumentParser, namespace: argparse.Namespace,
- arg: T.List[str], option_string: str = None) -> None:
- current_dict = getattr(namespace, self.dest)
- if current_dict is None:
- current_dict = {}
- setattr(namespace, self.dest, current_dict)
-
- try:
- keystr, value = arg[0].split('=', 1)
- key = OptionKey.from_string(keystr)
- current_dict[key] = value
- except ValueError:
- parser.error(f'The argument for option {option_string!r} must be in OPTION=VALUE format.')
-
-
-def register_builtin_arguments(parser: argparse.ArgumentParser) -> None:
- for n, b in options.BUILTIN_OPTIONS.items():
- options.option_to_argparse(b, n, parser, '')
- for n, b in options.BUILTIN_OPTIONS_PER_MACHINE.items():
- options.option_to_argparse(b, n, parser, ' (just for host machine)')
- options.option_to_argparse(b, n.as_build(), parser, ' (just for build machine)')
- parser.add_argument('-D', action=KeyValueAction, dest='cmd_line_options', default={}, metavar="option=value",
- help='Set the value of an option, can be used several times to set multiple options.')
-
-def parse_cmd_line_options(args: SharedCMDOptions) -> None:
- # Merge builtin options set with --option into the dict.
- for key in chain(
- options.BUILTIN_OPTIONS.keys(),
- (k.as_build() for k in options.BUILTIN_OPTIONS_PER_MACHINE.keys()),
- options.BUILTIN_OPTIONS_PER_MACHINE.keys(),
- ):
- name = str(key)
- value = getattr(args, name, None)
- if value is not None:
- if key in args.cmd_line_options:
- cmdline_name = options.argparse_name_to_arg(name)
- raise MesonException(
- f'Got argument {name} as both -D{name} and {cmdline_name}. Pick one.')
- args.cmd_line_options[key] = value
- delattr(args, name)
-
-
FORBIDDEN_TARGET_NAMES = frozenset({
'clean',
'clean-ctlist',
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index b33d8b854..fe364442e 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -9,13 +9,12 @@ import os, platform, re, sys, shutil
import typing as T
import collections
+from . import cmdline
from . import coredata
from . import mesonlib
from . import machinefile
from . import options
-CmdLineFileParser = machinefile.CmdLineFileParser
-
from .mesonlib import (
MesonException, MachineChoice, Popen_safe, PerMachine,
PerMachineDefaultable, PerThreeMachineDefaultable, split_args, quote_arg,
@@ -580,7 +579,7 @@ class Environment:
log_dir = 'meson-logs'
info_dir = 'meson-info'
- def __init__(self, source_dir: str, build_dir: T.Optional[str], cmd_options: coredata.SharedCMDOptions) -> None:
+ def __init__(self, source_dir: str, build_dir: T.Optional[str], cmd_options: cmdline.SharedCMDOptions) -> None:
self.source_dir = source_dir
# Do not try to create build directories when build_dir is none.
# This reduced mode is used by the --buildoptions introspector
@@ -600,15 +599,15 @@ class Environment:
except coredata.MesonVersionMismatchException as e:
# This is routine, but tell the user the update happened
mlog.log('Regenerating configuration from scratch:', str(e))
- coredata.read_cmd_line_file(self.build_dir, cmd_options)
+ cmdline.read_cmd_line_file(self.build_dir, cmd_options)
self.create_new_coredata(cmd_options)
except MesonException as e:
# If we stored previous command line options, we can recover from
# a broken/outdated coredata.
- if os.path.isfile(coredata.get_cmd_line_file(self.build_dir)):
+ if os.path.isfile(cmdline.get_cmd_line_file(self.build_dir)):
mlog.warning('Regenerating configuration from scratch.', fatal=False)
mlog.log('Reason:', mlog.red(str(e)))
- coredata.read_cmd_line_file(self.build_dir, cmd_options)
+ cmdline.read_cmd_line_file(self.build_dir, cmd_options)
self.create_new_coredata(cmd_options)
else:
raise MesonException(f'{str(e)} Try regenerating using "meson setup --wipe".')
@@ -890,7 +889,7 @@ class Environment:
self.properties[for_machine].properties.setdefault(name, p_env)
break
- def create_new_coredata(self, options: coredata.SharedCMDOptions) -> None:
+ def create_new_coredata(self, options: cmdline.SharedCMDOptions) -> None:
# WARNING: Don't use any values from coredata in __init__. It gets
# re-initialized with project options by the interpreter during
# build file parsing.
diff --git a/mesonbuild/interpreter/mesonmain.py b/mesonbuild/interpreter/mesonmain.py
index 74b655816..067d5ffb3 100644
--- a/mesonbuild/interpreter/mesonmain.py
+++ b/mesonbuild/interpreter/mesonmain.py
@@ -9,8 +9,8 @@ import typing as T
from .. import mesonlib
from .. import dependencies
-from .. import build
-from .. import mlog, coredata
+from .. import build, cmdline
+from .. import mlog
from ..mesonlib import MachineChoice
from ..options import OptionKey
@@ -485,4 +485,4 @@ class MesonMain(MesonInterpreterObject):
options = self.interpreter.user_defined_options
if options is None:
return ''
- return coredata.format_cmd_line_options(options)
+ return cmdline.format_cmd_line_options(options)
diff --git a/mesonbuild/machinefile.py b/mesonbuild/machinefile.py
index b39a47217..a20e25778 100644
--- a/mesonbuild/machinefile.py
+++ b/mesonbuild/machinefile.py
@@ -9,26 +9,12 @@ import os
from . import mparser
+from .cmdline import CmdLineFileParser
from .mesonlib import MesonException
if T.TYPE_CHECKING:
- from .coredata import StrOrBytesPath
from .options import ElementaryOptionValues
-class CmdLineFileParser(configparser.ConfigParser):
- def __init__(self) -> None:
- # We don't want ':' as key delimiter, otherwise it would break when
- # storing subproject options like "subproject:option=value"
- super().__init__(delimiters=['='], interpolation=None)
-
- def read(self, filenames: T.Union['StrOrBytesPath', T.Iterable['StrOrBytesPath']], encoding: T.Optional[str] = 'utf-8') -> T.List[str]:
- return super().read(filenames, encoding)
-
- def optionxform(self, optionstr: str) -> str:
- # Don't call str.lower() on keys
- return optionstr
-
-
class MachineFileParser():
def __init__(self, filenames: T.List[str], sourcedir: str) -> None:
self.parser = CmdLineFileParser()
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py
index 7f62ba000..4de7bc2af 100644
--- a/mesonbuild/mconf.py
+++ b/mesonbuild/mconf.py
@@ -13,6 +13,7 @@ import typing as T
import collections
from . import build
+from . import cmdline
from . import coredata
from . import options
from . import environment
@@ -28,7 +29,7 @@ if T.TYPE_CHECKING:
from typing_extensions import Protocol
import argparse
- class CMDOptions(coredata.SharedCMDOptions, Protocol):
+ class CMDOptions(cmdline.SharedCMDOptions, Protocol):
builddir: str
clearcache: bool
@@ -40,13 +41,13 @@ if T.TYPE_CHECKING:
# Note: when adding arguments, please also add them to the completion
# scripts in $MESONSRC/data/shell-completions/
def add_arguments(parser: 'argparse.ArgumentParser') -> None:
- coredata.register_builtin_arguments(parser)
+ cmdline.register_builtin_arguments(parser)
parser.add_argument('builddir', nargs='?', default='.')
parser.add_argument('--clearcache', action='store_true', default=False,
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('-U', action=coredata.KeyNoneAction, dest='cmd_line_options', default={},
+ parser.add_argument('-U', action=cmdline.KeyNoneAction, dest='cmd_line_options', default={},
help='Remove a subproject option.')
def stringify(val: T.Any) -> str:
@@ -377,7 +378,7 @@ def run_impl(options: CMDOptions, builddir: str) -> int:
save = False
if has_option_flags(options):
save |= c.coredata.set_from_configure_command(options)
- coredata.update_cmd_line_file(builddir, options)
+ cmdline.update_cmd_line_file(builddir, options)
if options.clearcache:
c.clear_cache()
save = True
@@ -396,6 +397,6 @@ def run_impl(options: CMDOptions, builddir: str) -> int:
return 0
def run(options: CMDOptions) -> int:
- coredata.parse_cmd_line_options(options)
+ cmdline.parse_cmd_line_options(options)
builddir = os.path.abspath(os.path.realpath(options.builddir))
return run_impl(options, builddir)
diff --git a/mesonbuild/mdist.py b/mesonbuild/mdist.py
index 6e1bfd0ee..a68736406 100644
--- a/mesonbuild/mdist.py
+++ b/mesonbuild/mdist.py
@@ -26,7 +26,7 @@ from mesonbuild.mesonlib import (GIT, MesonException, RealPathAction, get_meson_
from .options import OptionKey
from mesonbuild.msetup import add_arguments as msetup_argparse
from mesonbuild.wrap import wrap
-from mesonbuild import mlog, build, coredata
+from mesonbuild import mlog, build, cmdline
from .scripts.meson_exe import run_exe
if T.TYPE_CHECKING:
@@ -353,11 +353,11 @@ def check_dist(packagename: str, _meson_command: ImmutableListProtocol[str], ext
def create_cmdline_args(bld_root: str) -> T.List[str]:
parser = argparse.ArgumentParser()
msetup_argparse(parser)
- args = T.cast('coredata.SharedCMDOptions', parser.parse_args([]))
- coredata.parse_cmd_line_options(args)
- coredata.read_cmd_line_file(bld_root, args)
+ args = T.cast('cmdline.SharedCMDOptions', parser.parse_args([]))
+ cmdline.parse_cmd_line_options(args)
+ cmdline.read_cmd_line_file(bld_root, args)
args.cmd_line_options.pop(OptionKey('backend'), '')
- return shlex.split(coredata.format_cmd_line_options(args))
+ return shlex.split(cmdline.format_cmd_line_options(args))
def determine_archives_to_generate(options: argparse.Namespace) -> T.List[str]:
result = []
diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py
index 179ff3fa2..33c489958 100644
--- a/mesonbuild/msetup.py
+++ b/mesonbuild/msetup.py
@@ -9,7 +9,7 @@ import cProfile as profile
from pathlib import Path
import typing as T
-from . import build, coredata, environment, interpreter, mesonlib, mintro, mlog
+from . import build, cmdline, coredata, environment, interpreter, mesonlib, mintro, mlog
from .dependencies import Dependency
from .mesonlib import MesonException
from .interpreterbase import ObjectHolder
@@ -17,7 +17,7 @@ from .options import OptionKey
if T.TYPE_CHECKING:
from typing_extensions import Protocol
- from .coredata import SharedCMDOptions
+ from .cmdline import SharedCMDOptions
from .interpreter import SubprojectHolder
class CMDOptions(SharedCMDOptions, Protocol):
@@ -44,7 +44,7 @@ syntax: glob
# Note: when adding arguments, please also add them to the completion
# scripts in $MESONSRC/data/shell-completions/
def add_arguments(parser: argparse.ArgumentParser) -> None:
- coredata.register_builtin_arguments(parser)
+ cmdline.register_builtin_arguments(parser)
parser.add_argument('--native-file',
default=[],
action='append',
@@ -82,7 +82,7 @@ class MesonApp:
# configuration fails we need to be able to wipe again.
restore = []
with tempfile.TemporaryDirectory() as d:
- for filename in [coredata.get_cmd_line_file(self.build_dir)] + glob.glob(os.path.join(self.build_dir, environment.Environment.private_dir, '*.ini')):
+ for filename in [cmdline.get_cmd_line_file(self.build_dir)] + glob.glob(os.path.join(self.build_dir, environment.Environment.private_dir, '*.ini')):
try:
restore.append((shutil.copy(filename, d), filename))
except FileNotFoundError:
@@ -90,7 +90,7 @@ class MesonApp:
# a partial build or is empty.
pass
- coredata.read_cmd_line_file(self.build_dir, options)
+ cmdline.read_cmd_line_file(self.build_dir, options)
try:
# Don't delete the whole tree, just all of the files and
@@ -219,11 +219,11 @@ class MesonApp:
# Get all user defined options, including options that have been defined
# during a previous invocation or using meson configure.
user_defined_options = T.cast('CMDOptions', argparse.Namespace(**vars(self.options)))
- coredata.read_cmd_line_file(self.build_dir, user_defined_options)
+ cmdline.read_cmd_line_file(self.build_dir, user_defined_options)
mlog.debug('Build started at', datetime.datetime.now().isoformat())
mlog.debug('Main binary:', sys.executable)
- mlog.debug('Build Options:', coredata.format_cmd_line_options(user_defined_options))
+ mlog.debug('Build Options:', cmdline.format_cmd_line_options(user_defined_options))
mlog.debug('Python system:', platform.system())
mlog.log(mlog.bold('The Meson build system'))
mlog.log('Version:', coredata.version)
@@ -289,9 +289,9 @@ class MesonApp:
# read from a pipe and wrote into a private file.
self.options.cross_file = env.coredata.cross_files
self.options.native_file = env.coredata.config_files
- coredata.write_cmd_line_file(self.build_dir, self.options)
+ cmdline.write_cmd_line_file(self.build_dir, self.options)
else:
- coredata.update_cmd_line_file(self.build_dir, self.options)
+ cmdline.update_cmd_line_file(self.build_dir, self.options)
# Generate an IDE introspection file with the same syntax as the already existing API
if self.options.profile:
@@ -390,7 +390,7 @@ def run(options: T.Union[CMDOptions, T.List[str]]) -> int:
parser = argparse.ArgumentParser()
add_arguments(parser)
options = T.cast('CMDOptions', parser.parse_args(options))
- coredata.parse_cmd_line_options(options)
+ cmdline.parse_cmd_line_options(options)
# Msetup doesn't actually use this option, but we pass msetup options to
# mconf, and it does. We won't actually hit the path that uses it, but don't
diff --git a/mesonbuild/scripts/scanbuild.py b/mesonbuild/scripts/scanbuild.py
index 24e6924a5..20ce0a621 100644
--- a/mesonbuild/scripts/scanbuild.py
+++ b/mesonbuild/scripts/scanbuild.py
@@ -6,9 +6,8 @@ from __future__ import annotations
import subprocess
import shutil
import tempfile
+from ..cmdline import get_cmd_line_file, CmdLineFileParser
from ..environment import detect_ninja, detect_scanbuild
-from ..coredata import get_cmd_line_file
-from ..machinefile import CmdLineFileParser
from ..mesonlib import windows_proof_rmtree, determine_worker_count
from pathlib import Path
import typing as T
diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py
index d8e80068f..a2f09cf88 100644
--- a/mesonbuild/utils/universal.py
+++ b/mesonbuild/utils/universal.py
@@ -34,7 +34,7 @@ if T.TYPE_CHECKING:
from .._typing import ImmutableListProtocol
from ..build import ConfigurationData
- from ..coredata import StrOrBytesPath
+ from ..cmdline import StrOrBytesPath
from ..environment import Environment
from ..compilers.compilers import Compiler
from ..interpreterbase.baseobjects import SubProject
diff --git a/test cases/unit/116 empty project/expected_mods.json b/test cases/unit/116 empty project/expected_mods.json
index abba97dd9..defd6ea2f 100644
--- a/test cases/unit/116 empty project/expected_mods.json
+++ b/test cases/unit/116 empty project/expected_mods.json
@@ -181,6 +181,7 @@
"mesonbuild.backend.backends",
"mesonbuild.backend.ninjabackend",
"mesonbuild.build",
+ "mesonbuild.cmdline",
"mesonbuild.compilers",
"mesonbuild.compilers.compilers",
"mesonbuild.compilers.detect",
@@ -238,6 +239,6 @@
"mesonbuild.wrap",
"mesonbuild.wrap.wrap"
],
- "count": 69
+ "count": 70
}
}