aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2022-12-14 10:59:36 -0800
committerJussi Pakkanen <jpakkane@gmail.com>2023-03-28 15:01:10 +0300
commit4a014d17240f50059e20ccae3e9faaa395bdbf98 (patch)
tree4b2ae56e23db1cee4d04d602bfb1e154259cba36 /mesonbuild
parent65482497d326b0026eb11419d178d19b20ebe58b (diff)
downloadmeson-4a014d17240f50059e20ccae3e9faaa395bdbf98.zip
meson-4a014d17240f50059e20ccae3e9faaa395bdbf98.tar.gz
meson-4a014d17240f50059e20ccae3e9faaa395bdbf98.tar.bz2
Add support for meson.options as a replacement for meson_options.txt
We will still try to load `meson_options.txt` if `meson.options` doesn't exist. Because there are some advantages to using `meson.options` even with older versions of meson (such as better text editor handling) we will not warn about the existence of a `meson.options` file if a `meson_options.txt` file or symlink also exists. The name `meson.options` was picked instead of alternative proposals, such as `meson_options.build` for a couple of reasons: 1. meson.options is shorter 2. While the syntax is the same, only the `option()` function may be called in meson.options, while, it may not be called in meson.build 3. While the two files share a syntax and elementary types (strings, arrays, etc), they have different purposes: `meson.build` declares build targets, `meson.options` declares options. This is similar to the difference between C's `.c` and `.h` extensions. As an implementation detail `Interpreter.option_file` has been removed, as it is used exactly once, in the `project()` call to read the options, and we can just calculate it there and not store it. Fixes: #11176
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/ast/introspection.py8
-rw-r--r--mesonbuild/backend/xcodebackend.py1
-rw-r--r--mesonbuild/interpreter/interpreter.py28
-rw-r--r--mesonbuild/mintro.py8
4 files changed, 32 insertions, 13 deletions
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py
index 98f03fd..e811f11 100644
--- a/mesonbuild/ast/introspection.py
+++ b/mesonbuild/ast/introspection.py
@@ -76,7 +76,6 @@ class IntrospectionInterpreter(AstInterpreter):
self.environment = env
self.subproject_dir = subproject_dir
self.coredata = self.environment.get_coredata()
- self.option_file = os.path.join(self.source_root, self.subdir, 'meson_options.txt')
self.backend = backend
self.default_options = {OptionKey('backend'): self.backend}
self.project_data = {} # type: T.Dict[str, T.Any]
@@ -113,9 +112,12 @@ class IntrospectionInterpreter(AstInterpreter):
proj_vers = 'undefined'
self.project_data = {'descriptive_name': proj_name, 'version': proj_vers}
- if os.path.exists(self.option_file):
+ optfile = os.path.join(self.source_root, self.subdir, 'meson.options')
+ if not os.path.exists(optfile):
+ optfile = os.path.join(self.source_root, self.subdir, 'meson_options.txt')
+ if os.path.exists(optfile):
oi = optinterpreter.OptionInterpreter(self.subproject)
- oi.process(self.option_file)
+ oi.process(optfile)
self.coredata.update_project_options(oi.options)
def_opts = self.flatten_args(kwargs.get('default_options', []))
diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py
index e4195e2..b5cf83a 100644
--- a/mesonbuild/backend/xcodebackend.py
+++ b/mesonbuild/backend/xcodebackend.py
@@ -1025,6 +1025,7 @@ class XCodeBackend(backends.Backend):
group_id = self.write_group_target_entry(objects_dict, target)
children_array.add_item(group_id)
potentials = [os.path.join(current_subdir, 'meson.build'),
+ os.path.join(current_subdir, 'meson.options'),
os.path.join(current_subdir, 'meson_options.txt')]
for bf in potentials:
i = self.fileref_ids.get(bf, None)
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index a033c4f..72bc8e2 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -23,8 +23,9 @@ from .. import compilers
from .. import envconfig
from ..wrap import wrap, WrapMode
from .. import mesonlib
-from ..mesonlib import (MesonBugException, HoldableObject, FileMode, MachineChoice, OptionKey,
- listify, extract_as_list, has_path_sep, PerMachine)
+from ..mesonlib import (MesonBugException, MesonException, HoldableObject,
+ FileMode, MachineChoice, OptionKey, listify,
+ extract_as_list, has_path_sep, PerMachine)
from ..programs import ExternalProgram, NonExistingExternalProgram
from ..dependencies import Dependency
from ..depfile import DepFile
@@ -290,7 +291,6 @@ class Interpreter(InterpreterBase, HoldableObject):
# be different for dependencies provided by wrap files.
self.subproject_directory_name = subdir.split(os.path.sep)[-1]
self.subproject_dir = subproject_dir
- self.option_file = os.path.join(self.source_root, self.subdir, 'meson_options.txt')
self.relaxations = relaxations or set()
if not mock and ast is None:
self.load_root_meson_file()
@@ -1174,11 +1174,27 @@ class Interpreter(InterpreterBase, HoldableObject):
if kwargs['meson_version']:
self.handle_meson_version(kwargs['meson_version'], node)
- if os.path.exists(self.option_file):
+ # Load "meson.options" before "meson_options.txt", and produce a warning if
+ # it is being used with an old version. I have added check that if both
+ # exist the warning isn't raised
+ option_file = os.path.join(self.source_root, self.subdir, 'meson.options')
+ old_option_file = os.path.join(self.source_root, self.subdir, 'meson_options.txt')
+
+ if os.path.exists(option_file):
+ if os.path.exists(old_option_file):
+ if os.path.samefile(option_file, old_option_file):
+ mlog.debug("Not warning about meson.options with version minimum < 1.1 because meson_options.txt also exists")
+ else:
+ raise MesonException("meson.options and meson_options.txt both exist, but are not the same file.")
+ else:
+ FeatureNew.single_use('meson.options file', '1.1', self.subproject, 'Use meson_options.txt instead')
+ else:
+ option_file = old_option_file
+ if os.path.exists(option_file):
oi = optinterpreter.OptionInterpreter(self.subproject)
- oi.process(self.option_file)
+ oi.process(option_file)
self.coredata.update_project_options(oi.options)
- self.add_build_def_file(self.option_file)
+ self.add_build_def_file(option_file)
# Do not set default_options on reconfigure otherwise it would override
# values previously set from command line. That means that changing
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index 68820d6..1842313 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -329,12 +329,12 @@ def list_buildoptions(coredata: cdata.CoreData, subprojects: T.Optional[T.List[s
return optlist
def find_buildsystem_files_list(src_dir: str) -> T.List[str]:
+ build_files = frozenset({'meson.build', 'meson.options', 'meson_options.txt'})
# I feel dirty about this. But only slightly.
- filelist = [] # type: T.List[str]
+ filelist: T.List[str] = []
for root, _, files in os.walk(src_dir):
- for f in files:
- if f in {'meson.build', 'meson_options.txt'}:
- filelist.append(os.path.relpath(os.path.join(root, f), src_dir))
+ filelist.extend(os.path.relpath(os.path.join(root, f), src_dir)
+ for f in build_files.intersection(files))
return filelist
def list_buildsystem_files(builddata: build.Build, interpreter: Interpreter) -> T.List[str]: