Reviewers: Sven Panne,

Description:
[clang] Set correct clang warning flags.

Import the build/set_clang_warning_flags.gypi magic from Chrome (which
is used by third party .gyp files to enable/disable warnings that
we/Chrome shouldn't care about). Also make sure that we don't pass
certain flags as -Wall or -pedantic to third party code. This way we do
no longer generate all those stupid warnings in icu.

[email protected]

Please review this at https://codereview.chromium.org/960813002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+80, -3 lines):
  A build/set_clang_warning_flags.gypi
  M build/standalone.gypi
  M build/toolchain.gypi


Index: build/set_clang_warning_flags.gypi
diff --git a/build/set_clang_warning_flags.gypi b/build/set_clang_warning_flags.gypi
new file mode 100644
index 0000000000000000000000000000000000000000..b087f5d40df57dac651b12023d7bc57b1d72585a
--- /dev/null
+++ b/build/set_clang_warning_flags.gypi
@@ -0,0 +1,58 @@
+# Copyright 2015 the V8 project authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This file is meant to be included to set clang-specific compiler flags.
+# To use this the following variable can be defined:
+#   clang_warning_flags:       list: Compiler flags to pass to clang.
+#   clang_warning_flags_unset: list: Compiler flags to not pass to clang.
+#
+# Only use this in third-party code. In chromium_code, fix your code to not
+# warn instead!
+#
+# Note that the gypi file is included in target_defaults, so it does not need
+# to be explicitly included.
+#
+# Warning flags set by this will be used on all platforms. If you want to set
+# warning flags on only some platforms, you have to do so manually.
+#
+# To use this, create a gyp target with the following form:
+# {
+#   'target_name': 'my_target',
+#   'variables': {
+#     'clang_warning_flags': ['-Wno-awesome-warning'],
+#     'clang_warning_flags_unset': ['-Wpreviously-set-flag'],
+#   }
+# }
+
+{
+  'variables': {
+    'clang_warning_flags_unset%': [],  # Provide a default value.
+  },
+  'conditions': [
+    ['clang==1', {
+      # This uses >@ instead of @< to also see clang_warning_flags set in
+ # targets directly, not just the clang_warning_flags in target_defaults.
+      'cflags': [ '>@(clang_warning_flags)' ],
+      'cflags!': [ '>@(clang_warning_flags_unset)' ],
+      'xcode_settings': {
+        'WARNING_CFLAGS': ['>@(clang_warning_flags)'],
+        'WARNING_CFLAGS!': ['>@(clang_warning_flags_unset)'],
+      },
+      'msvs_settings': {
+        'VCCLCompilerTool': {
+          'AdditionalOptions': [ '>@(clang_warning_flags)' ],
+          'AdditionalOptions!': [ '>@(clang_warning_flags_unset)' ],
+        },
+      },
+    }],
+    ['clang==0 and host_clang==1', {
+      'target_conditions': [
+        ['_toolset=="host"', {
+          'cflags': [ '>@(clang_warning_flags)' ],
+          'cflags!': [ '>@(clang_warning_flags_unset)' ],
+        }],
+      ],
+    }],
+  ],
+}
Index: build/standalone.gypi
diff --git a/build/standalone.gypi b/build/standalone.gypi
index 8ec06fd5e011d44ecd7368f138b99f50fe7582b3..8d3a059ed77c151ef41683488d8d54297a11b0f6 100644
--- a/build/standalone.gypi
+++ b/build/standalone.gypi
@@ -199,8 +199,21 @@
         ],
         'conditions': [
           ['os_posix == 1 and OS != "mac"', {
+            # We don't want to get warnings from third-party code,
+            # so remove any existing warning-enabling flags like -Wall.
             'cflags!': [
+              '-pedantic',
+              '-Wall',
               '-Werror',
+              '-Wextra',
+            ],
+            # Clang considers the `register` keyword as deprecated, but
+            # icu uses it all over the place.
+            'cflags+': [
+              '-Wno-deprecated-register',
+            ],
+            'cflags_cc!': [
+              '-Wnon-virtual-dtor',
             ],
           }],
           ['OS == "mac"', {
@@ -286,7 +299,6 @@
         'cflags': [
           '-Wall',
           '<(werror)',
-          '-W',
           '-Wno-unused-parameter',
           '-Wno-long-long',
           '-pthread',
@@ -317,7 +329,6 @@
         'cflags': [
           '-Wall',
           '<(werror)',
-          '-W',
           '-Wno-unused-parameter',
           '-fno-exceptions',
# Don't warn about the "struct foo f = {0};" initialization pattern.
@@ -460,7 +471,6 @@
           'WARNING_CFLAGS': [
             '-Wall',
             '-Wendif-labels',
-            '-W',
             '-Wno-unused-parameter',
# Don't warn about the "struct foo f = {0};" initialization pattern.
             '-Wno-missing-field-initializers',
Index: build/toolchain.gypi
diff --git a/build/toolchain.gypi b/build/toolchain.gypi
index b8c73177853fa4ac988b8394dbfc633b272d557f..d8cb5f76108e3b8422c307cfc471050daa0db95a 100644
--- a/build/toolchain.gypi
+++ b/build/toolchain.gypi
@@ -165,6 +165,15 @@
     }],
   ],
   'target_defaults': {
+    'variables': {
+      'clang_warning_flags': [
+        '-Wheader-hygiene',
+
+        # Warns when a const char[] is converted to bool.
+        '-Wstring-conversion',
+      ],
+    },
+    'includes': [ 'set_clang_warning_flags.gypi', ],
     'conditions': [
       ['v8_target_arch=="arm"', {
         'defines': [


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to