diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2019-06-23 07:53:17 -0700 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-06-23 17:53:17 +0300 |
commit | 56f7e5c74f54d31b405fe1c4289a406ef826b757 (patch) | |
tree | 2ebe24ae3ca1c62d3d3ebc6275a67a89d2bd34fa /mesonbuild/msetup.py | |
parent | d61116efc116845d32cd56b82089addd6b9327cc (diff) | |
download | meson-56f7e5c74f54d31b405fe1c4289a406ef826b757.zip meson-56f7e5c74f54d31b405fe1c4289a406ef826b757.tar.gz meson-56f7e5c74f54d31b405fe1c4289a406ef826b757.tar.bz2 |
coredata: Correctly handle receiving a pipe for native/cross files
* coredata: Correctly handle receiving a pipe for native/cross files
In some cases a cross/native file may be a pipe, such as when using bash
process replacement `meson --native-file
<([binaries]llvm-config='/opt/bin/llvm-config')`, for example. In this
case we copy the contents of the pipe into a file in the meson-private
directory so we can create a proper ninja dependency, and be able to
reload the file on --wipe/--reconfigure. This requires some extra
negotiation to preserve these native/cross files.
Fixes #5505
* run_unitests: Add a unit test for native files that are pipes
Using mkfifo.
Diffstat (limited to 'mesonbuild/msetup.py')
-rw-r--r-- | mesonbuild/msetup.py | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py index 84bcefb..5670b25 100644 --- a/mesonbuild/msetup.py +++ b/mesonbuild/msetup.py @@ -19,6 +19,9 @@ import os.path import platform import cProfile as profile import argparse +import tempfile +import shutil +import glob from . import environment, interpreter, mesonlib from . import build @@ -60,38 +63,36 @@ class MesonApp: options.sourcedir, options.reconfigure, options.wipe) - 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 # configuration fails we need to be able to wipe again. - filename = coredata.get_cmd_line_file(self.build_dir) - try: - with open(filename, 'r') as f: - content = f.read() - except FileNotFoundError: - raise MesonException( - 'Cannot find cmd_line.txt. This is probably because this ' - 'build directory was configured with a meson version < 0.49.0.') - - coredata.read_cmd_line_file(self.build_dir, options) - - try: - # Don't delete the whole tree, just all of the files and - # folders in the tree. Otherwise calling wipe form the builddir - # will cause a crash - for l in os.listdir(self.build_dir): - l = os.path.join(self.build_dir, l) - if os.path.isdir(l): - mesonlib.windows_proof_rmtree(l) - else: - mesonlib.windows_proof_rm(l) - finally: - # Restore the file - path = os.path.dirname(filename) - os.makedirs(path, exist_ok=True) - with open(filename, 'w') as f: - f.write(content) + restore = [] + with tempfile.TemporaryDirectory() as d: + for filename in [coredata.get_cmd_line_file(self.build_dir)] + glob.glob(os.path.join(self.build_dir, environment.Environment.private_dir, '*.ini')): + try: + restore.append((shutil.copy(filename, d), filename)) + except FileNotFoundError: + raise MesonException( + 'Cannot find cmd_line.txt. This is probably because this ' + 'build directory was configured with a meson version < 0.49.0.') + + coredata.read_cmd_line_file(self.build_dir, options) + + try: + # Don't delete the whole tree, just all of the files and + # folders in the tree. Otherwise calling wipe form the builddir + # will cause a crash + for l in os.listdir(self.build_dir): + l = os.path.join(self.build_dir, l) + if os.path.isdir(l): + mesonlib.windows_proof_rmtree(l) + else: + mesonlib.windows_proof_rm(l) + finally: + for b, f in restore: + os.makedirs(os.path.dirname(f), exist_ok=True) + shutil.move(b, f) self.options = options |