summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorDylan Baker <[email protected]>2019-01-11 15:36:05 -0800
committerDylan Baker <[email protected]>2019-01-15 17:38:47 +0000
commit4a131a13303773d8b0e4d47e917b9c52d439146a (patch)
tree112d56fc02f4f502856d40ac00e5bf9f3a44bda4 /bin
parent7bef19201822ab2aebfd244142ff3a23535019a7 (diff)
meson: Add a script to extract the cmd line used for meson
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 <[email protected]> Acked-by: Eric Engestrom <[email protected]> Acked-by: Tapani Pälli <[email protected]>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/meson-cmd-extract.py77
1 files changed, 77 insertions, 0 deletions
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()