From c222f582b4c0b0f3081c150d0c5e958b6f28b1ec Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Tue, 23 Dec 2025 13:21:37 +0800 Subject: [PATCH] [gn] no propagating diagnostic flags (#12219) This commit moves the diagnostic flags into the toolchain itself, preventing these flags being propagated to OpenThread dependents. --- BUILD.gn | 7 ------- etc/gn/BUILDCONFIG.gn | 6 +++++- etc/gn/toolchain/BUILD.gn | 25 ++++++++++++++++++++----- script/check-gn-build | 24 ++++++++++++------------ 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 764182b00..dce4e68b3 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -33,13 +33,6 @@ config("openthread_config") { defines += [ "OPENTHREAD_CONFIG_FILE=${openthread_config_file}" ] } - cflags = [ - "-Werror", - "-Wall", - "-Wextra", - "-Wundef", - ] - include_dirs = openthread_project_include_dirs include_dirs += [ diff --git a/etc/gn/BUILDCONFIG.gn b/etc/gn/BUILDCONFIG.gn index 9e4a5d441..6af1e51ec 100644 --- a/etc/gn/BUILDCONFIG.gn +++ b/etc/gn/BUILDCONFIG.gn @@ -38,4 +38,8 @@ if (current_os == "") { current_os = target_os } -set_default_toolchain("//etc/gn/toolchain:gcc") +declare_args() { + use_clang = false +} + +set_default_toolchain("//etc/gn/toolchain") diff --git a/etc/gn/toolchain/BUILD.gn b/etc/gn/toolchain/BUILD.gn index 06939efd9..a5a54747b 100644 --- a/etc/gn/toolchain/BUILD.gn +++ b/etc/gn/toolchain/BUILD.gn @@ -25,10 +25,25 @@ # POSSIBILITY OF SUCH DAMAGE. # -toolchain("gcc") { +toolchain("toolchain") { + diagnostic_cflags = [ + "-Werror", + "-Wall", + "-Wextra", + "-Wundef", + ] + if (use_clang) { + cc = "clang" + cxx = "clang++" + } else { + cc = "gcc" + cxx = "g++" + } + cflags = string_join(" ", diagnostic_cflags) + tool("cc") { depfile = "{{output}}.d" - command = "gcc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" + command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} $cflags {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" depsformat = "gcc" description = "CC {{output}}" outputs = [ @@ -37,7 +52,7 @@ toolchain("gcc") { } tool("cxx") { depfile = "{{output}}.d" - command = "g++ -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" + command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} $cflags {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" depsformat = "gcc" description = "CXX {{output}}" outputs = [ @@ -59,7 +74,7 @@ toolchain("gcc") { soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". sofile = "{{output_dir}}/$soname" rspfile = soname + ".rsp" - command = "g++ -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile" + command = "$cxx -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile" rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}" description = "SOLINK $soname" # Use this for {{output_extension}} expansions unless a target manually @@ -79,7 +94,7 @@ toolchain("gcc") { tool("link") { outfile = "{{target_output_name}}{{output_extension}}" rspfile = "$outfile.rsp" - command = "g++ {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}" + command = "$cxx {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}" description = "LINK $outfile" default_output_dir = "{{root_out_dir}}" rspfile_content = "{{inputs}}" diff --git a/script/check-gn-build b/script/check-gn-build index 9c44e2057..3b8545710 100755 --- a/script/check-gn-build +++ b/script/check-gn-build @@ -34,23 +34,23 @@ set -e set -x -main() +check_build() { - # Check GN build for OT1.1 rm gn-out -r || true - gn gen --check gn-out - gn args gn-out --list - ninja -C gn-out - test -f gn-out/obj/src/core/libopenthread-ftd.a - - # Check GN build for OT1.4 - rm gn-out -r || true - mkdir gn-out - echo 'openthread_config_thread_version = "1.4"' >gn-out/args.gn - gn gen --check gn-out + gn gen --check gn-out "$@" gn args gn-out --list ninja -C gn-out test -f gn-out/obj/src/core/libopenthread-ftd.a } +main() +{ + for thread_version in 1.4 1.1; do + for use_clang in true false; do + check_build --args="use_clang=$use_clang openthread_config_thread_version=\"$thread_version\"" + done + done + +} + main "$@"