]> git.proxmox.com Git - mirror_qemu.git/blame - tests/docker/travis.py
python: futurize -f libfuturize.fixes.fix_print_with_import
[mirror_qemu.git] / tests / docker / travis.py
CommitLineData
d5bd7891
FZ
1#!/usr/bin/env python
2#
3# Travis YAML config parser
4#
5# Copyright (c) 2016 Red Hat Inc.
6#
7# Authors:
8# Fam Zheng <famz@redhat.com>
9#
10# This work is licensed under the terms of the GNU GPL, version 2
11# or (at your option) any later version. See the COPYING file in
12# the top-level directory.
13
f03868bd 14from __future__ import print_function
d5bd7891
FZ
15import sys
16import yaml
17import itertools
18
19def load_yaml(fname):
20 return yaml.load(open(fname, "r").read())
21
22def conf_iter(conf):
23 def env_to_list(env):
24 return env if isinstance(env, list) else [env]
d5bd7891 25 for entry in conf["matrix"]["include"]:
6ca9f7fe 26 yield {"env": env_to_list(entry["env"]),
d5bd7891
FZ
27 "compiler": entry["compiler"]}
28 for entry in itertools.product(conf["compiler"],
29 conf["env"]["matrix"]):
6ca9f7fe 30 yield {"env": env_to_list(entry[1]),
d5bd7891
FZ
31 "compiler": entry[0]}
32
33def main():
34 if len(sys.argv) < 2:
35 sys.stderr.write("Usage: %s <travis-file>\n" % sys.argv[0])
36 return 1
37 conf = load_yaml(sys.argv[1])
f03868bd 38 print("\n".join((": ${%s}" % var for var in conf["env"]["global"])))
d5bd7891 39 for config in conf_iter(conf):
f03868bd
EH
40 print("(")
41 print("\n".join(config["env"]))
42 print("alias cc=" + config["compiler"])
43 print("\n".join(conf["before_script"]))
44 print("\n".join(conf["script"]))
45 print(")")
d5bd7891
FZ
46 return 0
47
48if __name__ == "__main__":
49 sys.exit(main())