aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2023-03-30 09:29:27 -0400
committerXavier Claessens <xclaesse@gmail.com>2023-08-25 09:43:24 -0400
commite3a71a7b58ac559f8669ca6fa95617a537b47f98 (patch)
treeb75a9a8c65ea3196bd743bb85b7d1a879c3d0c6a /mesonbuild
parent1bb29b1b329ec056c61a54070024b6b003cf5ca4 (diff)
downloadmeson-e3a71a7b58ac559f8669ca6fa95617a537b47f98.zip
meson-e3a71a7b58ac559f8669ca6fa95617a537b47f98.tar.gz
meson-e3a71a7b58ac559f8669ca6fa95617a537b47f98.tar.bz2
msetup: Update options when builddir is already configured
`meson setup -Dfoo=bar builddir` command was returning success ignoring new option values. This now also update options. It is useful because it means `meson setup -Dfoo=bar builddir && ninja -C builddir` works regardless whether builddir already exists or not, and when done in a script, changing options in the script will automatically trigger a reconfigure if needed. This was already possible by always passing --reconfigure argument, but that triggers a reconfigure even when options did not change.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/mconf.py9
-rw-r--r--mesonbuild/msetup.py34
2 files changed, 21 insertions, 22 deletions
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py
index d4ecce8..9f6c685 100644
--- a/mesonbuild/mconf.py
+++ b/mesonbuild/mconf.py
@@ -301,9 +301,7 @@ class Conf:
for m in mismatching:
mlog.log(f'{m[0]:21}{m[1]:10}{m[2]:10}')
-def run(options: argparse.Namespace) -> int:
- coredata.parse_cmd_line_options(options)
- builddir = os.path.abspath(os.path.realpath(options.builddir))
+def run_impl(options: argparse.Namespace, builddir: str) -> int:
print_only = not options.cmd_line_options and not options.clearcache
c = None
try:
@@ -334,3 +332,8 @@ def run(options: argparse.Namespace) -> int:
# Pager quit before we wrote everything.
pass
return 0
+
+def run(options: argparse.Namespace) -> int:
+ coredata.parse_cmd_line_options(options)
+ builddir = os.path.abspath(os.path.realpath(options.builddir))
+ return run_impl(options, builddir)
diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py
index 73c9fb3..4ff6000 100644
--- a/mesonbuild/msetup.py
+++ b/mesonbuild/msetup.py
@@ -55,15 +55,15 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
help='Wipe build directory and reconfigure using previous command line options. ' +
'Useful when build directory got corrupted, or when rebuilding with a ' +
'newer version of meson.')
+ parser.add_argument('--clearcache', action='store_true', default=False,
+ help='Clear cached state (e.g. found dependencies). Since 1.3.0.')
parser.add_argument('builddir', nargs='?', default=None)
parser.add_argument('sourcedir', nargs='?', default=None)
class MesonApp:
def __init__(self, options: argparse.Namespace) -> None:
- (self.source_dir, self.build_dir) = self.validate_dirs(options.builddir,
- options.sourcedir,
- options.reconfigure,
- options.wipe)
+ self.options = options
+ (self.source_dir, self.build_dir) = self.validate_dirs()
if options.wipe:
# Make a copy of the cmd line file to make sure we can always
# restore that file if anything bad happens. For example if
@@ -96,8 +96,6 @@ class MesonApp:
os.makedirs(os.path.dirname(f), exist_ok=True)
shutil.move(b, f)
- self.options = options
-
def has_build_file(self, dirname: str) -> bool:
fname = os.path.join(dirname, environment.build_filename)
return os.path.exists(fname)
@@ -144,8 +142,8 @@ class MesonApp:
with open(os.path.join(build_dir, '.hgignore'), 'w', encoding='utf-8') as ofile:
ofile.write(hg_ignore_file)
- def validate_dirs(self, dir1: T.Optional[str], dir2: T.Optional[str], reconfigure: bool, wipe: bool) -> T.Tuple[str, str]:
- (src_dir, build_dir) = self.validate_core_dirs(dir1, dir2)
+ def validate_dirs(self) -> T.Tuple[str, str]:
+ (src_dir, build_dir) = self.validate_core_dirs(self.options.builddir, self.options.sourcedir)
if Path(build_dir) in Path(src_dir).parents:
raise MesonException(f'Build directory {build_dir} cannot be a parent of source directory {src_dir}')
if not os.listdir(build_dir):
@@ -155,21 +153,17 @@ class MesonApp:
has_valid_build = os.path.exists(os.path.join(priv_dir, 'coredata.dat'))
has_partial_build = os.path.isdir(priv_dir)
if has_valid_build:
- if not reconfigure and not wipe:
+ if not self.options.reconfigure and not self.options.wipe:
print('Directory already configured.\n\n'
'Just run your build command (e.g. ninja) and Meson will regenerate as necessary.\n'
- 'If ninja fails, run "ninja reconfigure" or "meson setup --reconfigure"\n'
- 'to force Meson to regenerate.\n\n'
+ 'Run "meson setup --reconfigure to force Meson to regenerate.\n\n'
'If build failures persist, run "meson setup --wipe" to rebuild from scratch\n'
- 'using the same options as passed when configuring the build.\n'
- 'To change option values, run "meson configure" instead.')
- # FIXME: This returns success and ignores new option values from CLI.
- # We should either make this a hard error, or update options and
- # return success.
- # Note that making this an error would not be backward compatible (and also isn't
- # universally agreed on): https://github.com/mesonbuild/meson/pull/4249.
+ 'using the same options as passed when configuring the build.')
+ if self.options.cmd_line_options:
+ from . import mconf
+ raise SystemExit(mconf.run_impl(self.options, build_dir))
raise SystemExit(0)
- elif not has_partial_build and wipe:
+ elif not has_partial_build and self.options.wipe:
raise MesonException(f'Directory is not empty and does not contain a previous build:\n{build_dir}')
return src_dir, build_dir
@@ -179,6 +173,8 @@ class MesonApp:
mlog.initialize(env.get_log_dir(), self.options.fatal_warnings)
if self.options.profile:
mlog.set_timestamp_start(time.monotonic())
+ if self.options.clearcache:
+ env.coredata.clear_cache()
with mesonlib.BuildDirLock(self.build_dir):
return self._generate(env, capture, vslite_ctx)