]> git.proxmox.com Git - mirror_qemu.git/blame - tests/docker/travis.py
docker: Fix travis.py parser and misc change
[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):
e8ced681 20 return yaml.safe_load(open(fname, "r").read())
d5bd7891
FZ
21
22def conf_iter(conf):
e8ced681
WSM
23 # If "compiler" is omitted from the included env then Travis picks the
24 # first entry of the global compiler list.
25 default_compiler = conf["compiler"][0]
d5bd7891
FZ
26 def env_to_list(env):
27 return env if isinstance(env, list) else [env]
d5bd7891 28 for entry in conf["matrix"]["include"]:
6ca9f7fe 29 yield {"env": env_to_list(entry["env"]),
e8ced681 30 "compiler": entry.get("compiler", default_compiler)}
d5bd7891
FZ
31
32def main():
33 if len(sys.argv) < 2:
34 sys.stderr.write("Usage: %s <travis-file>\n" % sys.argv[0])
35 return 1
36 conf = load_yaml(sys.argv[1])
f03868bd 37 print("\n".join((": ${%s}" % var for var in conf["env"]["global"])))
d5bd7891 38 for config in conf_iter(conf):
f03868bd
EH
39 print("(")
40 print("\n".join(config["env"]))
41 print("alias cc=" + config["compiler"])
42 print("\n".join(conf["before_script"]))
43 print("\n".join(conf["script"]))
44 print(")")
d5bd7891
FZ
45 return 0
46
47if __name__ == "__main__":
48 sys.exit(main())