|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import glob as py_glob |
| 3 | +import os |
| 4 | +import subprocess |
| 5 | +import sys |
| 6 | +from typing import Optional |
| 7 | + |
| 8 | +LIBS = {} |
| 9 | + |
| 10 | + |
| 11 | +def load(bzl: str, *syms: str) -> None: |
| 12 | + pass |
| 13 | + |
| 14 | + |
| 15 | +def exports_files(srcs: list[str], |
| 16 | + visibility: Optional[list[str]] = None) -> None: |
| 17 | + pass |
| 18 | + |
| 19 | + |
| 20 | +def cc_library(name: str, **kwargs: list[str]) -> None: |
| 21 | + LIBS[name] = kwargs |
| 22 | + |
| 23 | + |
| 24 | +def cc_test(name: str, **kwargs: list[str]) -> None: |
| 25 | + pass |
| 26 | + |
| 27 | + |
| 28 | +def cc_fuzz_test(name: str, **kwargs: list[str]) -> None: |
| 29 | + pass |
| 30 | + |
| 31 | + |
| 32 | +def select(selector: dict[str, list[str]]) -> list[str]: |
| 33 | + return selector["//tools/config:linux"] |
| 34 | + |
| 35 | + |
| 36 | +def glob(include: list[str]) -> list[str]: |
| 37 | + return [ |
| 38 | + f[len("toxcore/"):] for p in include |
| 39 | + for f in py_glob.glob(os.path.join("toxcore", p)) |
| 40 | + ] |
| 41 | + |
| 42 | + |
| 43 | +def alias(name: str, actual: str, visibility: list[str]) -> None: |
| 44 | + pass |
| 45 | + |
| 46 | + |
| 47 | +def sh_library(name: str, **kwargs: list[str]) -> None: |
| 48 | + pass |
| 49 | + |
| 50 | + |
| 51 | +def main() -> None: |
| 52 | + with open("toxcore/BUILD.bazel", "r") as fh: |
| 53 | + exec(fh.read()) |
| 54 | + |
| 55 | + with open("module.modulemap", "w") as fh: |
| 56 | + for name, lib in LIBS.items(): |
| 57 | + fh.write("module " + name + " {\n") |
| 58 | + for hdr in lib["hdrs"]: |
| 59 | + fh.write(f' header "toxcore/{hdr}"\n') |
| 60 | + for dep in lib.get("deps", []): |
| 61 | + if dep[0] == ":": |
| 62 | + fh.write(f" use {dep[1:]}\n") |
| 63 | + fh.write("}\n") |
| 64 | + |
| 65 | + srcs = sorted( |
| 66 | + set( |
| 67 | + os.path.join("toxcore", src) for lib in LIBS.values() |
| 68 | + for src in lib.get("srcs", []))) |
| 69 | + for src in srcs: |
| 70 | + print(f"Validating {src}", file=sys.stderr) |
| 71 | + subprocess.run( |
| 72 | + [ |
| 73 | + "clang", |
| 74 | + "-xc++", |
| 75 | + "-fsyntax-only", |
| 76 | + "-Wall", |
| 77 | + "-Werror", |
| 78 | + "-Wno-missing-braces", |
| 79 | + "-std=c++23", |
| 80 | + "-fdiagnostics-color=always", |
| 81 | + "-fmodules", |
| 82 | + # TODO(iphydf): Fix all the other errors. |
| 83 | + # "-fmodules-strict-decluse", |
| 84 | + "-fmodules-decluse", |
| 85 | + "-fmodule-map-file=module.modulemap", |
| 86 | + src, |
| 87 | + ], |
| 88 | + check=True, |
| 89 | + ) |
| 90 | + |
| 91 | + |
| 92 | +if __name__ == "__main__": |
| 93 | + main() |
0 commit comments