aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD.bazel5
-rw-r--r--cc_toolchain_features.bzl15
-rw-r--r--cc_toolchain_features_misc_test.bzl63
3 files changed, 83 insertions, 0 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
index 30ebc8cdc..ac1b3a383 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -44,6 +44,7 @@ load(
"cc_toolchain_features_arm_isa_test_suite",
)
load(":cc_toolchain_clang_version_test.bzl", "cc_toolchain_clang_version_test_suite")
+load(":cc_toolchain_features_misc_test.bzl", "cc_toolchain_features_test_suite")
load(
":cc_toolchain_features_cfi_test.bzl",
"cc_toolchain_features_cfi_test_suite",
@@ -433,6 +434,10 @@ cc_toolchain_clang_version_test_suite(
name = "cc_toolchain_clang_version_tests",
)
+cc_toolchain_features_test_suite(
+ name = "cc_toolchain_features_tests",
+)
+
cc_toolchain_features_cfi_test_suite(
name = "cc_toolchain_features_cfi_tests",
)
diff --git a/cc_toolchain_features.bzl b/cc_toolchain_features.bzl
index c095a3a1c..e800086e2 100644
--- a/cc_toolchain_features.bzl
+++ b/cc_toolchain_features.bzl
@@ -461,6 +461,21 @@ def _compiler_flag_features(ctx, target_arch, target_os, flags = []):
],
))
+ features.append(feature(
+ name = "warnings_as_errors",
+ enabled = True,
+ flag_sets = [
+ flag_set(
+ actions = _actions.compile,
+ flag_groups = [
+ flag_group(
+ flags = ["-Werror"],
+ ),
+ ],
+ ),
+ ],
+ ))
+
# The user_compile_flags feature is used by Bazel to add --copt, --conlyopt,
# and --cxxopt values. Any features added above this call will thus appear
# earlier in the commandline than the user opts (so users could override
diff --git a/cc_toolchain_features_misc_test.bzl b/cc_toolchain_features_misc_test.bzl
new file mode 100644
index 000000000..5a9b0ed62
--- /dev/null
+++ b/cc_toolchain_features_misc_test.bzl
@@ -0,0 +1,63 @@
+"""Copyright (C) 2022 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+
+load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
+load(
+ "//build/bazel/rules/test_common:flags.bzl",
+ "action_flags_absent_for_mnemonic_test",
+ "action_flags_present_for_mnemonic_nonexclusive_test",
+)
+
+def _test_warnings_as_errors_feature():
+ name = "warnings_as_errors_feature"
+ test_name = name + "_test"
+ native.cc_library(
+ name = name,
+ srcs = ["foo.c", "bar.cpp"],
+ tags = ["manual"],
+ )
+ action_flags_present_for_mnemonic_nonexclusive_test(
+ name = test_name,
+ target_under_test = name,
+ mnemonics = ["CppCompile"],
+ expected_flags = ["-Werror"],
+ )
+ return test_name
+
+def _test_warnings_as_errors_disabled_feature():
+ name = "no_warnings_as_errors_feature"
+ test_name = name + "_test"
+ native.cc_library(
+ name = name,
+ srcs = ["foo.c", "bar.cpp"],
+ features = ["-warnings_as_errors"],
+ tags = ["manual"],
+ )
+ action_flags_absent_for_mnemonic_test(
+ name = test_name,
+ target_under_test = name,
+ mnemonics = ["CppCompile"],
+ expected_absent_flags = ["-Werror"],
+ )
+ return test_name
+
+def cc_toolchain_features_test_suite(name):
+ native.test_suite(
+ name = name,
+ tests = [
+ _test_warnings_as_errors_feature(),
+ _test_warnings_as_errors_disabled_feature(),
+ ],
+ )