aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2019-02-12 20:00:34 +0200
committerGitHub <noreply@github.com>2019-02-12 20:00:34 +0200
commita32f31fdfaa2cfd3d6578742fba43bfa66049bf1 (patch)
treeb2519269fab446e06278b7b5276428ac8c949e68
parent627d0d1f3e0ece4a8d4dae1f66cc44b40439b171 (diff)
parent71d174bcbe7ef6d319ee0afd1794073354e1bd35 (diff)
downloadmeson-a32f31fdfaa2cfd3d6578742fba43bfa66049bf1.zip
meson-a32f31fdfaa2cfd3d6578742fba43bfa66049bf1.tar.gz
meson-a32f31fdfaa2cfd3d6578742fba43bfa66049bf1.tar.bz2
Merge pull request #4826 from mensinda/confDefOpts
mconf: Use introspection to print the project default options (fixes #2543)
-rw-r--r--docs/markdown/Configuring-a-build-directory.md5
-rw-r--r--docs/markdown/snippets/configure_default_opts.md6
-rw-r--r--mesonbuild/mconf.py59
-rw-r--r--mesonbuild/mintro.py2
4 files changed, 60 insertions, 12 deletions
diff --git a/docs/markdown/Configuring-a-build-directory.md b/docs/markdown/Configuring-a-build-directory.md
index 0c7487f..91ad6f7 100644
--- a/docs/markdown/Configuring-a-build-directory.md
+++ b/docs/markdown/Configuring-a-build-directory.md
@@ -111,3 +111,8 @@ you would issue the following command.
Then you would run your build command (usually `ninja`), which would
cause Meson to detect that the build setup has changed and do all the
work required to bring your build tree up to date.
+
+Since 0.50.0, it is also possible to get a list of all build options
+by invoking `meson configure` with the project source directory or
+the path to the root `meson.build`. In this case, meson will print the
+default values of all options similar to the example output from above.
diff --git a/docs/markdown/snippets/configure_default_opts.md b/docs/markdown/snippets/configure_default_opts.md
new file mode 100644
index 0000000..4b88bdf
--- /dev/null
+++ b/docs/markdown/snippets/configure_default_opts.md
@@ -0,0 +1,6 @@
+## meson configure can now print the default options of an unconfigured project
+
+With this release, it is also possible to get a list of all build options
+by invoking `meson configure` with the project source directory or
+the path to the root `meson.build`. In this case, meson will print the
+default values of all options.
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py
index 48f88e8..fbb528c 100644
--- a/mesonbuild/mconf.py
+++ b/mesonbuild/mconf.py
@@ -13,8 +13,7 @@
# limitations under the License.
import os
-from . import (coredata, mesonlib, build)
-from . import mintro
+from . import coredata, environment, mesonlib, build, mintro, mlog
def add_arguments(parser):
coredata.register_builtin_arguments(parser)
@@ -38,11 +37,28 @@ class ConfException(mesonlib.MesonException):
class Conf:
def __init__(self, build_dir):
- self.build_dir = build_dir
- if not os.path.isdir(os.path.join(build_dir, 'meson-private')):
- raise ConfException('Directory %s does not seem to be a Meson build directory.' % build_dir)
- self.build = build.load(self.build_dir)
- self.coredata = coredata.load(self.build_dir)
+ self.build_dir = os.path.abspath(os.path.realpath(build_dir))
+ if 'meson.build' in [os.path.basename(self.build_dir), self.build_dir]:
+ self.build_dir = os.path.dirname(self.build_dir)
+ self.build = None
+
+ 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()
+ self.coredata = coredata.load(self.build_dir)
+ self.default_values_only = False
+ 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
+ mlog.disable()
+ self.source_dir = os.path.abspath(os.path.realpath(self.build_dir))
+ intr = mintro.IntrospectionInterpreter(self.source_dir, '', 'ninja')
+ intr.analyze()
+ # Reenable logging just in case
+ mlog.enable()
+ self.coredata = intr.coredata
+ self.default_values_only = True
+ else:
+ raise ConfException('Directory {} is neither a Meson build directory nor a project source directory.'.format(build_dir))
def clear_cache(self):
self.coredata.deps = {}
@@ -51,18 +67,22 @@ class Conf:
self.coredata.set_options(options)
def save(self):
+ # Do nothing when using introspection
+ if self.default_values_only:
+ return
# Only called if something has changed so overwrite unconditionally.
coredata.save(self.coredata, self.build_dir)
# We don't write the build file because any changes to it
# are erased when Meson is executed the next time, i.e. when
# Ninja is run.
- @staticmethod
- def print_aligned(arr):
+ def print_aligned(self, arr):
if not arr:
return
titles = {'name': 'Option', 'descr': 'Description', 'value': 'Current Value', 'choices': 'Possible Values'}
+ if self.default_values_only:
+ titles['value'] = 'Default Value'
name_col = [titles['name'], '-' * len(titles['name'])]
value_col = [titles['value'], '-' * len(titles['value'])]
@@ -111,9 +131,18 @@ class Conf:
self.print_aligned(arr)
def print_conf(self):
+ def print_default_values_warning():
+ mlog.warning('The source directory instead of the build directory was specified.')
+ mlog.warning('Only the default values for the project are printed, and all command line parameters are ignored.')
+
+ if self.default_values_only:
+ print_default_values_warning()
+ print('')
+
print('Core properties:')
- print(' Source dir', self.build.environment.source_dir)
- print(' Build dir ', self.build.environment.build_dir)
+ print(' Source dir', self.source_dir)
+ if not self.default_values_only:
+ print(' Build dir ', self.build_dir)
dir_option_names = ['bindir',
'datadir',
@@ -145,6 +174,10 @@ class Conf:
self.print_options('Project options', self.coredata.user_options)
self.print_options('Testing options', test_options)
+ # Print the warning twice so that the user shouldn't be able to miss it
+ if self.default_values_only:
+ print('')
+ print_default_values_warning()
def run(options):
coredata.parse_cmd_line_options(options)
@@ -152,6 +185,10 @@ def run(options):
c = None
try:
c = Conf(builddir)
+ if c.default_values_only:
+ c.print_conf()
+ return 0
+
save = False
if len(options.cmd_line_options) > 0:
c.set_options(options.cmd_line_options)
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index 5eecb67..2d01c11 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -321,7 +321,7 @@ def run(options):
if options.builddir is not None:
datadir = os.path.join(options.builddir, datadir)
infodir = os.path.join(options.builddir, infodir)
- if options.builddir.endswith('/meson.build') or options.builddir.endswith('\\meson.build') or options.builddir == 'meson.build':
+ if 'meson.build' in [os.path.basename(options.builddir), options.builddir]:
sourcedir = '.' if options.builddir == 'meson.build' else options.builddir[:-11]
if options.projectinfo:
list_projinfo_from_source(sourcedir, indent)