Commit 7d7dd3c3 authored by Eric Seckler's avatar Eric Seckler Committed by Commit Bot

base tracing: Make trace_event includes a bypassable presubmit error

Base code should include base_tracing.h instead of trace_event impl
headers, so that base can build with enable_base_tracing = false.

Previously, a presubmit check emitted a warning if a trace_event
implementation header was included outside trace_event implementation
directories. This modifies the warning into an error, which can be
bypassed via a source code comment.

TBR: rsesek@chromium.org
Bug: 1093406
Change-Id: Ic82f399390ededd12c04ad6005de8f68929bae87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2264555Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782901}
parent 6fcef469
...@@ -40,20 +40,18 @@ def _CheckNoTraceEventInclude(input_api, output_api): ...@@ -40,20 +40,18 @@ def _CheckNoTraceEventInclude(input_api, output_api):
to maintain compatibility with the gn flag "enable_base_tracing = false". to maintain compatibility with the gn flag "enable_base_tracing = false".
""" """
discouraged_includes = [ discouraged_includes = [
r'^#include "base/trace_event/blame_context.h"$', r'^#include "base/trace_event/(?!base_tracing\.h)',
r'^#include "base/trace_event/memory_allocator_dump_guid.h"$',
r'^#include "base/trace_event/memory_dump_provider.h"$',
r'^#include "base/trace_event/trace_event.h"$',
r'^#include "base/trace_event/traced_value.h"$',
] ]
white_list = [ white_list = [
r".*\.(h|cc|mm)$", r".*\.(h|cc|mm)$",
] ]
black_list = [ black_list = [
r".*[\\/]test[\\/].*",
r".*[\\/]trace_event[\\/].*", r".*[\\/]trace_event[\\/].*",
r".*[\\/]tracing[\\/].*", r".*[\\/]tracing[\\/].*",
] ]
no_presubmit = r"// no-presubmit-check"
def FilterFile(affected_file): def FilterFile(affected_file):
return input_api.FilterSourceFile( return input_api.FilterSourceFile(
...@@ -65,16 +63,19 @@ def _CheckNoTraceEventInclude(input_api, output_api): ...@@ -65,16 +63,19 @@ def _CheckNoTraceEventInclude(input_api, output_api):
for f in input_api.AffectedSourceFiles(FilterFile): for f in input_api.AffectedSourceFiles(FilterFile):
for line_num, line in f.ChangedContents(): for line_num, line in f.ChangedContents():
for include in discouraged_includes: for include in discouraged_includes:
if input_api.re.search(include, line): if (input_api.re.search(include, line) and
not input_api.re.search(no_presubmit, line)):
locations.append(" %s:%d" % (f.LocalPath(), line_num)) locations.append(" %s:%d" % (f.LocalPath(), line_num))
break break
if locations: if locations:
return [ output_api.PresubmitPromptWarning( return [ output_api.PresubmitError(
'Consider replacing includes to trace_event implementation headers\n' + 'Base code should include "base/trace_event/base_tracing.h" instead\n' +
'in //base with "base/trace_event/base_tracing.h" and/or verify\n' + 'of trace_event implementation headers. If you need to include an\n' +
'that base_unittests still passes with gn arg\n' + 'implementation header, verify that base_unittests still passes\n' +
'enable_base_tracing = false.\n' + '\n'.join(locations)) ] 'with gn arg "enable_base_tracing = false" and add\n' +
'"// no-presubmit-check" after the include. \n' +
'\n'.join(locations)) ]
return [] return []
......
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/memory_dump_manager.h" // no-presubmit-check
#include "base/trace_event/memory_dump_provider.h" #include "base/trace_event/memory_dump_provider.h" // no-presubmit-check
#endif // BUILDFLAG(DEVTOOLS_INSTRUMENTATION_DUMPING) #endif // BUILDFLAG(DEVTOOLS_INSTRUMENTATION_DUMPING)
#if !BUILDFLAG(SUPPORTS_CODE_ORDERING) #if !BUILDFLAG(SUPPORTS_CODE_ORDERING)
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/memory_dump_manager.h" // no-presubmit-check
#include "base/trace_event/memory_dump_provider.h" #include "base/trace_event/memory_dump_provider.h" // no-presubmit-check
#endif // BUILDFLAG(DEVTOOLS_INSTRUMENTATION_DUMPING) #endif // BUILDFLAG(DEVTOOLS_INSTRUMENTATION_DUMPING)
#if !BUILDFLAG(SUPPORTS_CODE_ORDERING) #if !BUILDFLAG(SUPPORTS_CODE_ORDERING)
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "base/tracing_buildflags.h" #include "base/tracing_buildflags.h"
#if BUILDFLAG(ENABLE_BASE_TRACING) #if BUILDFLAG(ENABLE_BASE_TRACING)
#include "base/trace_event/trace_event_impl.h" #include "base/trace_event/trace_event_impl.h" // no-presubmit-check
#endif // BUILDFLAG(ENABLE_BASE_TRACING) #endif // BUILDFLAG(ENABLE_BASE_TRACING)
namespace base { namespace base {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(ENABLE_BASE_TRACING) #if BUILDFLAG(ENABLE_BASE_TRACING)
#include "base/trace_event/memory_usage_estimator.h" #include "base/trace_event/memory_usage_estimator.h" // no-presubmit-check
#endif // BUILDFLAG(ENABLE_BASE_TRACING) #endif // BUILDFLAG(ENABLE_BASE_TRACING)
namespace base { namespace base {
......
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
#endif #endif
#if BUILDFLAG(ENABLE_BASE_TRACING) #if BUILDFLAG(ENABLE_BASE_TRACING)
#include "base/trace_event/memory_allocator_dump.h" #include "base/trace_event/memory_allocator_dump.h" // no-presubmit-check
#include "base/trace_event/process_memory_dump.h" #include "base/trace_event/process_memory_dump.h" // no-presubmit-check
#endif // BUILDFLAG(ENABLE_BASE_TRACING) #endif // BUILDFLAG(ENABLE_BASE_TRACING)
namespace base { namespace base {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(ENABLE_BASE_TRACING) #if BUILDFLAG(ENABLE_BASE_TRACING)
#include "base/trace_event/memory_allocator_dump.h" #include "base/trace_event/memory_allocator_dump.h" // no-presubmit-check
#include "base/trace_event/process_memory_dump.h" #include "base/trace_event/process_memory_dump.h" // no-presubmit-check
#endif // BUILDFLAG(ENABLE_BASE_TRACING) #endif // BUILDFLAG(ENABLE_BASE_TRACING)
namespace base { namespace base {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "base/tracing_buildflags.h" #include "base/tracing_buildflags.h"
#if BUILDFLAG(ENABLE_BASE_TRACING) #if BUILDFLAG(ENABLE_BASE_TRACING)
#include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/memory_dump_manager.h" // no-presubmit-check
#endif // BUILDFLAG(ENABLE_BASE_TRACING) #endif // BUILDFLAG(ENABLE_BASE_TRACING)
namespace base { namespace base {
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(ENABLE_BASE_TRACING) #if BUILDFLAG(ENABLE_BASE_TRACING)
#include "base/trace_event/memory_allocator_dump.h" #include "base/trace_event/memory_allocator_dump.h" // no-presubmit-check
#include "base/trace_event/process_memory_dump.h" #include "base/trace_event/process_memory_dump.h" // no-presubmit-check
#endif // BUILDFLAG(ENABLE_BASE_TRACING) #endif // BUILDFLAG(ENABLE_BASE_TRACING)
#define SUCCEED_IF_MADV_FREE_UNSUPPORTED() \ #define SUCCEED_IF_MADV_FREE_UNSUPPORTED() \
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
#include "base/tracing_buildflags.h" #include "base/tracing_buildflags.h"
#if BUILDFLAG(ENABLE_BASE_TRACING) #if BUILDFLAG(ENABLE_BASE_TRACING)
#include "base/trace_event/memory_allocator_dump.h" #include "base/trace_event/memory_allocator_dump.h" // no-presubmit-check
#include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/memory_dump_manager.h" // no-presubmit-check
#endif // BUILDFLAG(ENABLE_BASE_TRACING) #endif // BUILDFLAG(ENABLE_BASE_TRACING)
#if defined(ADDRESS_SANITIZER) #if defined(ADDRESS_SANITIZER)
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include "base/tracing_buildflags.h" #include "base/tracing_buildflags.h"
#if BUILDFLAG(ENABLE_BASE_TRACING) #if BUILDFLAG(ENABLE_BASE_TRACING)
#include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/memory_dump_manager.h" // no-presubmit-check
#include "base/trace_event/process_memory_dump.h" #include "base/trace_event/process_memory_dump.h" // no-presubmit-check
#endif // BUILDFLAG(ENABLE_BASE_TRACING) #endif // BUILDFLAG(ENABLE_BASE_TRACING)
namespace base { namespace base {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "base/partition_alloc_buildflags.h" #include "base/partition_alloc_buildflags.h"
#include "base/sampling_heap_profiler/lock_free_address_hash_set.h" #include "base/sampling_heap_profiler/lock_free_address_hash_set.h"
#include "base/threading/thread_local_storage.h" #include "base/threading/thread_local_storage.h"
#include "base/trace_event/heap_profiler_allocation_context_tracker.h" #include "base/trace_event/heap_profiler_allocation_context_tracker.h" // no-presubmit-check
#include "build/build_config.h" #include "build/build_config.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#if defined(OS_ANDROID) && BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE) && \ #if defined(OS_ANDROID) && BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE) && \
defined(OFFICIAL_BUILD) defined(OFFICIAL_BUILD)
#include "base/trace_event/cfi_backtrace_android.h" #include "base/trace_event/cfi_backtrace_android.h" // no-presubmit-check
#endif #endif
namespace base { namespace base {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/threading/thread_local.h" #include "base/threading/thread_local.h"
#include "base/trace_event/heap_profiler_allocation_context_tracker.h" #include "base/trace_event/heap_profiler_allocation_context_tracker.h" // no-presubmit-check
namespace base { namespace base {
namespace { namespace {
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "base/tracing_buildflags.h" #include "base/tracing_buildflags.h"
#if BUILDFLAG(ENABLE_BASE_TRACING) #if BUILDFLAG(ENABLE_BASE_TRACING)
#include "base/trace_event/memory_usage_estimator.h" #include "base/trace_event/memory_usage_estimator.h" // no-presubmit-check
#endif // BUILDFLAG(ENABLE_BASE_TRACING) #endif // BUILDFLAG(ENABLE_BASE_TRACING)
namespace base { namespace base {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment