Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

meson-cmd-extract.py 2.8KB

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