From fc71dc7eaa34153441c3848f11c7944819179c7e Mon Sep 17 00:00:00 2001
From: Philipp Stephani
Date: Mon, 26 Feb 2024 14:13:09 +0100
Subject: [PATCH] Treat external repositories as system headers for warning
purposes.
This should reduce the noise necessary to disable warnings.
---
.bazelrc | 11 +++++++++++
elisp/binary.cc | 16 ----------------
elisp/binary.h | 16 ----------------
elisp/emacs.cc | 16 ----------------
elisp/launcher.cc | 16 ----------------
elisp/process.cc | 16 ----------------
elisp/process.h | 16 ----------------
elisp/proto/module.c | 16 ----------------
elisp/test.cc | 16 ----------------
examples/ext/.bazelrc | 5 +++++
private/defs.bzl | 9 +++++++++
11 files changed, 25 insertions(+), 128 deletions(-)
diff --git a/.bazelrc b/.bazelrc
index 1ab7296c..3f0d1029 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -12,12 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+common --enable_platform_specific_config
+
build --process_headers_in_dependencies
# Run Pylint by default.
build --aspects='//private:defs.bzl%check_python'
build --output_groups='+check_python'
+# The external_include_paths feature has to be specified in .bazelrc because it
+# needs to apply to all compile actions in all repositories.
+# TODO: File bug against Bazel to make this work as repository-level feature.
+build --features=external_include_paths --host_features=external_include_paths
+
+# The next line shouldn’t be necessary.
+# TODO: File bug against Bazel.
+build:windows --copt=/external:W3
+
import %workspace%/c-std.bazelrc
try-import %workspace%/github.bazelrc
diff --git a/elisp/binary.cc b/elisp/binary.cc
index 8e2e304f..3ceb5c8c 100644
--- a/elisp/binary.cc
+++ b/elisp/binary.cc
@@ -16,24 +16,8 @@
#include
-#ifdef __GNUC__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wpedantic"
-# pragma GCC diagnostic ignored "-Wconversion"
-# pragma GCC diagnostic ignored "-Wsign-conversion"
-# pragma GCC diagnostic ignored "-Woverflow"
-#endif
-#ifdef _MSC_VER
-# pragma warning(push, 3)
-#endif
#include "absl/status/statusor.h"
#include "absl/types/span.h"
-#ifdef __GNUC__
-# pragma GCC diagnostic pop
-#endif
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif
#include "elisp/platform.h"
#include "elisp/process.h"
diff --git a/elisp/binary.h b/elisp/binary.h
index 7e3c99d3..e8960911 100644
--- a/elisp/binary.h
+++ b/elisp/binary.h
@@ -21,24 +21,8 @@
#include
-#ifdef __GNUC__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wpedantic"
-# pragma GCC diagnostic ignored "-Wconversion"
-# pragma GCC diagnostic ignored "-Wsign-conversion"
-# pragma GCC diagnostic ignored "-Woverflow"
-#endif
-#ifdef _MSC_VER
-# pragma warning(push, 3)
-#endif
#include "absl/status/statusor.h"
#include "absl/types/span.h"
-#ifdef __GNUC__
-# pragma GCC diagnostic pop
-#endif
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif
#include "elisp/platform.h"
diff --git a/elisp/emacs.cc b/elisp/emacs.cc
index 567912e2..f8742b13 100644
--- a/elisp/emacs.cc
+++ b/elisp/emacs.cc
@@ -16,24 +16,8 @@
#include
-#ifdef __GNUC__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wpedantic"
-# pragma GCC diagnostic ignored "-Wconversion"
-# pragma GCC diagnostic ignored "-Wsign-conversion"
-# pragma GCC diagnostic ignored "-Woverflow"
-#endif
-#ifdef _MSC_VER
-# pragma warning(push, 3)
-#endif
#include "absl/status/statusor.h"
#include "absl/types/span.h"
-#ifdef __GNUC__
-# pragma GCC diagnostic pop
-#endif
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif
#include "elisp/platform.h"
#include "elisp/process.h"
diff --git a/elisp/launcher.cc b/elisp/launcher.cc
index d87716b9..33aed1e0 100644
--- a/elisp/launcher.cc
+++ b/elisp/launcher.cc
@@ -14,28 +14,12 @@
#include
-#ifdef __GNUC__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wpedantic"
-# pragma GCC diagnostic ignored "-Wconversion"
-# pragma GCC diagnostic ignored "-Wsign-conversion"
-# pragma GCC diagnostic ignored "-Woverflow"
-#endif
-#ifdef _MSC_VER
-# pragma warning(push, 3)
-#endif
#include "absl/container/fixed_array.h"
#include "absl/log/log.h"
#include "absl/meta/type_traits.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/types/span.h"
-#ifdef __GNUC__
-# pragma GCC diagnostic pop
-#endif
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif
#include "elisp/platform.h"
diff --git a/elisp/process.cc b/elisp/process.cc
index fdcaf745..2fb0363a 100644
--- a/elisp/process.cc
+++ b/elisp/process.cc
@@ -52,16 +52,6 @@
#include
#include
-#ifdef __GNUC__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wpedantic"
-# pragma GCC diagnostic ignored "-Wconversion"
-# pragma GCC diagnostic ignored "-Wsign-conversion"
-# pragma GCC diagnostic ignored "-Woverflow"
-#endif
-#ifdef _MSC_VER
-# pragma warning(push, 3)
-#endif
#include "absl/algorithm/container.h"
#include "absl/base/attributes.h"
#include "absl/base/nullability.h"
@@ -78,12 +68,6 @@
#include "absl/strings/str_join.h"
#include "absl/types/span.h"
#include "tools/cpp/runfiles/runfiles.h"
-#ifdef __GNUC__
-# pragma GCC diagnostic pop
-#endif
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif
#ifdef __APPLE__
# include // for _NSGetEnviron
diff --git a/elisp/process.h b/elisp/process.h
index 726d9102..65ce0ce0 100644
--- a/elisp/process.h
+++ b/elisp/process.h
@@ -22,24 +22,8 @@
#include
#include // IWYU pragma: keep
-#ifdef __GNUC__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wpedantic"
-# pragma GCC diagnostic ignored "-Wconversion"
-# pragma GCC diagnostic ignored "-Wsign-conversion"
-# pragma GCC diagnostic ignored "-Woverflow"
-#endif
-#ifdef _MSC_VER
-# pragma warning(push, 3)
-#endif
#include "absl/status/statusor.h"
#include "absl/types/span.h"
-#ifdef __GNUC__
-# pragma GCC diagnostic pop
-#endif
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif
#include "elisp/platform.h"
diff --git a/elisp/proto/module.c b/elisp/proto/module.c
index c7c6ba5c..e7eaed60 100644
--- a/elisp/proto/module.c
+++ b/elisp/proto/module.c
@@ -179,16 +179,6 @@ enum { kMaxIO = 0x7FFFF000 };
# error Emacs module header too old
#endif
-#ifdef __GNUC__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wconversion"
-# pragma GCC diagnostic ignored "-Wsign-conversion"
-# pragma GCC diagnostic ignored "-Wpedantic"
-#endif
-#ifdef _MSC_VER
-# pragma warning(push, 3)
-# pragma warning(disable : 4090 4098 4244 4267 4334)
-#endif
#include "absl/base/attributes.h"
#include "absl/base/config.h"
#include "google/protobuf/any.upb.h"
@@ -215,12 +205,6 @@ enum { kMaxIO = 0x7FFFF000 };
#include "upb/util/required_fields.h"
#include "upb/wire/decode.h"
#include "upb/wire/encode.h"
-#ifdef __GNUC__
-# pragma GCC diagnostic pop
-#endif
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif
/// Global variables
diff --git a/elisp/test.cc b/elisp/test.cc
index 41ba2e91..c489a51f 100644
--- a/elisp/test.cc
+++ b/elisp/test.cc
@@ -16,24 +16,8 @@
#include
-#ifdef __GNUC__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wpedantic"
-# pragma GCC diagnostic ignored "-Wconversion"
-# pragma GCC diagnostic ignored "-Wsign-conversion"
-# pragma GCC diagnostic ignored "-Woverflow"
-#endif
-#ifdef _MSC_VER
-# pragma warning(push, 3)
-#endif
#include "absl/status/statusor.h"
#include "absl/types/span.h"
-#ifdef __GNUC__
-# pragma GCC diagnostic pop
-#endif
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif
#include "elisp/platform.h"
#include "elisp/process.h"
diff --git a/examples/ext/.bazelrc b/examples/ext/.bazelrc
index 02603282..c5646948 100644
--- a/examples/ext/.bazelrc
+++ b/examples/ext/.bazelrc
@@ -12,6 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+# The external_include_paths feature has to be specified in .bazelrc because it
+# needs to apply to all compile actions in all repositories.
+# TODO: File bug against Bazel to make this work as repository-level feature.
+build --features=external_include_paths --host_features=external_include_paths
+
import %workspace%/../../c-std.bazelrc
try-import %workspace%/../../github.bazelrc
diff --git a/private/defs.bzl b/private/defs.bzl
index 161d5d4b..ecf70517 100644
--- a/private/defs.bzl
+++ b/private/defs.bzl
@@ -450,6 +450,15 @@ COPTS = select({
"-pedantic",
"-pedantic-errors",
],
+}) + select({
+ Label("//private:clang"): [
+ # This shouldn’t be needed, but the external_include_paths feature
+ # doesn’t work on macOS.
+ # TODO: File bug against Bazel.
+ "--system-header-prefix=absl/",
+ "--system-header-prefix=upb/",
+ ],
+ Label("//conditions:default"): [],
})
CXXOPTS = select({