2 # Copyright © 2019 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 """This script reads a meson build directory and gives back the command line it
25 This only works for meson 0.49.0 and newer.
35 def parse_args() -> argparse
.Namespace
:
36 """Parse arguments."""
37 parser
= argparse
.ArgumentParser()
40 help='Path the meson build directory')
41 args
= parser
.parse_args()
45 def load_config(path
: pathlib
.Path
) -> configparser
.ConfigParser
:
46 """Load config file."""
47 conf
= configparser
.ConfigParser()
48 with path
.open() as f
:
53 def build_cmd(conf
: configparser
.ConfigParser
) -> str:
54 """Rebuild the command line."""
56 for k
, v
in conf
['options'].items():
58 args
.append(f
'-D{k}="{v}"')
60 args
.append(f
'-D{k}={v}')
62 cf
= conf
['properties'].get('cross_file')
64 args
.append('--cross-file={}'.format(cf
))
65 nf
= conf
['properties'].get('native_file')
67 # this will be in the form "['str', 'str']", so use ast.literal_eval to
68 # convert it to a list of strings.
69 nf
= ast
.literal_eval(nf
)
70 args
.extend(['--native-file={}'.format(f
) for f
in nf
])
76 path
= pathlib
.Path(args
.build_dir
, 'meson-private', 'cmd_line.txt')
78 print('Cannot find the necessary file to rebuild command line. '
79 'Is your meson version >= 0.49.0?', file=sys
.stderr
)
82 conf
= load_config(path
)
87 if __name__
== '__main__':