Skip to content

Commit 511bfe3

Browse files
committed
cleanup: Use Bazel modules to enforce proper #include hygiene.
1 parent 1710a0d commit 511bfe3

File tree

128 files changed

+432
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+432
-21
lines changed

.clang-tidy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,5 @@ CheckOptions:
4141
value: true
4242
- key: concurrency-mt-unsafe.FunctionSet
4343
value: posix
44-
- key: misc-include-cleaner.IgnoreHeaders
45-
value: "pthread.h;stdbool.h;stddef.h;stdint.;stdint.h;stdint...;cstdint;sodium.*;sys/.*;unistd.h;opus.*;vpx.*;attributes.h;tox_struct.h"
4644
- key: readability-function-cognitive-complexity.Threshold
4745
value: 153 # TODO(iphydf): Decrease. tox_new is the highest at the moment.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
analysis:
1717
strategy:
1818
matrix:
19-
tool: [autotools, clang-tidy, compcert, cppcheck, doxygen, goblint, infer, misra, rpm, tcc, tokstyle]
19+
tool: [autotools, clang-tidy, compcert, cppcheck, doxygen, goblint, infer, misra, modules, rpm, tcc, tokstyle]
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Set up Docker Buildx

other/analysis/run-clang-tidy

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ CHECKS="$CHECKS,-cert-dcl03-c"
139139
CHECKS="$CHECKS,-hicpp-static-assert"
140140
CHECKS="$CHECKS,-misc-static-assert"
141141

142+
# Doesn't consider use of preprocessor macros as needing a header, breaking
143+
# struct definitions that depend on size macros from e.g. crypto_core.h.
144+
CHECKS="$CHECKS,-misc-include-cleaner"
145+
142146
set -eux
143147

144148
# TODO(iphydf): Add toxav.
@@ -154,7 +158,7 @@ copy_files() {
154158
find "${DIRS[@]}" \
155159
-maxdepth 1 -type d -exec mkdir -p "$1/{}" \;
156160
find "${DIRS[@]}" \
157-
-maxdepth 1 -name "*.c" -exec cp "{}" "$1/{}" \;
161+
-maxdepth 1 -name "*.[ch]" -exec cp "{}" "$1/{}" \;
158162
}
159163

160164
run() {
@@ -166,7 +170,7 @@ run() {
166170
ls .clang-tidy
167171
copy_files a
168172
if ! find "${DIRS[@]}" \
169-
-maxdepth 1 -name "*.c" -print0 \
173+
-maxdepth 1 -name "*.[ch]" -print0 \
170174
| xargs -0 -n15 -P"$(nproc)" clang-tidy \
171175
-p="$PWD/_build" \
172176
--extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e9e6e7baafe3cfe9b212ffb4f1ea8a8b48e2dc1ee4c07c6b1b0b04893b3b6464 /usr/local/bin/tox-bootstrapd
1+
af58a125e5c80d7a19bc7f32868c1edfdf80f366e3bf778728961a50ce63ee26 /usr/local/bin/tox-bootstrapd

other/bootstrap_daemon/src/log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include <stdbool.h>
1414

15-
#include "../../../toxcore/ccompat.h"
15+
#include "../../../toxcore/attributes.h"
1616

1717
typedef enum LOG_BACKEND {
1818
LOG_BACKEND_STDOUT,

other/bootstrap_daemon/src/log_backend_stdout.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
#ifndef C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_STDOUT_H
1111
#define C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_STDOUT_H
1212

13-
#include "log.h"
14-
1513
#include <stdarg.h>
1614

15+
#include "../../../toxcore/attributes.h"
16+
#include "log.h"
17+
1718
void log_backend_stdout_write(LOG_LEVEL level, const char *format, va_list args) GNU_PRINTF(2, 0);
1819

19-
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_STDOUT_H
20+
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_STDOUT_H

other/bootstrap_daemon/src/log_backend_syslog.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
#ifndef C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_SYSLOG_H
1111
#define C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_SYSLOG_H
1212

13-
#include "log.h"
14-
1513
#include <stdarg.h>
1614

15+
#include "../../../toxcore/attributes.h"
16+
#include "log.h"
17+
1718
void log_backend_syslog_open(void);
1819
void log_backend_syslog_close(void);
1920
void log_backend_syslog_write(LOG_LEVEL level, const char *format, va_list args) GNU_PRINTF(2, 0);
2021

21-
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_SYSLOG_H
22+
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_SYSLOG_H

other/docker/modules/check

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM toxchat/c-toxcore:sources AS sources
2+
FROM alpine:3.19.0
3+
4+
RUN ["apk", "add", "--no-cache", \
5+
"bash", \
6+
"clang", \
7+
"libconfig-dev", \
8+
"libsodium-dev", \
9+
"libvpx-dev", \
10+
"linux-headers", \
11+
"opus-dev", \
12+
"pkgconfig", \
13+
"python3"]
14+
15+
WORKDIR /work
16+
COPY --from=sources /src/ /work/
17+
18+
COPY toxcore/BUILD.bazel /work/toxcore/
19+
COPY other/docker/modules/check /work/other/docker/modules/
20+
RUN ["other/docker/modules/check"]

other/docker/modules/run

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -eux
4+
BUILD=modules
5+
other/docker/sources/build
6+
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

0 commit comments

Comments
 (0)