mesonmain: Add --reconfigure argument

Allows to manually reconfigure a project the same way backends would do
(e.g. ninja reconfigure). This has the advantage that new options can be
set using "meson --reconfigure -Dfoo=bar" and solve situations where a
project cannot be reconfigured because new options has been added with
the wrong default value.

Fixes #3543.
pull/4077/head
Xavier Claessens 7 years ago
parent 8de60f9078
commit 674ae466c8
  1. 40
      mesonbuild/mesonmain.py

@ -43,6 +43,10 @@ def create_parser():
help=argparse.SUPPRESS) help=argparse.SUPPRESS)
p.add_argument('--fatal-meson-warnings', action='store_true', dest='fatal_warnings', p.add_argument('--fatal-meson-warnings', action='store_true', dest='fatal_warnings',
help='Make all Meson warnings fatal') help='Make all Meson warnings fatal')
p.add_argument('--reconfigure', action='store_true',
help='Set options and reconfigure the project. Useful when new ' +
'options have been added to the project and the default value ' +
'is not working.')
p.add_argument('builddir', nargs='?', default=None) p.add_argument('builddir', nargs='?', default=None)
p.add_argument('sourcedir', nargs='?', default=None) p.add_argument('sourcedir', nargs='?', default=None)
return p return p
@ -57,10 +61,10 @@ def wrapmodetype(string):
class MesonApp: class MesonApp:
def __init__(self, handshake, options): def __init__(self, options):
(self.source_dir, self.build_dir) = self.validate_dirs(options.builddir, (self.source_dir, self.build_dir) = self.validate_dirs(options.builddir,
options.sourcedir, options.sourcedir,
handshake) options.reconfigure)
self.options = options self.options = options
def has_build_file(self, dirname): def has_build_file(self, dirname):
@ -97,21 +101,23 @@ class MesonApp:
return ndir2, ndir1 return ndir2, ndir1
raise MesonException('Neither directory contains a build file %s.' % environment.build_filename) raise MesonException('Neither directory contains a build file %s.' % environment.build_filename)
def validate_dirs(self, dir1, dir2, handshake): def validate_dirs(self, dir1, dir2, reconfigure):
(src_dir, build_dir) = self.validate_core_dirs(dir1, dir2) (src_dir, build_dir) = self.validate_core_dirs(dir1, dir2)
priv_dir = os.path.join(build_dir, 'meson-private/coredata.dat') priv_dir = os.path.join(build_dir, 'meson-private/coredata.dat')
if os.path.exists(priv_dir): if os.path.exists(priv_dir):
if not handshake: if not reconfigure:
print('Directory already configured, exiting Meson. Just run your build command\n' print('Directory already configured.\n'
'(e.g. ninja) and Meson will regenerate as necessary. If ninja fails, run ninja\n' '\nJust run your build command (e.g. ninja) and Meson will regenerate as necessary.\n'
'reconfigure to force Meson to regenerate.\n' 'If ninja fails, run "ninja reconfigure" or "meson --reconfigure"\n'
'to force Meson to regenerate.\n'
'\nIf build failures persist, manually wipe your build directory to clear any\n' '\nIf build failures persist, manually wipe your build directory to clear any\n'
'stored system data.\n' 'stored system data.\n'
'\nTo change option values, run meson configure instead.') '\nTo change option values, run "meson configure" instead.')
sys.exit(0) sys.exit(1)
else: else:
if handshake: if reconfigure:
raise RuntimeError('Something went terribly wrong. Please file a bug.') print('Directory does not contain a valid build tree:\n{}'.format(build_dir))
sys.exit(1)
return src_dir, build_dir return src_dir, build_dir
def check_pkgconfig_envvar(self, env): def check_pkgconfig_envvar(self, env):
@ -328,7 +334,11 @@ def run(original_args, mainfile):
# No special command? Do the basic setup/reconf. # No special command? Do the basic setup/reconf.
if len(args) >= 2 and args[0] == '--internal': if len(args) >= 2 and args[0] == '--internal':
if args[1] != 'regenerate': if args[1] == 'regenerate':
# Rewrite "meson --internal regenerate" command line to
# "meson --reconfigure"
args = ['--reconfigure'] + args[2:]
else:
script = args[1] script = args[1]
try: try:
sys.exit(run_script_command(args[1:])) sys.exit(run_script_command(args[1:]))
@ -336,10 +346,6 @@ def run(original_args, mainfile):
mlog.error('\nError in {} helper script:'.format(script)) mlog.error('\nError in {} helper script:'.format(script))
mlog.exception(e) mlog.exception(e)
sys.exit(1) sys.exit(1)
args = args[2:]
handshake = True
else:
handshake = False
parser = create_parser() parser = create_parser()
@ -347,7 +353,7 @@ def run(original_args, mainfile):
options = parser.parse_args(args) options = parser.parse_args(args)
coredata.parse_cmd_line_options(options) coredata.parse_cmd_line_options(options)
try: try:
app = MesonApp(handshake, options) app = MesonApp(options)
except Exception as e: except Exception as e:
# Log directory does not exist, so just print # Log directory does not exist, so just print
# to stdout. # to stdout.

Loading…
Cancel
Save