base: don't enable DCHECKs in SDK builds
Until now DCHECKs were linked to the NDEBUG
symbols. This CL restricts this to: (1) standalone;
(2) chromium-tree; (3) android-tree builds.
In all other cases (in particular, for SDK/amalgamated
builds) DCHECKs are off by default, regardless of NDEBUG.
The old behavior turned out to be problematic for amalgamated
SDK users for two reasons:
1. Some of them reportedly build perfetto.cc once as
a static library and then build perfetto.h as part
of various .so(s). The NDEBUG flag might not match
in all cases.
2. In general when projects that embed perfetto build in
debug mode, they likely want to debug their own code,
not perfetto's.
Bug: 197340286
Change-Id: Idcc94b300715c88fb578b679fb1d54f354c54adb
diff --git a/CHANGELOG b/CHANGELOG
index 4fc0ced..51843f5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,7 +7,8 @@
UI:
*
SDK:
- *
+ * Changed DCHECK and DLOGs to be always disabled in SDK builds, regardless
+ of NDEBUG.
v19.0 - 2021-09-02:
diff --git a/gn/BUILD.gn b/gn/BUILD.gn
index 15fa31b..92f1107 100644
--- a/gn/BUILD.gn
+++ b/gn/BUILD.gn
@@ -43,6 +43,9 @@
perfetto_force_dlog_on = perfetto_force_dlog == "on"
perfetto_force_dlog_off = perfetto_force_dlog == "off"
+ perfetto_force_dcheck_on = perfetto_force_dcheck == "on"
+ perfetto_force_dcheck_off = perfetto_force_dcheck == "off"
+
# We can't just use (is_linux || is_android) in perfetto.gni because that
# doesn't work in Android Mac host builds. We lose the GN notion of OS once
# we run the tools/gen_xxx generators.
@@ -71,6 +74,8 @@
"PERFETTO_COMPONENT_BUILD=$perfetto_component_build",
"PERFETTO_FORCE_DLOG_ON=$perfetto_force_dlog_on",
"PERFETTO_FORCE_DLOG_OFF=$perfetto_force_dlog_off",
+ "PERFETTO_FORCE_DCHECK_ON=$perfetto_force_dcheck_on",
+ "PERFETTO_FORCE_DCHECK_OFF=$perfetto_force_dcheck_off",
"PERFETTO_VERBOSE_LOGS=$perfetto_verbose_logs_enabled",
"PERFETTO_VERSION_GEN=$enable_perfetto_version_gen",
"PERFETTO_TP_PERCENTILE=$enable_perfetto_trace_processor_percentile",
diff --git a/gn/perfetto.gni b/gn/perfetto.gni
index ebed8f3..c6817aa 100644
--- a/gn/perfetto.gni
+++ b/gn/perfetto.gni
@@ -217,6 +217,16 @@
# console.
perfetto_force_dlog = perfetto_force_dlog_default
+ # Whether DCHECKs should be enabled or not. Values: "on" | "off" | "".
+ # By default ("") DCHECKs are enabled only:
+ # - If DCHECK_ALWAYS_ON is defined (which is mainly a Chromium-ism).
+ # - On debug builds (i.e. if NDEBUG is NOT defined) but only in Chromium,
+ # Android and standalone builds.
+ # - On all other builds (e.g., SDK) it's off regardless of NDEBUG (unless
+ # DCHECK_ALWAYS_ON is defined).
+ # See base/logging.h for the implementation of all this.
+ perfetto_force_dcheck = ""
+
# Installs a signal handler for the most common crash signals which unwinds
# the stack and prints the stack trace on stderr. Requires a dependency on
# libbacktrace when enabled.
diff --git a/include/perfetto/base/build_configs/android_tree/perfetto_build_flags.h b/include/perfetto/base/build_configs/android_tree/perfetto_build_flags.h
index a114665..2867007 100644
--- a/include/perfetto/base/build_configs/android_tree/perfetto_build_flags.h
+++ b/include/perfetto/base/build_configs/android_tree/perfetto_build_flags.h
@@ -30,6 +30,8 @@
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_COMPONENT_BUILD() (0)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_FORCE_DLOG_ON() (0)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_FORCE_DLOG_OFF() (0)
+#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_FORCE_DCHECK_ON() (0)
+#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_FORCE_DCHECK_OFF() (0)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_VERBOSE_LOGS() (1)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_VERSION_GEN() (1)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_TP_PERCENTILE() (0)
diff --git a/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h b/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h
index 393c2b2..d448829 100644
--- a/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h
+++ b/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h
@@ -30,6 +30,8 @@
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_COMPONENT_BUILD() (0)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_FORCE_DLOG_ON() (0)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_FORCE_DLOG_OFF() (0)
+#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_FORCE_DCHECK_ON() (0)
+#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_FORCE_DCHECK_OFF() (0)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_VERBOSE_LOGS() (1)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_VERSION_GEN() (1)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_TP_PERCENTILE() (1)
diff --git a/include/perfetto/base/logging.h b/include/perfetto/base/logging.h
index 8641a1c..6e128be 100644
--- a/include/perfetto/base/logging.h
+++ b/include/perfetto/base/logging.h
@@ -29,12 +29,17 @@
#pragma GCC system_header
#endif
-// TODO(primiano): move this to base/build_config.h, turn into
-// PERFETTO_BUILDFLAG(DCHECK_IS_ON) and update call sites to use that instead.
-#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
-#define PERFETTO_DCHECK_IS_ON() 0
-#else
+#if PERFETTO_BUILDFLAG(PERFETTO_FORCE_DCHECK_ON)
#define PERFETTO_DCHECK_IS_ON() 1
+#elif PERFETTO_BUILDFLAG(PERFETTO_FORCE_DCHECK_OFF)
+#define PERFETTO_DCHECK_IS_ON() 0
+#elif defined(DCHECK_ALWAYS_ON) || \
+ (!defined(NDEBUG) && (PERFETTO_BUILDFLAG(PERFETTO_STANDALONE_BUILD) || \
+ PERFETTO_BUILDFLAG(PERFETTO_CHROMIUM_BUILD) || \
+ PERFETTO_BUILDFLAG(PERFETTO_ANDROID_BUILD)))
+#define PERFETTO_DCHECK_IS_ON() 1
+#else
+#define PERFETTO_DCHECK_IS_ON() 0
#endif
#if PERFETTO_BUILDFLAG(PERFETTO_FORCE_DLOG_ON)