Change the canonical way to include the C macros.h to <mojo/macros.h>.

I've updated includes everywhere except in headers under
mojo/public/{c,cpp}. This is because doing so will require making sure
that public_deps are used appropriately everywhere, and it'll be easier
to do so as I'm moving other headers under mojo/public/c to the new
scheme.

R=jamesr@chromium.org

Review URL: https://codereview.chromium.org/2229573002 .

Cr-Mirrored-From: https://github.com/domokit/mojo
Cr-Mirrored-Commit: 5d24787424f3c7ca77b1de906d6aec0a6ba8311c
diff --git a/c/BUILD.gn b/c/BUILD.gn
new file mode 100644
index 0000000..36935b8
--- /dev/null
+++ b/c/BUILD.gn
@@ -0,0 +1,41 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("../mojo_sdk.gni")
+
+config("c_config") {
+  include_dirs = [ "include" ]
+}
+
+# Catch-all for all public C headers/libraries, except for the implementation
+# libraries that are meant to be replaceable ("pluggable"), like ...
+# (TODO(vtl)).
+group("c") {
+  public_deps = [
+    ":common",
+    ":system",
+  ]
+}
+
+# Headers in include/mojo (to be include as <mojo/HEADER.h>).
+mojo_sdk_source_set("common") {
+  public_configs = [ ":c_config" ]
+
+  sources = [
+    "include/mojo/macros.h",
+  ]
+}
+
+# Headers in include/mojo/system (to be include as <mojo/system/HEADER.h>).
+mojo_sdk_source_set("system") {
+  public_configs = [ ":c_config" ]
+
+  sources = [
+    # Nothing here yet.
+  ]
+
+  public_deps = [
+    ":common",
+  ]
+}
diff --git a/c/include/mojo/macros.h b/c/include/mojo/macros.h
new file mode 100644
index 0000000..886ed04
--- /dev/null
+++ b/c/include/mojo/macros.h
@@ -0,0 +1,89 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_C_INCLUDE_MOJO_MACROS_H_
+#define MOJO_PUBLIC_C_INCLUDE_MOJO_MACROS_H_
+
+#include <stddef.h>
+
+// Annotate a variable indicating it's okay if it's unused.
+// Use like:
+//   int x = ...;
+//   MOJO_ALLOW_UNUSED_LOCAL(x);
+#define MOJO_ALLOW_UNUSED_LOCAL(x) false ? (void)x : (void)0
+
+// Annotate a function indicating that the caller must examine the return value.
+// Use like:
+//   int foo() MOJO_WARN_UNUSED_RESULT;
+// Note that it can only be used on the prototype, and not the definition.
+#if defined(__GNUC__)
+#define MOJO_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
+#else
+#define MOJO_WARN_UNUSED_RESULT
+#endif
+
+// Assert things at compile time. (|msg| should be a valid identifier name.)
+// Use like:
+//   MOJO_STATIC_ASSERT(sizeof(Foo) == 12, "Foo has invalid size");
+#if defined(__cplusplus)
+#define MOJO_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
+#else
+#define MOJO_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg)
+#endif
+
+// Like the C++11 |alignof| operator.
+#if defined(__cplusplus) && __cplusplus >= 201103L
+#define MOJO_ALIGNOF(type) alignof(type)
+#elif defined(__GNUC__)
+#define MOJO_ALIGNOF(type) __alignof__(type)
+#elif defined(_MSC_VER)
+// The use of |sizeof| is to work around a bug in MSVC 2010 (see
+// http://goo.gl/isH0C; supposedly fixed since then).
+#define MOJO_ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
+#else
+#error "Please define MOJO_ALIGNOF() for your compiler."
+#endif
+
+// Specify the alignment of a |struct|, etc.
+// Use like:
+//   struct MOJO_ALIGNAS(8) Foo { ... };
+// Unlike the C++11 |alignas()|, |alignment| must be an integer. It may not be a
+// type, nor can it be an expression like |MOJO_ALIGNOF(type)| (due to the
+// non-C++11 MSVS version).
+#if defined(__cplusplus) && __cplusplus >= 201103L
+#define MOJO_ALIGNAS(alignment) alignas(alignment)
+#elif defined(__GNUC__)
+#define MOJO_ALIGNAS(alignment) __attribute__((aligned(alignment)))
+#elif defined(_MSC_VER)
+#define MOJO_ALIGNAS(alignment) __declspec(align(alignment))
+#else
+#error "Please define MOJO_ALIGNAS() for your compiler."
+#endif
+
+// Use these to declare functions in C header files so that they'll be usable
+// from C++.
+#if defined(__cplusplus)
+#define MOJO_BEGIN_EXTERN_C extern "C" {
+#define MOJO_END_EXTERN_C }
+#else
+#define MOJO_BEGIN_EXTERN_C
+#define MOJO_END_EXTERN_C
+#endif
+
+// Use |MOJO_RESTRICT| (in C function declarations) in place of C99's
+// |restrict|, to work properly with C++. (It allows certain optimizations, but
+// more importantly it serves a documentary purpose for the caller.)
+//
+// Recommendation: If a function has multiple pointer parameters at least one of
+// which is to non-const, then all the pointer parameters should be declared
+// using |MOJO_RESTRICT| unless aliasing is explicitly allowed.
+#if defined(__GNUC__) || defined(_MSC_VER)
+// Use |__restrict|, since it works both in C++ and when compiling as C90
+// (|restrict| is only available in C99 and later, and never in C++).
+#define MOJO_RESTRICT __restrict
+#else
+#error "Please define MOJO_RESTRICT for your compiler."
+#endif
+
+#endif  // MOJO_PUBLIC_C_INCLUDE_MOJO_MACROS_H_
diff --git a/c/system/BUILD.gn b/c/system/BUILD.gn
index 160cf33..ee594ca 100644
--- a/c/system/BUILD.gn
+++ b/c/system/BUILD.gn
@@ -19,4 +19,6 @@
     "wait.h",
     "wait_set.h",
   ]
+
+  mojo_sdk_public_deps = [ "mojo/public/c:common" ]
 }
diff --git a/c/system/macros.h b/c/system/macros.h
index b8dbb1d..2f75ca2 100644
--- a/c/system/macros.h
+++ b/c/system/macros.h
@@ -2,88 +2,14 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+// TODO(vtl): Remove this file.
+
 #ifndef MOJO_PUBLIC_C_SYSTEM_MACROS_H_
 #define MOJO_PUBLIC_C_SYSTEM_MACROS_H_
 
-#include <stddef.h>
-
-// Annotate a variable indicating it's okay if it's unused.
-// Use like:
-//   int x = ...;
-//   MOJO_ALLOW_UNUSED_LOCAL(x);
-#define MOJO_ALLOW_UNUSED_LOCAL(x) false ? (void)x : (void)0
-
-// Annotate a function indicating that the caller must examine the return value.
-// Use like:
-//   int foo() MOJO_WARN_UNUSED_RESULT;
-// Note that it can only be used on the prototype, and not the definition.
-#if defined(__GNUC__)
-#define MOJO_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
-#else
-#define MOJO_WARN_UNUSED_RESULT
-#endif
-
-// Assert things at compile time. (|msg| should be a valid identifier name.)
-// Use like:
-//   MOJO_STATIC_ASSERT(sizeof(Foo) == 12, "Foo has invalid size");
-#if defined(__cplusplus)
-#define MOJO_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
-#else
-#define MOJO_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg)
-#endif
-
-// Like the C++11 |alignof| operator.
-#if defined(__cplusplus) && __cplusplus >= 201103L
-#define MOJO_ALIGNOF(type) alignof(type)
-#elif defined(__GNUC__)
-#define MOJO_ALIGNOF(type) __alignof__(type)
-#elif defined(_MSC_VER)
-// The use of |sizeof| is to work around a bug in MSVC 2010 (see
-// http://goo.gl/isH0C; supposedly fixed since then).
-#define MOJO_ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
-#else
-#error "Please define MOJO_ALIGNOF() for your compiler."
-#endif
-
-// Specify the alignment of a |struct|, etc.
-// Use like:
-//   struct MOJO_ALIGNAS(8) Foo { ... };
-// Unlike the C++11 |alignas()|, |alignment| must be an integer. It may not be a
-// type, nor can it be an expression like |MOJO_ALIGNOF(type)| (due to the
-// non-C++11 MSVS version).
-#if defined(__cplusplus) && __cplusplus >= 201103L
-#define MOJO_ALIGNAS(alignment) alignas(alignment)
-#elif defined(__GNUC__)
-#define MOJO_ALIGNAS(alignment) __attribute__((aligned(alignment)))
-#elif defined(_MSC_VER)
-#define MOJO_ALIGNAS(alignment) __declspec(align(alignment))
-#else
-#error "Please define MOJO_ALIGNAS() for your compiler."
-#endif
-
-// Use these to declare functions in C header files so that they'll be usable
-// from C++.
-#if defined(__cplusplus)
-#define MOJO_BEGIN_EXTERN_C extern "C" {
-#define MOJO_END_EXTERN_C }
-#else
-#define MOJO_BEGIN_EXTERN_C
-#define MOJO_END_EXTERN_C
-#endif
-
-// Use |MOJO_RESTRICT| (in C function declarations) in place of C99's
-// |restrict|, to work properly with C++. (It allows certain optimizations, but
-// more importantly it serves a documentary purpose for the caller.)
-//
-// Recommendation: If a function has multiple pointer parameters at least one of
-// which is to non-const, then all the pointer parameters should be declared
-// using |MOJO_RESTRICT| unless aliasing is explicitly allowed.
-#if defined(__GNUC__) || defined(_MSC_VER)
-// Use |__restrict|, since it works both in C++ and when compiling as C90
-// (|restrict| is only available in C99 and later, and never in C++).
-#define MOJO_RESTRICT __restrict
-#else
-#error "Please define MOJO_RESTRICT for your compiler."
-#endif
+// TODO(vtl): This would be better (and more correct), but it requires fixing
+// lots of public_deps:
+// #include <mojo/macros.h>
+#include "mojo/public/c/include/mojo/macros.h"
 
 #endif  // MOJO_PUBLIC_C_SYSTEM_MACROS_H_
diff --git a/c/system/tests/BUILD.gn b/c/system/tests/BUILD.gn
index cd38a25..9e80de1 100644
--- a/c/system/tests/BUILD.gn
+++ b/c/system/tests/BUILD.gn
@@ -28,6 +28,7 @@
   ]
 
   mojo_sdk_deps = [
+    "mojo/public/c:system",
     "mojo/public/c/environment",
     "mojo/public/c/system",
   ]
@@ -49,6 +50,7 @@
   ]
 
   mojo_sdk_deps = [
+    "mojo/public/c:system",
     "mojo/public/c/environment",
     "mojo/public/c/system",
   ]
@@ -70,6 +72,7 @@
   ]
 
   mojo_sdk_deps = [
+    "mojo/public/c:system",
     "mojo/public/c/environment",
     "mojo/public/c/system",
     "mojo/public/cpp/test_support",
diff --git a/c/system/tests/compile_unittest_pure_c.c b/c/system/tests/compile_unittest_pure_c.c
index 135261a..c4a46c4 100644
--- a/c/system/tests/compile_unittest_pure_c.c
+++ b/c/system/tests/compile_unittest_pure_c.c
@@ -6,6 +6,8 @@
 #error "This file should be compiled as C, not C++."
 #endif
 
+// Include all the header files that are meant to be compilable as C.
+#include <mojo/macros.h>
 #include <stddef.h>
 #include <string.h>
 
@@ -15,7 +17,6 @@
 #include "mojo/public/c/system/buffer.h"
 #include "mojo/public/c/system/data_pipe.h"
 #include "mojo/public/c/system/handle.h"
-#include "mojo/public/c/system/macros.h"
 #include "mojo/public/c/system/main.h"
 #include "mojo/public/c/system/message_pipe.h"
 #include "mojo/public/c/system/result.h"
diff --git a/c/system/tests/compile_unittest_pure_cpp.cc b/c/system/tests/compile_unittest_pure_cpp.cc
index ff3351e..23ef94a 100644
--- a/c/system/tests/compile_unittest_pure_cpp.cc
+++ b/c/system/tests/compile_unittest_pure_cpp.cc
@@ -6,12 +6,14 @@
 // more stringent warnings, in particular with "-Wundef".
 
 // Include all the header files that are meant to be compilable as C.
+#include <mojo/macros.h>
+
+// Include all the header files that are meant to be compilable as C.
 #include "mojo/public/c/environment/async_waiter.h"
 #include "mojo/public/c/environment/logger.h"
 #include "mojo/public/c/system/buffer.h"
 #include "mojo/public/c/system/data_pipe.h"
 #include "mojo/public/c/system/handle.h"
-#include "mojo/public/c/system/macros.h"
 #include "mojo/public/c/system/main.h"
 #include "mojo/public/c/system/message_pipe.h"
 #include "mojo/public/c/system/result.h"
diff --git a/c/system/tests/macros_unittest.cc b/c/system/tests/macros_unittest.cc
index b22e124..45ef6bc 100644
--- a/c/system/tests/macros_unittest.cc
+++ b/c/system/tests/macros_unittest.cc
@@ -8,7 +8,7 @@
 // TODO(vtl): Fix no-compile tests (which are all disabled; crbug.com/105388)
 // and write some "negative" tests.
 
-#include "mojo/public/c/system/macros.h"
+#include <mojo/macros.h>
 
 #include <assert.h>
 #include <stdint.h>
diff --git a/c/system/tests/message_pipe_perftest.cc b/c/system/tests/message_pipe_perftest.cc
index 05fd00e..4663d88 100644
--- a/c/system/tests/message_pipe_perftest.cc
+++ b/c/system/tests/message_pipe_perftest.cc
@@ -7,13 +7,13 @@
 #include "mojo/public/c/system/message_pipe.h"
 
 #include <assert.h>
+#include <mojo/macros.h>
 #include <stdint.h>
 #include <stdio.h>
 
 #include <thread>
 
 #include "mojo/public/c/system/handle.h"
-#include "mojo/public/c/system/macros.h"
 #include "mojo/public/c/system/result.h"
 #include "mojo/public/c/system/tests/perftest_utils.h"
 #include "mojo/public/c/system/time.h"
diff --git a/c/system/tests/perftest_utils.cc b/c/system/tests/perftest_utils.cc
index 43ccb5f..3d9a2f8 100644
--- a/c/system/tests/perftest_utils.cc
+++ b/c/system/tests/perftest_utils.cc
@@ -5,10 +5,10 @@
 #include "mojo/public/c/system/tests/perftest_utils.h"
 
 #include <assert.h>
+#include <mojo/macros.h>
 #include <stddef.h>
 #include <time.h>
 
-#include "mojo/public/c/system/macros.h"
 #include "mojo/public/c/system/time.h"
 #include "mojo/public/cpp/test_support/test_support.h"
 
diff --git a/c/system/tests/wait_set_perftest.cc b/c/system/tests/wait_set_perftest.cc
index 40f72af..6c58c7e 100644
--- a/c/system/tests/wait_set_perftest.cc
+++ b/c/system/tests/wait_set_perftest.cc
@@ -7,6 +7,7 @@
 #include "mojo/public/c/system/wait_set.h"
 
 #include <assert.h>
+#include <mojo/macros.h>
 #include <stdint.h>
 #include <stdio.h>
 
@@ -15,7 +16,6 @@
 #include <vector>
 
 #include "mojo/public/c/system/handle.h"
-#include "mojo/public/c/system/macros.h"
 #include "mojo/public/c/system/message_pipe.h"
 #include "mojo/public/c/system/result.h"
 #include "mojo/public/c/system/tests/perftest_utils.h"
diff --git a/cpp/bindings/lib/array_internal.h b/cpp/bindings/lib/array_internal.h
index d276b8c..26509b1 100644
--- a/cpp/bindings/lib/array_internal.h
+++ b/cpp/bindings/lib/array_internal.h
@@ -10,7 +10,6 @@
 #include <type_traits>
 #include <vector>
 
-#include "mojo/public/c/system/macros.h"
 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
 #include "mojo/public/cpp/bindings/lib/bounds_checker.h"
diff --git a/cpp/bindings/lib/array_serialization.h b/cpp/bindings/lib/array_serialization.h
index 7c8f515..cd30bc0 100644
--- a/cpp/bindings/lib/array_serialization.h
+++ b/cpp/bindings/lib/array_serialization.h
@@ -16,7 +16,6 @@
 #include <type_traits>
 #include <vector>
 
-#include "mojo/public/c/system/macros.h"
 #include "mojo/public/cpp/bindings/lib/array_internal.h"
 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
 #include "mojo/public/cpp/bindings/lib/iterator_util.h"
diff --git a/cpp/bindings/tests/validation_test_input_parser.cc b/cpp/bindings/tests/validation_test_input_parser.cc
index 9d2607d..7678711 100644
--- a/cpp/bindings/tests/validation_test_input_parser.cc
+++ b/cpp/bindings/tests/validation_test_input_parser.cc
@@ -13,8 +13,6 @@
 #include <set>
 #include <utility>
 
-#include "mojo/public/c/system/macros.h"
-
 namespace mojo {
 namespace test {
 namespace {
diff --git a/cpp/utility/BUILD.gn b/cpp/utility/BUILD.gn
index dd2c240..3568659 100644
--- a/cpp/utility/BUILD.gn
+++ b/cpp/utility/BUILD.gn
@@ -12,6 +12,7 @@
   ]
 
   mojo_sdk_deps = [
+    "mojo/public/c:common",
     "mojo/public/cpp/bindings:callback",
     "mojo/public/cpp/system",
   ]
diff --git a/cpp/utility/lib/run_loop.cc b/cpp/utility/lib/run_loop.cc
index 4ca04da..e5c8b86 100644
--- a/cpp/utility/lib/run_loop.cc
+++ b/cpp/utility/lib/run_loop.cc
@@ -5,6 +5,7 @@
 #include "mojo/public/cpp/utility/run_loop.h"
 
 #include <assert.h>
+#include <mojo/macros.h>
 #include <pthread.h>
 
 #include <algorithm>
@@ -12,7 +13,6 @@
 #include <utility>
 #include <vector>
 
-#include "mojo/public/c/system/macros.h"
 #include "mojo/public/cpp/system/time.h"
 #include "mojo/public/cpp/system/wait.h"
 #include "mojo/public/cpp/utility/run_loop_handler.h"
diff --git a/tools/bindings/mojom.gni b/tools/bindings/mojom.gni
index 8fb23dc..31b199f 100644
--- a/tools/bindings/mojom.gni
+++ b/tools/bindings/mojom.gni
@@ -300,7 +300,12 @@
     public_configs =
         rebase_path([ "mojo/public/build/config:mojo_sdk" ], ".", mojo_root)
 
-    public_deps = rebase_path([ "mojo/public/c/bindings" ], ".", mojo_root)
+    public_deps = rebase_path([
+                                "mojo/public/c",
+                                "mojo/public/c/bindings",
+                              ],
+                              ".",
+                              mojo_root)
     foreach(d, rebased_mojo_sdk_public_deps) {
       full_name = get_label_info(d, "label_no_toolchain")
       public_deps += [ "${full_name}_c" ]