1#!/usr/bin/env python3
2
3import sys, os, subprocess, shutil
4
5"""
6Script to check that Waypipe builds and that tests pass in all of
7its configurations.
8"""
9
10waypipe_root, build_root = sys.argv[1], sys.argv[2]
11os.makedirs(build_root, exist_ok=True)
12
13setups = [
14    ("regular", ["--buildtype", "debugoptimized"], {}),
15    ("release", ["--buildtype", "release"], {}),
16    ("clang", ["--buildtype", "debugoptimized"], {"CC": "clang"}),
17    (
18        "clang-tsan",
19        ["--buildtype", "debugoptimized", "-Db_sanitize=thread"],
20        {"CC": "clang"},
21    ),
22    (
23        "clang-asan",
24        ["--buildtype", "debugoptimized", "-Db_sanitize=address,undefined"],
25        {"CC": "clang"},
26    ),
27    (
28        "empty",
29        [
30            "--buildtype",
31            "debugoptimized",
32            "-Dwith_video=disabled",
33            "-Dwith_lz4=disabled",
34            "-Dwith_zstd=disabled",
35            "-Dwith_dmabuf=disabled",
36        ],
37        {"CC": "gcc"},
38    ),
39    (
40        "novideo",
41        [
42            "--buildtype",
43            "debugoptimized",
44            "-Dwith_video=disabled",
45        ],
46        {"CC": "gcc"},
47    ),
48    (
49        "nolz4",
50        [
51            "--buildtype",
52            "debugoptimized",
53            "-Dwith_lz4=disabled",
54        ],
55        {"CC": "gcc"},
56    ),
57    (
58        "unity",
59        ["--buildtype", "debugoptimized", "--unity", "on", "--unity-size", "400"],
60        {"CC": "gcc", "CFLAGS": "-pedantic -D_GNU_SOURCE"},
61    ),
62    (
63        "error",
64        ["--buildtype", "debugoptimized"],
65        {"CC": "gcc", "CFLAGS": "-Wunused-result -std=c11 -pedantic -ggdb3 -O1"},
66    ),
67]
68main_options = ["video", "dmabuf", "lz4", "zstd", "vaapi"]
69bool_map = {True: "enabled", False: "disabled"}
70for compiler in ["gcc", "clang"]:
71    for flags in range(2 ** len(main_options)):
72        bool_options = [(2 ** i) & flags != 0 for i in range(len(main_options))]
73        name = "-".join(
74            ["poly", compiler] + [m for m, b in zip(main_options, bool_options) if b]
75        )
76        flag_values = [
77            "-Dwith_{}={}".format(m, bool_map[b])
78            for m, b in zip(main_options, bool_options)
79        ]
80        setups.append(
81            (name, ["--buildtype", "debugoptimized"] + flag_values, {"CC": compiler})
82        )
83
84if len(sys.argv) >= 4:
85    setups = [(s, c, e) for s, c, e in setups if s == sys.argv[3]]
86
87base_env = os.environ.copy()
88for key, options, env in setups:
89    print(key, end=" ")
90    sys.stdout.flush()
91    nenv = base_env.copy()
92    for e in env:
93        nenv[e] = env[e]
94
95    bdir = os.path.join(build_root, key)
96    try:
97        shutil.rmtree(bdir)
98    except FileNotFoundError:
99        pass
100    r1 = subprocess.run(
101        ["meson", waypipe_root, bdir] + options, capture_output=True, env=nenv
102    )
103    if r1.returncode:
104        print("failed")
105        print(r1.stdout, r1.stderr, r1.returncode)
106        continue
107    r2 = subprocess.run(["ninja", "test"], cwd=bdir, capture_output=True, env=nenv)
108    if r2.returncode:
109        print("failed")
110        print(r2.stdout, r2.stderr, r2.returncode)
111        continue
112    print("passed")
113