From 4a131a13303773d8b0e4d47e917b9c52d439146a Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 11 Jan 2019 15:36:05 -0800 Subject: [PATCH] meson: Add a script to extract the cmd line used for meson MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Upstream I'm persuing a more comprehensive solution, but this should prove a suitable stop-gap measure in the meantime. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=109325 Reviewed-by: Jordan Justen Acked-by: Eric Engestrom Acked-by: Tapani Pälli --- bin/meson-cmd-extract.py | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 bin/meson-cmd-extract.py diff --git a/bin/meson-cmd-extract.py b/bin/meson-cmd-extract.py new file mode 100755 index 00000000000..61d6b406fbb --- /dev/null +++ b/bin/meson-cmd-extract.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +# Copyright © 2019 Intel Corporation + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +"""This script reads a meson build directory and gives back the command line it +was configured with. + +This only works for meson 0.49.0 and newer. +""" + +import argparse +import configparser +import pathlib +import sys + + +def parse_args() -> argparse.Namespace: + """Parse arguments.""" + parser = argparse.ArgumentParser() + parser.add_argument( + 'build_dir', + help='Path the meson build directory') + args = parser.parse_args() + return args + + +def load_config(path: pathlib.Path) -> configparser.ConfigParser: + """Load config file.""" + conf = configparser.ConfigParser() + with path.open() as f: + conf.read_file(f) + return conf + + +def build_cmd(conf: configparser.ConfigParser) -> str: + """Rebuild the command line.""" + args = [] + for k, v in conf['options'].items(): + if ' ' in v: + args.append(f'-D{k}="{v}"') + else: + args.append(f'-D{k}={v}') + return ' '.join(args) + + +def main(): + args = parse_args() + path = pathlib.Path(args.build_dir, 'meson-private', 'cmd_line.txt') + if not path.exists(): + print('Cannot find the necessary file to rebuild command line. ' + 'Is your meson version >= 0.49.0?', file=sys.stderr) + sys.exit(1) + + conf = load_config(path) + cmd = build_cmd(conf) + print(cmd) + + +if __name__ == '__main__': + main() -- 2.30.2