2023-12-14 03:38:41 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2016-01-16 23:07:43 +08:00
|
|
|
# Copyright 2014-2016 The Meson development team
|
2024-03-09 03:17:58 +08:00
|
|
|
# Copyright © 2023-2024 Intel Corporation
|
2014-01-06 03:36:25 +08:00
|
|
|
|
2022-09-14 09:22:35 +08:00
|
|
|
from __future__ import annotations
|
2014-01-06 03:36:25 +08:00
|
|
|
|
2021-04-21 05:16:37 +08:00
|
|
|
import itertools
|
2024-03-09 03:17:58 +08:00
|
|
|
import hashlib
|
2021-04-21 05:16:37 +08:00
|
|
|
import shutil
|
2018-03-05 02:56:53 +08:00
|
|
|
import os
|
2021-04-21 05:16:37 +08:00
|
|
|
import textwrap
|
2020-09-01 20:28:08 +08:00
|
|
|
import typing as T
|
2021-10-04 23:11:17 +08:00
|
|
|
import collections
|
2014-01-06 03:36:25 +08:00
|
|
|
|
2021-04-21 04:38:13 +08:00
|
|
|
from . import build
|
|
|
|
from . import coredata
|
2024-05-23 04:59:02 +08:00
|
|
|
from . import options
|
2021-04-21 04:38:13 +08:00
|
|
|
from . import environment
|
|
|
|
from . import mesonlib
|
|
|
|
from . import mintro
|
|
|
|
from . import mlog
|
2023-04-26 02:47:37 +08:00
|
|
|
from .ast import AstIDGenerator, IntrospectionInterpreter
|
2020-12-05 08:09:10 +08:00
|
|
|
from .mesonlib import MachineChoice, OptionKey
|
2024-03-09 03:17:58 +08:00
|
|
|
from .optinterpreter import OptionInterpreter
|
2020-12-03 08:02:03 +08:00
|
|
|
|
2020-09-01 20:28:08 +08:00
|
|
|
if T.TYPE_CHECKING:
|
2023-12-12 04:06:31 +08:00
|
|
|
from typing_extensions import Protocol
|
2024-06-12 02:20:33 +08:00
|
|
|
from typing import Any
|
|
|
|
from .options import UserOption
|
2020-09-01 20:28:08 +08:00
|
|
|
import argparse
|
|
|
|
|
2023-12-12 04:06:31 +08:00
|
|
|
class CMDOptions(coredata.SharedCMDOptions, Protocol):
|
|
|
|
|
|
|
|
builddir: str
|
|
|
|
clearcache: bool
|
|
|
|
pager: bool
|
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
# cannot be TV_Loggable, because non-ansidecorators do direct string concat
|
|
|
|
LOGLINE = T.Union[str, mlog.AnsiDecorator]
|
|
|
|
|
2023-09-11 14:37:51 +08:00
|
|
|
# Note: when adding arguments, please also add them to the completion
|
|
|
|
# scripts in $MESONSRC/data/shell-completions/
|
2020-09-01 20:28:08 +08:00
|
|
|
def add_arguments(parser: 'argparse.ArgumentParser') -> None:
|
2018-03-16 07:19:13 +08:00
|
|
|
coredata.register_builtin_arguments(parser)
|
2018-05-13 22:36:58 +08:00
|
|
|
parser.add_argument('builddir', nargs='?', default='.')
|
2018-03-25 23:22:52 +08:00
|
|
|
parser.add_argument('--clearcache', action='store_true', default=False,
|
|
|
|
help='Clear cached state (e.g. found dependencies)')
|
2022-09-24 02:26:06 +08:00
|
|
|
parser.add_argument('--no-pager', action='store_false', dest='pager',
|
2022-09-07 06:25:59 +08:00
|
|
|
help='Do not redirect output to a pager')
|
2014-01-06 05:03:52 +08:00
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def stringify(val: T.Any) -> str:
|
2019-01-06 05:12:02 +08:00
|
|
|
if isinstance(val, bool):
|
|
|
|
return str(val).lower()
|
|
|
|
elif isinstance(val, list):
|
2022-09-24 03:52:30 +08:00
|
|
|
s = ', '.join(stringify(i) for i in val)
|
|
|
|
return f'[{s}]'
|
|
|
|
elif val is None:
|
|
|
|
return ''
|
2019-01-06 05:12:02 +08:00
|
|
|
else:
|
|
|
|
return str(val)
|
|
|
|
|
|
|
|
|
2016-03-23 01:31:55 +08:00
|
|
|
class ConfException(mesonlib.MesonException):
|
2017-05-17 15:54:49 +08:00
|
|
|
pass
|
2014-01-06 03:45:07 +08:00
|
|
|
|
2018-03-05 02:56:53 +08:00
|
|
|
|
2014-01-06 03:45:07 +08:00
|
|
|
class Conf:
|
2023-06-22 08:04:01 +08:00
|
|
|
def __init__(self, build_dir: str):
|
2019-01-25 19:21:32 +08:00
|
|
|
self.build_dir = os.path.abspath(os.path.realpath(build_dir))
|
2019-02-05 18:18:57 +08:00
|
|
|
if 'meson.build' in [os.path.basename(self.build_dir), self.build_dir]:
|
2019-01-25 19:21:32 +08:00
|
|
|
self.build_dir = os.path.dirname(self.build_dir)
|
2019-02-05 18:18:57 +08:00
|
|
|
self.build = None
|
2019-02-17 17:10:18 +08:00
|
|
|
self.max_choices_line_length = 60
|
2023-06-22 08:04:01 +08:00
|
|
|
self.name_col: T.List[LOGLINE] = []
|
|
|
|
self.value_col: T.List[LOGLINE] = []
|
|
|
|
self.choices_col: T.List[LOGLINE] = []
|
|
|
|
self.descr_col: T.List[LOGLINE] = []
|
2020-12-05 08:09:10 +08:00
|
|
|
self.all_subprojects: T.Set[str] = set()
|
2019-01-25 19:21:32 +08:00
|
|
|
|
|
|
|
if os.path.isdir(os.path.join(self.build_dir, 'meson-private')):
|
|
|
|
self.build = build.load(self.build_dir)
|
|
|
|
self.source_dir = self.build.environment.get_source_dir()
|
2023-01-19 23:38:38 +08:00
|
|
|
self.coredata = self.build.environment.coredata
|
2019-01-25 19:21:32 +08:00
|
|
|
self.default_values_only = False
|
2024-03-09 03:17:58 +08:00
|
|
|
|
|
|
|
# if the option file has been updated, reload it
|
|
|
|
# This cannot handle options for a new subproject that has not yet
|
|
|
|
# been configured.
|
2024-05-23 04:59:02 +08:00
|
|
|
for sub, conf_options in self.coredata.options_files.items():
|
|
|
|
if conf_options is not None and os.path.exists(conf_options[0]):
|
|
|
|
opfile = conf_options[0]
|
2024-03-09 03:17:58 +08:00
|
|
|
with open(opfile, 'rb') as f:
|
|
|
|
ophash = hashlib.sha1(f.read()).hexdigest()
|
2024-05-23 04:59:02 +08:00
|
|
|
if ophash != conf_options[1]:
|
2024-03-09 03:17:58 +08:00
|
|
|
oi = OptionInterpreter(sub)
|
|
|
|
oi.process(opfile)
|
|
|
|
self.coredata.update_project_options(oi.options, sub)
|
|
|
|
self.coredata.options_files[sub] = (opfile, ophash)
|
|
|
|
else:
|
|
|
|
opfile = os.path.join(self.source_dir, 'meson.options')
|
|
|
|
if not os.path.exists(opfile):
|
|
|
|
opfile = os.path.join(self.source_dir, 'meson_options.txt')
|
|
|
|
if os.path.exists(opfile):
|
|
|
|
oi = OptionInterpreter(sub)
|
|
|
|
oi.process(opfile)
|
|
|
|
self.coredata.update_project_options(oi.options, sub)
|
|
|
|
with open(opfile, 'rb') as f:
|
|
|
|
ophash = hashlib.sha1(f.read()).hexdigest()
|
|
|
|
self.coredata.options_files[sub] = (opfile, ophash)
|
|
|
|
else:
|
|
|
|
self.coredata.update_project_options({}, sub)
|
2019-01-25 19:21:32 +08:00
|
|
|
elif os.path.isfile(os.path.join(self.build_dir, environment.build_filename)):
|
|
|
|
# Make sure that log entries in other parts of meson don't interfere with the JSON output
|
2022-11-19 05:25:12 +08:00
|
|
|
with mlog.no_logging():
|
|
|
|
self.source_dir = os.path.abspath(os.path.realpath(self.build_dir))
|
2023-04-26 02:47:37 +08:00
|
|
|
intr = IntrospectionInterpreter(self.source_dir, '', 'ninja', visitors = [AstIDGenerator()])
|
2022-11-19 05:25:12 +08:00
|
|
|
intr.analyze()
|
2019-01-25 19:21:32 +08:00
|
|
|
self.coredata = intr.coredata
|
|
|
|
self.default_values_only = True
|
|
|
|
else:
|
2021-03-05 06:16:11 +08:00
|
|
|
raise ConfException(f'Directory {build_dir} is neither a Meson build directory nor a project source directory.')
|
2014-01-06 04:01:52 +08:00
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def clear_cache(self) -> None:
|
2023-05-30 00:53:51 +08:00
|
|
|
self.coredata.clear_cache()
|
2017-01-14 22:24:07 +08:00
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def set_options(self, options: T.Dict[OptionKey, str]) -> bool:
|
2022-07-15 20:10:31 +08:00
|
|
|
return self.coredata.set_options(options)
|
2018-05-13 22:36:58 +08:00
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def save(self) -> None:
|
2019-01-25 19:21:32 +08:00
|
|
|
# Do nothing when using introspection
|
|
|
|
if self.default_values_only:
|
|
|
|
return
|
2018-03-01 06:25:12 +08:00
|
|
|
coredata.save(self.coredata, self.build_dir)
|
2014-06-08 04:39:59 +08:00
|
|
|
# We don't write the build file because any changes to it
|
2017-11-27 01:28:33 +08:00
|
|
|
# are erased when Meson is executed the next time, i.e. when
|
2017-01-14 22:24:07 +08:00
|
|
|
# Ninja is run.
|
2014-01-06 05:03:52 +08:00
|
|
|
|
2021-04-21 05:16:37 +08:00
|
|
|
def print_aligned(self) -> None:
|
|
|
|
"""Do the actual printing.
|
|
|
|
|
|
|
|
This prints the generated output in an aligned, pretty form. it aims
|
|
|
|
for a total width of 160 characters, but will use whatever the tty
|
|
|
|
reports it's value to be. Though this is much wider than the standard
|
|
|
|
80 characters of terminals, and even than the newer 120, compressing
|
|
|
|
it to those lengths makes the output hard to read.
|
|
|
|
|
|
|
|
Each column will have a specific width, and will be line wrapped.
|
|
|
|
"""
|
|
|
|
total_width = shutil.get_terminal_size(fallback=(160, 0))[0]
|
|
|
|
_col = max(total_width // 5, 20)
|
2022-09-07 05:36:58 +08:00
|
|
|
last_column = total_width - (3 * _col) - 3
|
2022-06-19 23:47:48 +08:00
|
|
|
four_column = (_col, _col, _col, last_column if last_column > 1 else _col)
|
2018-03-04 20:42:28 +08:00
|
|
|
|
2019-07-18 02:17:18 +08:00
|
|
|
for line in zip(self.name_col, self.value_col, self.choices_col, self.descr_col):
|
2021-04-21 05:16:37 +08:00
|
|
|
if not any(line):
|
2022-09-03 08:43:19 +08:00
|
|
|
mlog.log('')
|
2021-04-21 05:16:37 +08:00
|
|
|
continue
|
|
|
|
|
|
|
|
# This is a header, like `Subproject foo:`,
|
|
|
|
# We just want to print that and get on with it
|
|
|
|
if line[0] and not any(line[1:]):
|
2022-09-03 08:43:19 +08:00
|
|
|
mlog.log(line[0])
|
2021-04-21 05:16:37 +08:00
|
|
|
continue
|
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def wrap_text(text: LOGLINE, width: int) -> mlog.TV_LoggableList:
|
2022-09-07 05:39:10 +08:00
|
|
|
raw = text.text if isinstance(text, mlog.AnsiDecorator) else text
|
|
|
|
indent = ' ' if raw.startswith('[') else ''
|
2023-06-22 08:04:01 +08:00
|
|
|
wrapped_ = textwrap.wrap(raw, width, subsequent_indent=indent)
|
|
|
|
# We cast this because https://github.com/python/mypy/issues/1965
|
|
|
|
# mlog.TV_LoggableList does not provide __len__ for stringprotocol
|
2022-09-07 05:39:10 +08:00
|
|
|
if isinstance(text, mlog.AnsiDecorator):
|
2023-06-22 08:04:01 +08:00
|
|
|
wrapped = T.cast('T.List[LOGLINE]', [mlog.AnsiDecorator(i, text.code) for i in wrapped_])
|
|
|
|
else:
|
|
|
|
wrapped = T.cast('T.List[LOGLINE]', wrapped_)
|
2022-09-07 05:39:10 +08:00
|
|
|
# Add padding here to get even rows, as `textwrap.wrap()` will
|
|
|
|
# only shorten, not lengthen each item
|
|
|
|
return [str(i) + ' ' * (width - len(i)) for i in wrapped]
|
|
|
|
|
2021-04-21 05:16:37 +08:00
|
|
|
# wrap will take a long string, and create a list of strings no
|
|
|
|
# longer than the size given. Then that list can be zipped into, to
|
|
|
|
# print each line of the output, such the that columns are printed
|
|
|
|
# to the right width, row by row.
|
2022-09-07 05:39:10 +08:00
|
|
|
name = wrap_text(line[0], four_column[0])
|
|
|
|
val = wrap_text(line[1], four_column[1])
|
|
|
|
choice = wrap_text(line[2], four_column[2])
|
|
|
|
desc = wrap_text(line[3], four_column[3])
|
2022-09-07 05:32:32 +08:00
|
|
|
for l in itertools.zip_longest(name, val, choice, desc, fillvalue=''):
|
2022-09-07 05:39:10 +08:00
|
|
|
items = [l[i] if l[i] else ' ' * four_column[i] for i in range(4)]
|
|
|
|
mlog.log(*items)
|
2019-07-18 02:17:18 +08:00
|
|
|
|
2024-06-12 02:20:33 +08:00
|
|
|
def split_options_per_subproject(self, options: 'T.Union[dict[OptionKey, UserOption[Any]], coredata.KeyedOptionDictType]') -> T.Dict[str, 'coredata.MutableKeyedOptionDictType']:
|
2023-06-22 08:04:01 +08:00
|
|
|
result: T.Dict[str, 'coredata.MutableKeyedOptionDictType'] = {}
|
2020-12-01 08:49:18 +08:00
|
|
|
for k, o in options.items():
|
|
|
|
if k.subproject:
|
2022-04-12 21:52:50 +08:00
|
|
|
self.all_subprojects.add(k.subproject)
|
|
|
|
result.setdefault(k.subproject, {})[k] = o
|
2020-12-01 08:49:18 +08:00
|
|
|
return result
|
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def _add_line(self, name: LOGLINE, value: LOGLINE, choices: LOGLINE, descr: LOGLINE) -> None:
|
2022-09-07 05:39:10 +08:00
|
|
|
if isinstance(name, mlog.AnsiDecorator):
|
|
|
|
name.text = ' ' * self.print_margin + name.text
|
|
|
|
else:
|
|
|
|
name = ' ' * self.print_margin + name
|
|
|
|
self.name_col.append(name)
|
2019-07-18 02:17:18 +08:00
|
|
|
self.value_col.append(value)
|
|
|
|
self.choices_col.append(choices)
|
|
|
|
self.descr_col.append(descr)
|
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def add_option(self, name: str, descr: str, value: T.Any, choices: T.Any) -> None:
|
2022-09-24 03:52:30 +08:00
|
|
|
value = stringify(value)
|
|
|
|
choices = stringify(choices)
|
2022-09-07 05:39:10 +08:00
|
|
|
self._add_line(mlog.green(name), mlog.yellow(value), mlog.blue(choices), descr)
|
mesonconf: reorder output columns
mesonconf prints build dir information in the order of
'Option' 'Description' 'Current Value' and, optionally, 'Possible Value'.
The Description tends to be longer and push the following values far
right, sometimes way far than fits in the full screen size of a
terminal on a FullHD monitor.
Experienced users know which options they want to change without
looking at the description string however they need to check the
current values for sure.
This patch moves the description to the last column. Now mesonconf
prints options in the following order:
'Option' 'Current Value' 'Possible Value' 'Description'
To implement this, mainly print_aligned() is modified. The second
argument of the function is changed from
- array of array of string to
- array of dict with 'name', 'descr', 'value', and 'choices,
which maps to 'option', 'description', 'current value' and 'possible
values', respectively.
Since the position of the possible values are moved before its
description, the presence and the length of it affects header as well
as the following description. Thus, we cal curate it before printing
the header.
To avoid re-calculation, we keep string version of the values and
flattened version of the possible values _in the given array_, which
means that now the print_aligned() function modify the the given
array. The current callers do not use the passing array. So there
should be no bad effects.
2017-05-10 13:49:01 +08:00
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def add_title(self, title: str) -> None:
|
|
|
|
newtitle = mlog.cyan(title)
|
2022-09-07 05:39:10 +08:00
|
|
|
descr = mlog.cyan('Description')
|
|
|
|
value = mlog.cyan('Default Value' if self.default_values_only else 'Current Value')
|
|
|
|
choices = mlog.cyan('Possible Values')
|
2019-07-18 02:17:18 +08:00
|
|
|
self._add_line('', '', '', '')
|
2023-06-22 08:04:01 +08:00
|
|
|
self._add_line(newtitle, value, choices, descr)
|
|
|
|
self._add_line('-' * len(newtitle), '-' * len(value), '-' * len(choices), '-' * len(descr))
|
2019-07-18 02:17:18 +08:00
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def add_section(self, section: str) -> None:
|
2019-07-18 02:17:18 +08:00
|
|
|
self.print_margin = 0
|
|
|
|
self._add_line('', '', '', '')
|
2022-09-07 05:39:10 +08:00
|
|
|
self._add_line(mlog.normal_yellow(section + ':'), '', '', '')
|
2019-07-18 02:17:18 +08:00
|
|
|
self.print_margin = 2
|
2014-01-06 04:15:29 +08:00
|
|
|
|
2024-06-12 02:20:33 +08:00
|
|
|
def print_options(self, title: str, opts: 'T.Union[dict[OptionKey, UserOption[Any]], coredata.KeyedOptionDictType]') -> None:
|
2024-05-23 04:59:02 +08:00
|
|
|
if not opts:
|
2019-07-18 02:17:18 +08:00
|
|
|
return
|
|
|
|
if title:
|
|
|
|
self.add_title(title)
|
2024-06-09 06:03:49 +08:00
|
|
|
auto = T.cast('options.UserFeatureOption', self.coredata.optstore.get_value_object('auto_features'))
|
2024-05-23 04:59:02 +08:00
|
|
|
for k, o in sorted(opts.items()):
|
2019-07-18 02:17:18 +08:00
|
|
|
printable_value = o.printable_value()
|
2022-04-12 21:52:50 +08:00
|
|
|
root = k.as_root()
|
2024-06-09 04:16:36 +08:00
|
|
|
if o.yielding and k.subproject and root in self.coredata.optstore:
|
2019-07-18 02:17:18 +08:00
|
|
|
printable_value = '<inherited from main project>'
|
2024-05-23 04:59:02 +08:00
|
|
|
if isinstance(o, options.UserFeatureOption) and o.is_auto():
|
2023-02-05 19:14:56 +08:00
|
|
|
printable_value = auto.printable_value()
|
2022-04-12 21:52:50 +08:00
|
|
|
self.add_option(str(root), o.description, printable_value, o.choices)
|
2018-05-13 22:36:58 +08:00
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def print_conf(self, pager: bool) -> None:
|
2022-09-24 02:26:06 +08:00
|
|
|
if pager:
|
|
|
|
mlog.start_pager()
|
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def print_default_values_warning() -> None:
|
2019-01-25 19:21:32 +08:00
|
|
|
mlog.warning('The source directory instead of the build directory was specified.')
|
2023-05-30 00:52:30 +08:00
|
|
|
mlog.warning('Only the default values for the project are printed.')
|
2019-01-25 19:21:32 +08:00
|
|
|
|
|
|
|
if self.default_values_only:
|
|
|
|
print_default_values_warning()
|
2022-09-03 08:43:19 +08:00
|
|
|
mlog.log('')
|
2019-01-25 19:21:32 +08:00
|
|
|
|
2022-09-03 08:43:19 +08:00
|
|
|
mlog.log('Core properties:')
|
|
|
|
mlog.log(' Source dir', self.source_dir)
|
2019-01-25 19:21:32 +08:00
|
|
|
if not self.default_values_only:
|
2022-09-03 08:43:19 +08:00
|
|
|
mlog.log(' Build dir ', self.build_dir)
|
2018-05-13 22:36:58 +08:00
|
|
|
|
2024-05-23 04:59:02 +08:00
|
|
|
dir_option_names = set(options.BUILTIN_DIR_OPTIONS)
|
2020-12-05 08:09:10 +08:00
|
|
|
test_option_names = {OptionKey('errorlogs'),
|
2021-10-22 07:05:27 +08:00
|
|
|
OptionKey('stdsplit')}
|
2020-12-05 09:01:45 +08:00
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
dir_options: 'coredata.MutableKeyedOptionDictType' = {}
|
|
|
|
test_options: 'coredata.MutableKeyedOptionDictType' = {}
|
|
|
|
core_options: 'coredata.MutableKeyedOptionDictType' = {}
|
|
|
|
module_options: T.Dict[str, 'coredata.MutableKeyedOptionDictType'] = collections.defaultdict(dict)
|
2024-06-09 04:16:36 +08:00
|
|
|
for k, v in self.coredata.optstore.items():
|
2020-12-05 09:01:45 +08:00
|
|
|
if k in dir_option_names:
|
|
|
|
dir_options[k] = v
|
|
|
|
elif k in test_option_names:
|
|
|
|
test_options[k] = v
|
2021-10-04 23:11:17 +08:00
|
|
|
elif k.module:
|
|
|
|
# Ignore module options if we did not use that module during
|
|
|
|
# configuration.
|
|
|
|
if self.build and k.module not in self.build.modules:
|
|
|
|
continue
|
|
|
|
module_options[k.module][k] = v
|
2020-12-05 09:01:45 +08:00
|
|
|
elif k.is_builtin():
|
|
|
|
core_options[k] = v
|
|
|
|
|
|
|
|
host_core_options = self.split_options_per_subproject({k: v for k, v in core_options.items() if k.machine is MachineChoice.HOST})
|
|
|
|
build_core_options = self.split_options_per_subproject({k: v for k, v in core_options.items() if k.machine is MachineChoice.BUILD})
|
2024-06-09 04:16:36 +08:00
|
|
|
host_compiler_options = self.split_options_per_subproject({k: v for k, v in self.coredata.optstore.items() if k.is_compiler() and k.machine is MachineChoice.HOST})
|
|
|
|
build_compiler_options = self.split_options_per_subproject({k: v for k, v in self.coredata.optstore.items() if k.is_compiler() and k.machine is MachineChoice.BUILD})
|
|
|
|
project_options = self.split_options_per_subproject({k: v for k, v in self.coredata.optstore.items() if k.is_project()})
|
2019-07-18 02:17:18 +08:00
|
|
|
show_build_options = self.default_values_only or self.build.environment.is_cross_build()
|
|
|
|
|
|
|
|
self.add_section('Main project options')
|
2020-12-05 08:09:10 +08:00
|
|
|
self.print_options('Core options', host_core_options[''])
|
2019-07-18 02:17:18 +08:00
|
|
|
if show_build_options:
|
2020-12-05 08:09:10 +08:00
|
|
|
self.print_options('', build_core_options[''])
|
2024-06-09 04:16:36 +08:00
|
|
|
self.print_options('Backend options', {k: v for k, v in self.coredata.optstore.items() if k.is_backend()})
|
|
|
|
self.print_options('Base options', {k: v for k, v in self.coredata.optstore.items() if k.is_base()})
|
2019-10-21 22:38:58 +08:00
|
|
|
self.print_options('Compiler options', host_compiler_options.get('', {}))
|
2019-07-18 02:17:18 +08:00
|
|
|
if show_build_options:
|
2019-10-21 22:38:58 +08:00
|
|
|
self.print_options('', build_compiler_options.get('', {}))
|
2021-10-04 23:11:17 +08:00
|
|
|
for mod, mod_options in module_options.items():
|
|
|
|
self.print_options(f'{mod} module options', mod_options)
|
2018-05-13 22:36:58 +08:00
|
|
|
self.print_options('Directories', dir_options)
|
|
|
|
self.print_options('Testing options', test_options)
|
2019-10-21 22:38:58 +08:00
|
|
|
self.print_options('Project options', project_options.get('', {}))
|
2019-07-18 02:17:18 +08:00
|
|
|
for subproject in sorted(self.all_subprojects):
|
|
|
|
if subproject == '':
|
|
|
|
continue
|
|
|
|
self.add_section('Subproject ' + subproject)
|
2021-04-21 04:25:08 +08:00
|
|
|
if subproject in host_core_options:
|
|
|
|
self.print_options('Core options', host_core_options[subproject])
|
|
|
|
if subproject in build_core_options and show_build_options:
|
|
|
|
self.print_options('', build_core_options[subproject])
|
2019-07-18 02:17:18 +08:00
|
|
|
if subproject in host_compiler_options:
|
|
|
|
self.print_options('Compiler options', host_compiler_options[subproject])
|
|
|
|
if subproject in build_compiler_options and show_build_options:
|
|
|
|
self.print_options('', build_compiler_options[subproject])
|
|
|
|
if subproject in project_options:
|
|
|
|
self.print_options('Project options', project_options[subproject])
|
|
|
|
self.print_aligned()
|
2014-01-06 03:36:25 +08:00
|
|
|
|
2019-01-25 19:21:32 +08:00
|
|
|
# Print the warning twice so that the user shouldn't be able to miss it
|
|
|
|
if self.default_values_only:
|
2022-09-03 08:43:19 +08:00
|
|
|
mlog.log('')
|
2019-01-25 19:21:32 +08:00
|
|
|
print_default_values_warning()
|
2018-03-05 02:56:53 +08:00
|
|
|
|
2021-01-13 03:51:19 +08:00
|
|
|
self.print_nondefault_buildtype_options()
|
|
|
|
|
2023-06-22 08:04:01 +08:00
|
|
|
def print_nondefault_buildtype_options(self) -> None:
|
2021-01-13 03:51:19 +08:00
|
|
|
mismatching = self.coredata.get_nondefault_buildtype_args()
|
|
|
|
if not mismatching:
|
|
|
|
return
|
2022-09-03 08:43:19 +08:00
|
|
|
mlog.log("\nThe following option(s) have a different value than the build type default\n")
|
|
|
|
mlog.log(' current default')
|
2021-01-13 03:51:19 +08:00
|
|
|
for m in mismatching:
|
2022-09-03 08:43:19 +08:00
|
|
|
mlog.log(f'{m[0]:21}{m[1]:10}{m[2]:10}')
|
2021-01-13 03:51:19 +08:00
|
|
|
|
2023-12-12 04:06:31 +08:00
|
|
|
def run_impl(options: CMDOptions, builddir: str) -> int:
|
2023-05-30 00:52:30 +08:00
|
|
|
print_only = not options.cmd_line_options and not options.clearcache
|
2019-01-03 02:27:20 +08:00
|
|
|
c = None
|
2014-01-06 03:45:07 +08:00
|
|
|
try:
|
|
|
|
c = Conf(builddir)
|
2023-05-30 00:52:30 +08:00
|
|
|
if c.default_values_only and not print_only:
|
|
|
|
raise mesonlib.MesonException('No valid build directory found, cannot modify options.')
|
|
|
|
if c.default_values_only or print_only:
|
2022-09-24 02:26:06 +08:00
|
|
|
c.print_conf(options.pager)
|
2019-02-05 18:18:57 +08:00
|
|
|
return 0
|
|
|
|
|
2017-01-14 22:24:07 +08:00
|
|
|
save = False
|
2020-12-01 04:10:40 +08:00
|
|
|
if options.cmd_line_options:
|
2022-07-15 20:10:31 +08:00
|
|
|
save = c.set_options(options.cmd_line_options)
|
2018-10-26 00:19:23 +08:00
|
|
|
coredata.update_cmd_line_file(builddir, options)
|
2023-05-30 00:52:30 +08:00
|
|
|
if options.clearcache:
|
2017-01-14 22:24:07 +08:00
|
|
|
c.clear_cache()
|
|
|
|
save = True
|
|
|
|
if save:
|
|
|
|
c.save()
|
2018-12-03 01:14:44 +08:00
|
|
|
mintro.update_build_options(c.coredata, c.build.environment.info_dir)
|
2019-01-03 02:27:20 +08:00
|
|
|
mintro.write_meson_info_file(c.build, [])
|
2015-11-10 06:45:05 +08:00
|
|
|
except ConfException as e:
|
2022-09-03 08:43:19 +08:00
|
|
|
mlog.log('Meson configurator encountered an error:')
|
2019-01-03 02:27:20 +08:00
|
|
|
if c is not None and c.build is not None:
|
|
|
|
mintro.write_meson_info_file(c.build, [e])
|
2018-03-10 20:18:15 +08:00
|
|
|
raise e
|
2022-09-03 08:46:29 +08:00
|
|
|
except BrokenPipeError:
|
|
|
|
# Pager quit before we wrote everything.
|
|
|
|
pass
|
2016-01-16 23:07:43 +08:00
|
|
|
return 0
|
2023-03-30 21:29:27 +08:00
|
|
|
|
2023-12-12 04:06:31 +08:00
|
|
|
def run(options: CMDOptions) -> int:
|
2023-03-30 21:29:27 +08:00
|
|
|
coredata.parse_cmd_line_options(options)
|
|
|
|
builddir = os.path.abspath(os.path.realpath(options.builddir))
|
|
|
|
return run_impl(options, builddir)
|