summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHidehiko Abe <hidehiko@google.com>2018-02-19 14:07:30 +0000
committerandroid-build-merger <android-build-merger@google.com>2018-02-19 14:07:30 +0000
commit10d13da659e61fc2b390ee408870b3f84213543d (patch)
treef72f6679ce6e841c2613caf596098be9ea63b89f
parent777fba1ec208c9ec9725a18b9067652e3d3eac35 (diff)
parentdee79250222e7ced18f435c265cac7882d346280 (diff)
downloadlibchrome-10d13da659e61fc2b390ee408870b3f84213543d.tar.gz
Deal with -Wunused-parameter in libchrome build rule. am: c0d6a3235d
am: dee7925022 Change-Id: I8d49de87cdabf21905c6a7f68884bbc41766d93a
-rw-r--r--Android.bp20
-rw-r--r--base/threading/thread_restrictions.h4
-rwxr-xr-xlibchrome_tools/include_generator.py93
3 files changed, 114 insertions, 3 deletions
diff --git a/Android.bp b/Android.bp
index bf4809e30e..202076beec 100644
--- a/Android.bp
+++ b/Android.bp
@@ -15,6 +15,18 @@
// Common defaults
// ========================================================
+// Using Chrome header files directly could cause -Wunused-parameter errors,
+// and this is workaround. Please find the document in include_generator.py
+// for details.
+gensrcs {
+ name: "libchrome-include",
+ cmd: "$(location libchrome_tools/include_generator.py) $(in) $(out)",
+ tool_files: ["libchrome_tools/include_generator.py"],
+ export_include_dirs: ["."],
+ srcs: ["**/*.h"],
+ output_extension: "h",
+}
+
cc_defaults {
name: "libchrome-defaults",
// Set clang to "true" to force clang or "false" to force gcc.
@@ -24,12 +36,18 @@ cc_defaults {
"-Wall",
"-Werror",
"-Wno-deprecated-declarations",
+ "-Wno-unused-parameter",
],
include_dirs: [
"external/valgrind/include",
"external/valgrind",
],
- export_include_dirs: ["."],
+
+ // Note: Although the generated header files are exported here, in building
+ // libchrome, "." has priority (unlike building projects using libchrome),
+ // so the raw header files are used for them.
+ generated_headers: ["libchrome-include"],
+ export_generated_headers: ["libchrome-include"],
target: {
host: {
cflags: [
diff --git a/base/threading/thread_restrictions.h b/base/threading/thread_restrictions.h
index a86dd452b8..ad8b4ba629 100644
--- a/base/threading/thread_restrictions.h
+++ b/base/threading/thread_restrictions.h
@@ -163,9 +163,9 @@ class BASE_EXPORT ThreadRestrictions {
#else
// Inline the empty definitions of these functions so that they can be
// compiled out.
- static bool SetIOAllowed(bool) { return true; }
+ static bool SetIOAllowed(bool allowed) { return true; }
static void AssertIOAllowed() {}
- static bool SetSingletonAllowed(bool) { return true; }
+ static bool SetSingletonAllowed(bool allowed) { return true; }
static void AssertSingletonAllowed() {}
static void DisallowWaiting() {}
static void AssertWaitAllowed() {}
diff --git a/libchrome_tools/include_generator.py b/libchrome_tools/include_generator.py
new file mode 100755
index 0000000000..efffd3952c
--- /dev/null
+++ b/libchrome_tools/include_generator.py
@@ -0,0 +1,93 @@
+#!/usr/bin/python
+
+# Copyright (C) 2018 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.
+
+"""Generates wrapped include files to workaround -Wunused-parameter errors.
+
+In Chrome repository, "-Wunused-parameter" is disabled, and several header
+files in Chrome repository have actually unused-parameter.
+One of the typical scenarios is; in Chrome, Observer class is often defined
+as follows:
+
+class Foo {
+ public:
+ class Observer {
+ public:
+ virtual void OnSomeEvent(EventArg arg) {}
+ virtual void OnAnotherEvent(EventArg arg) {}
+ ...
+ };
+ ...
+};
+
+Here, On...Event() methods do nothing by default, and subclasses will override
+only necessary ones.
+In this use case, argument names can also work as documentation, and overrides
+can use these good interface-defined default names as a starting point for
+their implementation.
+
+On the other hand, in Android, -Wunused-parameter is enabled by default.
+Thus, if such a project includes header files from libchrome, it could cause
+a compile error (by the warning and "-Werror").
+
+To avoid such a situation, libchrome exports include files wrapped by the
+pragmas as follows.
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+${actual_include_file_content}
+#pragma GCC diagnostic pop
+
+so, the unused-parameter warning generated by the libchrome include headers
+will be ignored.
+Note that these GCC pragmas are also supported by clang for compatibility. cf)
+https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas
+
+Usage: include_generator.py $(in) $(out)
+"""
+
+import sys
+
+
+def _generate(input_path, output_path):
+ """Generates a include file wrapped by pragmas.
+
+ Reads the file at |input_path| and output the content with wrapping by
+ #pragma to ignore unused-parameter warning into the file at |output_path|.
+ If the parent directories of |output_path| do not exist, creates them.
+
+ Args:
+ input_path: Path to the source file. Expected this is a chrome's header
+ file.
+ output_path: Path to the output file.
+ """
+ with open(input_path, 'r') as f:
+ content = f.read()
+
+ with open(output_path, 'w') as f:
+ f.writelines([
+ '// Generated by %s\n' % sys.argv[0],
+ '#pragma GCC diagnostic push\n'
+ '#pragma GCC diagnostic ignored "-Wunused-parameter"\n',
+ content,
+ '#pragma GCC diagnostic pop\n'])
+
+
+def main():
+ _generate(*sys.argv[1:])
+
+
+if __name__ == '__main__':
+ main()