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 <jordan.l.justen@intel.com> Acked-by: Eric Engestrom <eric@engestrom.ch> Acked-by: Tapani Pälli <tapani.palli@intel.com>
This commit is contained in:
parent
7bef192018
commit
4a131a1330
|
@ -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()
|
Loading…
Reference in New Issue